Search in sources :

Example 1 with InvalidEthereumBytesException

use of com.hedera.mirror.importer.exception.InvalidEthereumBytesException in project hedera-mirror-node by hashgraph.

the class LegacyEthereumTransactionParser method decode.

@Override
public EthereumTransaction decode(byte[] transactionBytes) {
    var decoder = RLPDecoder.RLP_STRICT.sequenceIterator(transactionBytes);
    var legacyRlpItem = decoder.next();
    var rlpItems = legacyRlpItem.asRLPList().elements();
    if (rlpItems.size() != LEGACY_TYPE_RLP_ITEM_COUNT) {
        throw new InvalidEthereumBytesException(TRANSACTION_TYPE_NAME, String.format("RLPItem list size was %s " + "but should be %s", rlpItems.size(), LEGACY_TYPE_RLP_ITEM_COUNT));
    }
    var ethereumTransaction = EthereumTransaction.builder().nonce(rlpItems.get(0).asLong()).gasPrice(rlpItems.get(1).asBytes()).gasLimit(rlpItems.get(2).asLong()).toAddress(rlpItems.get(3).data()).value(rlpItems.get(4).asBigInt().toByteArray()).callData(rlpItems.get(5).data()).type(LEGACY_TYPE_BYTE);
    var v = rlpItems.get(6).asBytes();
    BigInteger vBi = new BigInteger(1, v);
    ethereumTransaction.signatureV(v).signatureR(rlpItems.get(7).data()).signatureS(rlpItems.get(8).data()).recoveryId(vBi.testBit(0) ? 0 : 1);
    if (vBi.compareTo(BigInteger.valueOf(34)) > 0) {
        ethereumTransaction.chainId(vBi.subtract(BigInteger.valueOf(35)).shiftRight(1).toByteArray());
    }
    return ethereumTransaction.build();
}
Also used : BigInteger(java.math.BigInteger) InvalidEthereumBytesException(com.hedera.mirror.importer.exception.InvalidEthereumBytesException)

Aggregations

InvalidEthereumBytesException (com.hedera.mirror.importer.exception.InvalidEthereumBytesException)1 BigInteger (java.math.BigInteger)1