use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AionTransactionTest method testTransactionCost2.
@Test
public void testTransactionCost2() {
byte[] nonce = DataWord.ONE.getData();
byte[] from = RandomUtils.nextBytes(Address.ADDRESS_LEN);
Address to = Address.EMPTY_ADDRESS();
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, to, value, data, nrg, nrgPrice);
long expected = 200000 + 21000;
for (byte b : data) {
expected += (b == 0) ? 4 : 64;
}
assertEquals(expected, tx.transactionCost(1));
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class AbstractRepositoryCache method loadAccountState.
/**
* @implNote The loaded objects are fresh copies of the locally cached
* account state and contract details.
*/
@Override
public synchronized void loadAccountState(Address address, Map<Address, AccountState> accounts, Map<Address, IContractDetails<DataWord>> details) {
// check if the account is cached locally
AccountState accountState = this.cachedAccounts.get(address);
IContractDetails<DataWord> contractDetails = this.cachedDetails.get(address);
// when account not cached load from repository
if (accountState == null) {
// load directly to the caches given as parameters
repository.loadAccountState(address, accounts, details);
} else {
// copy the objects if they were cached locally
accounts.put(address, new AccountState(accountState));
details.put(address, new ContractDetailsCacheImpl(contractDetails));
}
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class ContractDetailsCacheImpl method setStorage.
@Override
public void setStorage(List<DataWord> storageKeys, List<DataWord> storageValues) {
for (int i = 0; i < storageKeys.size(); ++i) {
DataWord key = storageKeys.get(i);
DataWord value = storageValues.get(i);
if (value.isZero()) {
storage.put(key, null);
}
}
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class ContractDetailsCacheImpl method get.
@Override
public DataWord get(DataWord key) {
DataWord value = storage.get(key);
if (value != null) {
value = value.clone();
} else {
if (origContract == null) {
return null;
}
value = origContract.get(key);
storage.put(key.clone(), value == null ? DataWord.ZERO.clone() : value.clone());
}
if (value == null || value.isZero()) {
return null;
} else {
return value;
}
}
use of org.aion.mcf.vm.types.DataWord in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getStorageAt.
public Object eth_getStorageAt(String _address, String _storageIndex, Object _bnOrId) {
Address address = new Address(_address);
String bnOrId = "latest";
if (_bnOrId != null && !_bnOrId.equals(null))
bnOrId = _bnOrId + "";
DataWord key = DataWord.ZERO;
try {
key = new DataWord(ByteUtil.hexStringToBytes(_storageIndex));
} catch (Exception e) {
// invalid key
LOG.debug("eth_getStorageAt: invalid storageIndex. Must be <= 16 bytes.");
return null;
}
DataWord storageValue = (DataWord) getRepoByJsonBlockId(bnOrId).getStorageValue(address, key);
return storageValue != null ? TypeConverter.toJsonHex(storageValue.getData()) : null;
}
Aggregations