module Eth::Tx
def estimate_intrinsic_gas(data = "", list = [])
-
(Integer)
- the estimated intrinsic gas cost.
Parameters:
-
list
(Array
) -- the access list. -
data
(String
) -- the call data.
def estimate_intrinsic_gas(data = "", list = []) gas = DEFAULT_GAS_LIMIT unless data.nil? or data.empty? data = Util.hex_to_bin data if Util.hex? data # count zero bytes zero = data.count ZERO_BYTE gas += zero * COST_ZERO_BYTE # count non-zero bytes none = data.size - zero gas += none * COST_NON_ZERO_BYTE # count "words" as per EIP-3860 word_count = (data.length.to_f / 32.0).ceil gas += word_count * COST_INITCODE_WORD end unless list.nil? or list.empty? list.each do |entry| # count addresses gas += COST_ADDRESS entry.last.each do |key| # count storage keys gas += COST_STORAGE_KEY end end end return gas.to_i end