RawEVMTransactionType2.fromHex constructor
RawEVMTransactionType2.fromHex( - String rawTxHex
)
Implementation
factory RawEVMTransactionType2.fromHex(String rawTxHex) {
rawTxHex = rawTxHex.replaceFirst("0x", ""); // Remove the 0x prefix
assert(rawTxHex.startsWith("02"), "Invalid Type 1 Transaction");
rawTxHex = rawTxHex.substring(2); // Remove the type prefix
final rlpDecoded = decodeRLP(rawTxHex.hexToBytes).$1;
if (rlpDecoded is! RLPList) {
throw Exception("Error RLP decoding transaction: $rlpDecoded");
}
if (rlpDecoded.length < 12) {
throw Exception("Invalid transaction, missing fields: $rlpDecoded");
}
return RawEVMTransactionType2(
chainId: rlpDecoded[0].buffer.toUInt,
nonce: rlpDecoded[1].buffer.toUBigInt,
maxPriorityFeePerGas: rlpDecoded[2].buffer.toUBigInt,
maxFeePerGas: rlpDecoded[3].buffer.toUBigInt,
gasLimit: rlpDecoded[4].buffer.toUBigInt,
to: "0x" + rlpDecoded[5].buffer.toHex,
value: rlpDecoded[6].buffer.toUBigInt,
data: rlpDecoded[7].buffer,
accessList: switch (rlpDecoded[8]) {
RLPList list => list.value
.whereType<RLPList>()
.map((item) {
final subList = item[1];
if (subList is RLPList)
return (
address: "0x" + item[0].buffer.toHex,
storageKeys:
subList.value.map((key) => key.buffer.toHex).toList(),
);
return null;
})
.nonNulls
.toList(),
_ => [],
},
signatureYParity: rlpDecoded[9].buffer.toUInt,
signatureR: rlpDecoded[10].buffer,
signatureS: rlpDecoded[11].buffer,
);
}