ETHTransaction.fromSerialized constructor
Factory constructor to create an ETHTransaction from serialized transaction bytes.
Implementation
factory ETHTransaction.fromSerialized(List<int> transactionBytes) {
if (transactionBytes.isEmpty) {
throw const MessageException("invalid transaction bytes");
}
List<int> bytes = List.from(transactionBytes);
final int prefix = bytes[0];
if (prefix == 1 || prefix == 2) {
bytes = bytes.sublist(1);
} else {
if (prefix < 0x7f) {
throw const MessageException("unsupported transaction type");
}
}
final decode = RLPDecoder.decode(bytes);
if (prefix == 1) {
return _ETHTransactionUtils._fromEIP2930(decode);
} else if (prefix == 2) {
return _ETHTransactionUtils._fromEIP1559(decode);
}
return _ETHTransactionUtils._fromLegacy(decode);
}