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();
}
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;
}
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;
}
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;
}
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);
}
Aggregations