transactionType property
ETHTransactionType
transactionType
Determines the ETHTransactionType based on the transaction's properties.
Implementation
ETHTransactionType get transactionType {
final hasGasPrice = gasPrice != null;
final isEIP1559 = maxFeePerGas != null || maxPriorityFeePerGas != null;
final hasAccessList = accessList?.isNotEmpty ?? false;
if (maxFeePerGas != null && maxPriorityFeePerGas != null) {
if (maxPriorityFeePerGas! > maxFeePerGas!) {
throw MessageException("priorityFee cannot be more than maxFee",
details: {
"priorityFee": maxFeePerGas,
"maxFee": maxPriorityFeePerGas
});
}
}
if (type != null) {
if (type == ETHTransactionType.legacy ||
type == ETHTransactionType.eip2930) {
if (gasPrice == null) {
throw const MessageException(
"Gas price must not be null for legacy transactions.");
}
if (maxFeePerGas != null || maxPriorityFeePerGas != null) {
throw MessageException(
"maxFeePerGas and maxPriorityFeePerGas must be null for legacy transactions.",
details: {
"maxFeePerGas": maxFeePerGas,
"maxPriorityFeePerGas": maxPriorityFeePerGas
});
}
if (type == ETHTransactionType.legacy && hasAccessList) {
throw MessageException(
"accsesslist must be null or empty for legacy transactions",
details: {"accessList": accessList});
}
} else {
if (gasPrice != null) {
throw MessageException(
"Gas price must be null for EIP1559 transactions.",
details: {"gasPrice": gasPrice});
}
if (maxFeePerGas == null || maxPriorityFeePerGas == null) {
throw const MessageException(
"maxFeePerGas and maxPriorityFeePerGas must not be null for EIP1559 transactions.");
}
}
} else {
if (!hasGasPrice && !isEIP1559) {
throw const MessageException(
"use gasPrice for legacy or Eip2930 transaction or priorityFee and maxFee for Eip1559 transactions");
}
}
if (type != null) {
return type!;
} else {
if (isEIP1559) {
return ETHTransactionType.eip1559;
} else if (hasGasPrice) {
if (!hasAccessList) {
return ETHTransactionType.legacy;
}
return ETHTransactionType.eip2930;
} else {
return ETHTransactionType.eip1559;
}
}
}