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

Make DataWord immutable #1154

Merged
merged 10 commits into from
Aug 17, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ public Source<byte[], ProgramPrecompile> precompileSource() {
return new SourceCodec<byte[], ProgramPrecompile, byte[], byte[]>(source,
new Serializer<byte[], byte[]>() {
public byte[] serialize(byte[] object) {
DataWord ret = new DataWord(object);
ret.add(new DataWord(1));
return ret.getLast20Bytes();
DataWord ret = DataWord.of(object);
DataWord addResult = ret.add(DataWord.ONE);
return addResult.getLast20Bytes();
}
public byte[] deserialize(byte[] stream) {
throw new RuntimeException("Shouldn't be called");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public DataWord getCallGas(OpCode op, DataWord requestedGas, DataWord availableG
if (requestedGas.compareTo(availableGas) > 0) {
throw Program.Exception.notEnoughOpGas(op, requestedGas, availableGas);
}
return requestedGas.clone();
return requestedGas;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public static TransactionTouchedStorage decodeTouchedStorage(RLPElement encoded)
for (RLPElement entry : (RLPList) encoded) {
RLPList asList = (RLPList) entry;

DataWord key = new DataWord(asList.get(0).getRLPData());
DataWord value = new DataWord(asList.get(1).getRLPData());
DataWord key = DataWord.of(asList.get(0).getRLPData());
DataWord value = DataWord.of(asList.get(1).getRLPData());
byte[] changedBytes = asList.get(2).getRLPData();
boolean changed = isNotEmpty(changedBytes) && RLP.decodeInt(changedBytes, 0) == 1;

Expand Down Expand Up @@ -184,8 +184,8 @@ private static byte[] encodeStorageDiff(Map<DataWord, DataWord> storageDiff) {
private static Map<DataWord, DataWord> decodeStorageDiff(RLPList storageDiff) {
Map<DataWord, DataWord> result = new HashMap<>();
for (RLPElement entry : storageDiff) {
DataWord key = new DataWord(((RLPList) entry).get(0).getRLPData());
DataWord value = new DataWord(((RLPList) entry).get(1).getRLPData());
DataWord key = DataWord.of(((RLPList) entry).get(0).getRLPData());
DataWord value = DataWord.of(((RLPList) entry).get(1).getRLPData());
result.put(key, value);
}
return result;
Expand Down Expand Up @@ -222,7 +222,7 @@ private static byte[] encodeDeletedAccounts(List<DataWord> deletedAccounts) {
private static List<DataWord> decodeDeletedAccounts(RLPList deletedAccounts) {
List<DataWord> result = new ArrayList<>();
for (RLPElement deletedAccount : deletedAccounts) {
result.add(new DataWord(deletedAccount.getRLPData()));
result.add(DataWord.of(deletedAccount.getRLPData()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void call() {
if (!readyToExecute) return;

byte[] targetAddress = tx.getReceiveAddress();
precompiledContract = PrecompiledContracts.getContractForAddress(new DataWord(targetAddress), blockchainConfig);
precompiledContract = PrecompiledContracts.getContractForAddress(DataWord.of(targetAddress), blockchainConfig);

if (precompiledContract != null) {
long requiredGas = precompiledContract.getGasForData(tx.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public byte[] serialize(DataWord object) {

@Override
public DataWord deserialize(byte[] stream) {
return new DataWord(stream);
return DataWord.of(stream);
}
};

Expand All @@ -86,7 +86,7 @@ public byte[] serialize(DataWord object) {
public DataWord deserialize(byte[] stream) {
if (stream == null || stream.length == 0) return null;
byte[] dataDecoded = RLP.decode2(stream).get(0).getRLPData();
return new DataWord(dataDecoded);
return DataWord.of(dataDecoded);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public boolean matchesExactly(LogInfo logInfo) {
boolean orMatches = false;
DataWord logTopic = logTopics.get(i);
for (byte[] orTopic : orTopics) {
if (new DataWord(orTopic).equals(logTopic)) {
if (DataWord.of(orTopic).equals(logTopic)) {
orMatches = true;
break;
}
Expand Down
9 changes: 3 additions & 6 deletions ethereumj-core/src/main/java/org/ethereum/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import javax.swing.*;

public class Utils {
private static final DataWord DIVISOR = new DataWord(64);
private static final DataWord DIVISOR = DataWord.of(64);

private static SecureRandom random = new SecureRandom();

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

public static DataWord allButOne64th(DataWord dw) {
DataWord ret = dw.clone();
DataWord d = dw.clone();
d.div(DIVISOR);
ret.sub(d);
return ret;
DataWord divResult = dw.div(DIVISOR);
return dw.sub(divResult);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,12 @@ public SolidityStorageImpl(byte[] contractAddr) {

@Override
public byte[] getStorageSlot(long slot) {
return getStorageSlot(new DataWord(slot).getData());
return getStorageSlot(DataWord.of(slot).getData());
}

@Override
public byte[] getStorageSlot(byte[] slot) {
DataWord ret = getBlockchain().getRepository().getContractDetails(contractAddr).get(new DataWord(slot));
DataWord ret = getBlockchain().getRepository().getContractDetails(contractAddr).get(DataWord.of(slot));
return ret.getData();
}
}
Expand Down
Loading