Skip to content

Commit

Permalink
Merge pull request #456 from sfsf9797/fix-datatype
Browse files Browse the repository at this point in the history
Fix datatype
  • Loading branch information
allenday authored Aug 23, 2023
2 parents 8410140 + 438c9af commit aab122e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ethereumetl/mappers/receipt_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from ethereumetl.domain.receipt import EthReceipt
from ethereumetl.mappers.receipt_log_mapper import EthReceiptLogMapper
from ethereumetl.utils import hex_to_dec, to_normalized_address
from ethereumetl.utils import hex_to_dec, to_normalized_address, to_float_or_none


class EthReceiptMapper(object):
Expand Down Expand Up @@ -53,7 +53,7 @@ def json_dict_to_receipt(self, json_dict):
receipt.l1_fee = hex_to_dec(json_dict.get('l1Fee'))
receipt.l1_gas_used = hex_to_dec(json_dict.get('l1GasUsed'))
receipt.l1_gas_price = hex_to_dec(json_dict.get('l1GasPrice'))
receipt.l1_fee_scalar = hex_to_dec(json_dict.get('l1FeeScalar'))
receipt.l1_fee_scalar = to_float_or_none(json_dict.get('l1FeeScalar'))


if 'logs' in json_dict:
Expand Down
10 changes: 10 additions & 0 deletions ethereumetl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def to_int_or_none(val):
except ValueError:
return None

def to_float_or_none(val):
if isinstance(val, float):
return val
if val is None or val == "":
return None
try:
return float(val)
except ValueError:
print("can't cast %s to float" % val)
return val

def chunk_string(string, length):
return (string[0 + i:length + i] for i in range(0, len(string), length))
Expand Down

0 comments on commit aab122e

Please sign in to comment.