Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 5229ee2

Browse files
authored
Merge pull request #1154 from ethereum/tonycox-immutableDW
Make DataWord immutable
2 parents 0e5f1bd + d8bfbef commit 5229ee2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+562
-549
lines changed

ethereumj-core/src/main/java/org/ethereum/config/CommonConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ public Source<byte[], ProgramPrecompile> precompileSource() {
257257
return new SourceCodec<byte[], ProgramPrecompile, byte[], byte[]>(source,
258258
new Serializer<byte[], byte[]>() {
259259
public byte[] serialize(byte[] object) {
260-
DataWord ret = new DataWord(object);
261-
ret.add(new DataWord(1));
262-
return ret.getLast20Bytes();
260+
DataWord ret = DataWord.of(object);
261+
DataWord addResult = ret.add(DataWord.ONE);
262+
return addResult.getLast20Bytes();
263263
}
264264
public byte[] deserialize(byte[] stream) {
265265
throw new RuntimeException("Shouldn't be called");

ethereumj-core/src/main/java/org/ethereum/config/blockchain/AbstractConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public DataWord getCallGas(OpCode op, DataWord requestedGas, DataWord availableG
140140
if (requestedGas.compareTo(availableGas) > 0) {
141141
throw Program.Exception.notEnoughOpGas(op, requestedGas, availableGas);
142142
}
143-
return requestedGas.clone();
143+
return requestedGas;
144144
}
145145

146146
@Override

ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutionSummary.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public static TransactionTouchedStorage decodeTouchedStorage(RLPElement encoded)
141141
for (RLPElement entry : (RLPList) encoded) {
142142
RLPList asList = (RLPList) entry;
143143

144-
DataWord key = new DataWord(asList.get(0).getRLPData());
145-
DataWord value = new DataWord(asList.get(1).getRLPData());
144+
DataWord key = DataWord.of(asList.get(0).getRLPData());
145+
DataWord value = DataWord.of(asList.get(1).getRLPData());
146146
byte[] changedBytes = asList.get(2).getRLPData();
147147
boolean changed = isNotEmpty(changedBytes) && RLP.decodeInt(changedBytes, 0) == 1;
148148

@@ -184,8 +184,8 @@ private static byte[] encodeStorageDiff(Map<DataWord, DataWord> storageDiff) {
184184
private static Map<DataWord, DataWord> decodeStorageDiff(RLPList storageDiff) {
185185
Map<DataWord, DataWord> result = new HashMap<>();
186186
for (RLPElement entry : storageDiff) {
187-
DataWord key = new DataWord(((RLPList) entry).get(0).getRLPData());
188-
DataWord value = new DataWord(((RLPList) entry).get(1).getRLPData());
187+
DataWord key = DataWord.of(((RLPList) entry).get(0).getRLPData());
188+
DataWord value = DataWord.of(((RLPList) entry).get(1).getRLPData());
189189
result.put(key, value);
190190
}
191191
return result;
@@ -222,7 +222,7 @@ private static byte[] encodeDeletedAccounts(List<DataWord> deletedAccounts) {
222222
private static List<DataWord> decodeDeletedAccounts(RLPList deletedAccounts) {
223223
List<DataWord> result = new ArrayList<>();
224224
for (RLPElement deletedAccount : deletedAccounts) {
225-
result.add(new DataWord(deletedAccount.getRLPData()));
225+
result.add(DataWord.of(deletedAccount.getRLPData()));
226226
}
227227
return result;
228228
}

ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private void call() {
207207
if (!readyToExecute) return;
208208

209209
byte[] targetAddress = tx.getReceiveAddress();
210-
precompiledContract = PrecompiledContracts.getContractForAddress(new DataWord(targetAddress), blockchainConfig);
210+
precompiledContract = PrecompiledContracts.getContractForAddress(DataWord.of(targetAddress), blockchainConfig);
211211

212212
if (precompiledContract != null) {
213213
long requiredGas = precompiledContract.getGasForData(tx.getData());

ethereumj-core/src/main/java/org/ethereum/datasource/Serializers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public byte[] serialize(DataWord object) {
6969

7070
@Override
7171
public DataWord deserialize(byte[] stream) {
72-
return new DataWord(stream);
72+
return DataWord.of(stream);
7373
}
7474
};
7575

@@ -86,7 +86,7 @@ public byte[] serialize(DataWord object) {
8686
public DataWord deserialize(byte[] stream) {
8787
if (stream == null || stream.length == 0) return null;
8888
byte[] dataDecoded = RLP.decode2(stream).get(0).getRLPData();
89-
return new DataWord(dataDecoded);
89+
return DataWord.of(dataDecoded);
9090
}
9191
};
9292

ethereumj-core/src/main/java/org/ethereum/listener/LogFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public boolean matchesExactly(LogInfo logInfo) {
100100
boolean orMatches = false;
101101
DataWord logTopic = logTopics.get(i);
102102
for (byte[] orTopic : orTopics) {
103-
if (new DataWord(orTopic).equals(logTopic)) {
103+
if (DataWord.of(orTopic).equals(logTopic)) {
104104
orMatches = true;
105105
break;
106106
}

ethereumj-core/src/main/java/org/ethereum/util/Utils.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import javax.swing.*;
4141

4242
public class Utils {
43-
private static final DataWord DIVISOR = new DataWord(64);
43+
private static final DataWord DIVISOR = DataWord.of(64);
4444

4545
private static SecureRandom random = new SecureRandom();
4646

@@ -230,11 +230,8 @@ public static List<ByteArrayWrapper> dumpKeys(DbSource<byte[]> ds) {
230230
}
231231

232232
public static DataWord allButOne64th(DataWord dw) {
233-
DataWord ret = dw.clone();
234-
DataWord d = dw.clone();
235-
d.div(DIVISOR);
236-
ret.sub(d);
237-
return ret;
233+
DataWord divResult = dw.div(DIVISOR);
234+
return dw.sub(divResult);
238235
}
239236

240237
/**

ethereumj-core/src/main/java/org/ethereum/util/blockchain/StandaloneBlockchain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,12 @@ public SolidityStorageImpl(byte[] contractAddr) {
701701

702702
@Override
703703
public byte[] getStorageSlot(long slot) {
704-
return getStorageSlot(new DataWord(slot).getData());
704+
return getStorageSlot(DataWord.of(slot).getData());
705705
}
706706

707707
@Override
708708
public byte[] getStorageSlot(byte[] slot) {
709-
DataWord ret = getBlockchain().getRepository().getContractDetails(contractAddr).get(new DataWord(slot));
709+
DataWord ret = getBlockchain().getRepository().getContractDetails(contractAddr).get(DataWord.of(slot));
710710
return ret.getData();
711711
}
712712
}

0 commit comments

Comments
 (0)