Search in sources :

Example 16 with DataWord

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));
}
Also used : Address(org.aion.base.type.Address) DataWord(org.aion.mcf.vm.types.DataWord) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 17 with DataWord

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));
    }
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord) AccountState(org.aion.mcf.core.AccountState)

Example 18 with DataWord

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);
        }
    }
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord)

Example 19 with DataWord

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;
    }
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord)

Example 20 with DataWord

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;
}
Also used : Address(org.aion.base.type.Address) DataWord(org.aion.mcf.vm.types.DataWord) ByteUtil.toHexString(org.aion.base.util.ByteUtil.toHexString)

Aggregations

DataWord (org.aion.mcf.vm.types.DataWord)29 Address (org.aion.base.type.Address)11 AccountState (org.aion.mcf.core.AccountState)11 Test (org.junit.Test)9 AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)5 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)5 HashMap (java.util.HashMap)3 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 IRepositoryCache (org.aion.base.db.IRepositoryCache)3 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)3 ContractDetailsCacheImpl (org.aion.mcf.db.ContractDetailsCacheImpl)3 IContractDetails (org.aion.base.db.IContractDetails)2 RLPElement (org.aion.rlp.RLPElement)2 RLPList (org.aion.rlp.RLPList)2 AionTransaction (org.aion.zero.types.AionTransaction)2 BigInteger (java.math.BigInteger)1 Map (java.util.Map)1 ByteUtil.toHexString (org.aion.base.util.ByteUtil.toHexString)1 IEvent (org.aion.evtmgr.IEvent)1 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)1