Search in sources :

Example 11 with DataWord

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

Example 12 with DataWord

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

Example 13 with DataWord

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

Example 14 with DataWord

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

Example 15 with DataWord

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

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