base.py (1590B)
1 # standard imports 2 import logging 3 4 # external imports 5 from funga.eth.transaction import EIP155Transaction 6 from hexathon import strip_0x 7 8 logg = logging.getLogger(__name__) 9 10 class BaseTokenResolver: 11 12 def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle, advance_nonce=False): 13 self.chain_spec = chain_spec 14 self.chain_id = chain_spec.chain_id() 15 self.signer = signer 16 self.sender = sender 17 self.gas_oracle = gas_oracle 18 self.nonce_oracle = nonce_oracle 19 self.factory = None 20 self.gas_limit_start = None 21 self.gas_price_start = None 22 if advance_nonce: 23 self.nonce_getter = self.nonce_oracle.next_nonce 24 else: 25 self.nonce_getter = self.nonce_oracle.get_nonce 26 27 28 def reset(self): 29 gas_data = self.gas_oracle.get_gas() 30 self.gas_price_start = gas_data[0] 31 self.gas_limit_start = gas_data[1] 32 33 34 def get_values(self, gas_value, value, executable_address=None): 35 nonce = self.nonce_getter() 36 37 if executable_address == None: 38 return (value, 0, nonce) 39 40 try: 41 value = int(value) 42 except ValueError: 43 value = int(strip_0x(value), 16) 44 45 try: 46 gas_value = int(gas_value) 47 except ValueError: 48 gas_value = int(strip_0x(gas_value), 16) 49 50 return (gas_value, value, nonce,) 51 52 53 def sign(self, tx): 54 tx_o = EIP155Transaction(tx, tx['nonce'], self.chain_id) 55 tx_bytes = self.signer.sign_transaction_to_wire(tx_o) 56 return tx_bytes