feat(core/TypedTransaction): add helper for calculating max cost of tx (#1070)

This commit is contained in:
Meet Mangukiya 2022-03-21 20:34:02 +05:30 committed by GitHub
parent 95a384b121
commit d4fca905f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -253,6 +253,16 @@ impl TypedTransaction {
let encoded = self.rlp();
keccak256(encoded).into()
}
/// Max cost of the transaction
pub fn max_cost(&self) -> Option<U256> {
let gas_limit = self.gas();
let gas_price = self.gas_price();
match (gas_limit, gas_price) {
(Some(gas_limit), Some(gas_price)) => Some(gas_limit * gas_price),
_ => None,
}
}
}
/// Get a TypedTransaction directly from an rlp encoded byte stream