Search in sources :

Example 6 with RLPList

use of org.aion.rlp.RLPList in project aion by aionnetwork.

the class AionTransaction method rlpParse.

public void rlpParse() {
    RLPList decodedTxList = RLP.decode2(rlpEncoded);
    RLPList tx = (RLPList) decodedTxList.get(0);
    this.nonce = tx.get(RLP_TX_NONCE).getRLPData();
    this.value = tx.get(RLP_TX_VALUE).getRLPData();
    this.data = tx.get(RLP_TX_DATA).getRLPData();
    if (tx.get(RLP_TX_TO).getRLPData() == null) {
        this.to = null;
    } else {
        this.to = Address.wrap(tx.get(RLP_TX_TO).getRLPData());
    }
    this.timeStamp = tx.get(RLP_TX_TIMESTAMP).getRLPData();
    this.nrg = new BigInteger(1, tx.get(RLP_TX_NRG).getRLPData()).longValue();
    this.nrgPrice = new BigInteger(1, tx.get(RLP_TX_NRGPRICE).getRLPData()).longValue();
    this.type = new BigInteger(1, tx.get(RLP_TX_TYPE).getRLPData()).byteValue();
    byte[] sigs = tx.get(RLP_TX_SIG).getRLPData();
    if (sigs != null) {
        // Singature Factory will decode the signature based on the algo
        // presetted in main() entry.
        ISignature is = SignatureFac.fromBytes(sigs);
        if (is != null) {
            this.signature = is;
        } else {
            // still ok if signature is null, but log it out.
            this.signature = null;
            LOG.error("tx -> unable to decode signature");
        }
    } else {
        LOG.error("tx -> no signature found");
    }
    this.parsed = true;
    this.hash = getHash();
}
Also used : BigInteger(java.math.BigInteger) RLPList(org.aion.rlp.RLPList) ISignature(org.aion.crypto.ISignature)

Example 7 with RLPList

use of org.aion.rlp.RLPList in project aion by aionnetwork.

the class AionTxExecSummary method rlpParse.

public void rlpParse() {
    if (parsed) {
        return;
    }
    RLPList decodedTxList = RLP.decode2(rlpEncoded);
    RLPList summary = (RLPList) decodedTxList.get(0);
    this.receipt = new AionTxReceipt(summary.get(0).getRLPData());
    this.value = decodeBigInteger(summary.get(1).getRLPData());
    this.deletedAccounts = decodeDeletedAccounts((RLPList) summary.get(2));
    this.internalTransactions = decodeInternalTransactions((RLPList) summary.get(3));
    this.touchedStorage = decodeTouchedStorage(summary.get(4));
    this.result = summary.get(5).getRLPData();
    this.logs = decodeLogs((RLPList) summary.get(6));
    byte[] failed = summary.get(7).getRLPData();
    int value = RLP.decodeInt(failed, 0);
    this.failed = TransactionStatus.getStatus(value);
    this.parsed = true;
}
Also used : RLPList(org.aion.rlp.RLPList)

Example 8 with RLPList

use of org.aion.rlp.RLPList 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 9 with RLPList

use of org.aion.rlp.RLPList 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 10 with RLPList

use of org.aion.rlp.RLPList in project aion by aionnetwork.

the class AvmContractDetailsTest method testDecode_withIncorrectListForConcatenatedData.

@Test(expected = IllegalArgumentException.class)
public void testDecode_withIncorrectListForConcatenatedData() {
    AionAddress address = new AionAddress(RandomUtils.nextBytes(AionAddress.LENGTH));
    byte[] rootHash = RandomUtils.nextBytes(32);
    RLPElement root = mock(RLPItem.class);
    when(root.getRLPData()).thenReturn(rootHash);
    byte[] codeBytes1 = RandomUtils.nextBytes(100);
    byte[] codeBytes2 = RandomUtils.nextBytes(100);
    RLPList code = new RLPList();
    code.add(new RLPItem(codeBytes1));
    code.add(new RLPItem(codeBytes2));
    byte[] storageHash = RandomUtils.nextBytes(32);
    when(mockDatabase.get(rootHash)).thenReturn(Optional.of(RLP.encodeList(RLP.encodeElement(storageHash))));
    RLPContractDetails input = new RLPContractDetails(address, true, root, null, code);
    AvmContractDetails.decodeAtRoot(input, mockDatabase, mockDatabase, rootHash);
}
Also used : SharedRLPItem(org.aion.rlp.SharedRLPItem) RLPItem(org.aion.rlp.RLPItem) AionAddress(org.aion.types.AionAddress) RLPElement(org.aion.rlp.RLPElement) RLPContractDetails(org.aion.zero.impl.db.DetailsDataStore.RLPContractDetails) SharedRLPList(org.aion.rlp.SharedRLPList) RLPList(org.aion.rlp.RLPList) Test(org.junit.Test)

Aggregations

RLPList (org.aion.rlp.RLPList)30 RLPElement (org.aion.rlp.RLPElement)18 RLPItem (org.aion.rlp.RLPItem)7 SharedRLPList (org.aion.rlp.SharedRLPList)7 SharedRLPItem (org.aion.rlp.SharedRLPItem)5 AionAddress (org.aion.types.AionAddress)5 RLPContractDetails (org.aion.zero.impl.db.DetailsDataStore.RLPContractDetails)5 Test (org.junit.Test)5 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)3 A0BlockHeader (org.aion.zero.types.A0BlockHeader)3 HashMap (java.util.HashMap)2 DataWord (org.aion.mcf.vm.types.DataWord)2 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)2 DatabaseType (org.aion.zero.impl.sync.DatabaseType)2 SecureTrie (org.aion.zero.impl.trie.SecureTrie)2 ByteUtil.toHexString (org.aion.base.util.ByteUtil.toHexString)1 ISignature (org.aion.crypto.ISignature)1 TxTouchedStorage (org.aion.mcf.core.TxTouchedStorage)1 Value (org.aion.rlp.Value)1