Search in sources :

Example 6 with RLPElement

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

the class AbstractBlockSummary method decodeMap.

protected static <K, V> Map<K, V> decodeMap(RLPList list, Functional.Function<byte[], K> keyDecoder, Functional.Function<byte[], V> valueDecoder) {
    Map<K, V> result = new HashMap<>();
    for (RLPElement entry : list) {
        K key = keyDecoder.apply(((RLPList) entry).get(0).getRLPData());
        V value = valueDecoder.apply(((RLPList) entry).get(1).getRLPData());
        result.put(key, value);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) RLPElement(org.aion.rlp.RLPElement) RLPList(org.aion.rlp.RLPList)

Example 7 with RLPElement

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

the class AionBlockHeaderWrapper method parse.

protected void parse(byte[] bytes) {
    List<RLPElement> params = RLP.decode2(bytes);
    List<RLPElement> wrapper = (RLPList) params.get(0);
    byte[] headerBytes = wrapper.get(0).getRLPData();
    this.header = new A0BlockHeader(headerBytes);
    this.nodeId = wrapper.get(1).getRLPData();
}
Also used : A0BlockHeader(org.aion.zero.types.A0BlockHeader) RLPElement(org.aion.rlp.RLPElement) RLPList(org.aion.rlp.RLPList)

Example 8 with RLPElement

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

the class BroadcastTx method decode.

/* return the encodedData of the Transaction list, the caller function need to cast the return byte[] array
     */
public static List<byte[]> decode(final byte[] _msgBytes) {
    RLPList paramsList = (RLPList) RLP.decode2(_msgBytes).get(0);
    List<byte[]> txl = new ArrayList<>();
    for (RLPElement aParamsList : paramsList) {
        RLPList rlpData = ((RLPList) aParamsList);
        txl.add(rlpData.getRLPData());
    }
    return txl;
}
Also used : RLPElement(org.aion.rlp.RLPElement) ArrayList(java.util.ArrayList) RLPList(org.aion.rlp.RLPList)

Example 9 with RLPElement

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

the class ResBlocksHeaders method decode.

public static ResBlocksHeaders decode(final byte[] _msgBytes) {
    if (_msgBytes == null || _msgBytes.length == 0)
        return null;
    else {
        try {
            RLPList list = (RLPList) RLP.decode2(_msgBytes).get(0);
            List<A0BlockHeader> blockHeaders = new ArrayList<>();
            for (RLPElement aList : list) {
                RLPList rlpData = ((RLPList) aList);
                blockHeaders.add(A0BlockHeader.fromRLP(rlpData, true));
            }
            return new ResBlocksHeaders(blockHeaders);
        } catch (Exception ex) {
            return null;
        }
    }
}
Also used : A0BlockHeader(org.aion.zero.types.A0BlockHeader) RLPElement(org.aion.rlp.RLPElement) ArrayList(java.util.ArrayList) RLPList(org.aion.rlp.RLPList)

Example 10 with RLPElement

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

the class AionContractDetailsImpl method decode.

@Override
public void decode(byte[] rlpCode) {
    RLPList data = RLP.decode2(rlpCode);
    RLPList rlpList = (RLPList) data.get(0);
    RLPItem address = (RLPItem) rlpList.get(0);
    RLPItem isExternalStorage = (RLPItem) rlpList.get(1);
    RLPItem storage = (RLPItem) rlpList.get(2);
    RLPElement code = rlpList.get(3);
    RLPList keys = (RLPList) rlpList.get(4);
    RLPItem storageRoot = (RLPItem) rlpList.get(5);
    if (address.getRLPData() == null) {
        this.address = Address.EMPTY_ADDRESS();
    } else {
        this.address = Address.wrap(address.getRLPData());
    }
    this.externalStorage = !Arrays.equals(isExternalStorage.getRLPData(), EMPTY_BYTE_ARRAY);
    this.storageTrie.deserialize(storage.getRLPData());
    if (code instanceof RLPList) {
        for (RLPElement e : ((RLPList) code)) {
            setCode(e.getRLPData());
        }
    } else {
        setCode(code.getRLPData());
    }
    for (RLPElement key : keys) {
        addKey(key.getRLPData());
    }
    if (externalStorage) {
        storageTrie.withPruningEnabled(prune >= 0);
        storageTrie.setRoot(storageRoot.getRLPData());
        storageTrie.getCache().setDB(getExternalStorageDataSource());
    }
    externalStorage = (storage.getRLPData().length > detailsInMemoryStorageLimit) || externalStorage;
    this.rlpEncoded = rlpCode;
}
Also used : RLPItem(org.aion.rlp.RLPItem) RLPElement(org.aion.rlp.RLPElement) RLPList(org.aion.rlp.RLPList)

Aggregations

RLPElement (org.aion.rlp.RLPElement)10 RLPList (org.aion.rlp.RLPList)9 ArrayList (java.util.ArrayList)3 DataWord (org.aion.mcf.vm.types.DataWord)2 A0BlockHeader (org.aion.zero.types.A0BlockHeader)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 TxTouchedStorage (org.aion.mcf.core.TxTouchedStorage)1 TrieImpl (org.aion.mcf.trie.TrieImpl)1 RLPItem (org.aion.rlp.RLPItem)1 AionTransaction (org.aion.zero.types.AionTransaction)1