use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionRepositoryImpl method getCode.
@Override
public synchronized byte[] getCode(Address address) {
AccountState accountState = getAccountState(address);
if (accountState == null) {
return EMPTY_BYTE_ARRAY;
}
byte[] codeHash = accountState.getCodeHash();
IContractDetails<DataWord> details = getContractDetails(address);
return (details == null) ? EMPTY_BYTE_ARRAY : details.getCode(codeHash);
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionContractDetailsImpl method getStorage.
@Override
public Map<DataWord, DataWord> getStorage(Collection<DataWord> keys) {
Map<DataWord, DataWord> storage = new HashMap<>();
if (keys == null) {
for (ByteArrayWrapper keyBytes : this.keys) {
DataWord key = new DataWord(keyBytes);
DataWord value = get(key);
// cause we keep all historical keys
if (value != null) {
storage.put(key, value);
}
}
} else {
for (DataWord key : keys) {
DataWord value = get(key);
// cause we keep all historical keys
if (value != null) {
storage.put(key, value);
}
}
}
return storage;
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionTxExecSummary method decodeStorageDiff.
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());
result.put(key, value);
}
return result;
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionTxExecSummary method decodeTouchedStorage.
protected static TxTouchedStorage decodeTouchedStorage(RLPElement encoded) {
TxTouchedStorage result = new TxTouchedStorage();
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());
byte[] changedBytes = asList.get(2).getRLPData();
boolean changed = isNotEmpty(changedBytes) && RLP.decodeInt(changedBytes, 0) == 1;
result.add(new TxTouchedStorage.Entry(key, value, changed));
}
return result;
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionTransactionTest method testTransactionCost.
@Test
public void testTransactionCost() {
byte[] nonce = DataWord.ONE.getData();
byte[] from = RandomUtils.nextBytes(20);
byte[] to = RandomUtils.nextBytes(Address.ADDRESS_LEN);
byte[] value = DataWord.ONE.getData();
byte[] data = RandomUtils.nextBytes(128);
long nrg = new DataWord(1000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
AionTransaction tx = new AionTransaction(nonce, Address.wrap(to), value, data, nrg, nrgPrice);
long expected = 21000;
for (byte b : data) {
expected += (b == 0) ? 4 : 64;
}
assertEquals(expected, tx.transactionCost(1));
}
Aggregations