chainlib-eth

Ethereum implementation of the chainlib interface
Info | Log | Files | Refs | README | LICENSE

rpc.py (2512B)


      1 # external imports
      2 from chainlib.cli import Rpc as BaseRpc
      3 from chainlib.eth.connection import EthHTTPConnection
      4 from chainlib.eth.constant import ZERO_ADDRESS
      5 
      6 # local imports
      7 from chainlib.eth.gas import (
      8         OverrideGasOracle,
      9         RPCGasOracle,
     10         )
     11 from chainlib.eth.nonce import (
     12         OverrideNonceOracle,
     13         RPCNonceOracle,
     14         )
     15 
     16 
     17 # TODO: how is the keystore implemented in rpc here?
     18 class Rpc(BaseRpc):
     19     """Convenience constructor to set Ethereum defaults for chainlib cli Rpc object
     20 
     21 
     22     """
     23 
     24     default_sender_address = ZERO_ADDRESS
     25 
     26     def __init__(self, wallet=None):
     27         super(Rpc, self).__init__(EthHTTPConnection, wallet=wallet)
     28 
     29     
     30     def connect_by_config(self, config, nonce_confirmed=True):
     31         """
     32 
     33         If the standard arguments for nonce and fee price/price have been defined (which generate the configuration keys "_NONCE", "_FEE_PRICE" and "_FEE_LIMIT" respectively) , the corresponding overrides for fee and nonce generators will be defined.
     34     
     35         """
     36         super(Rpc, self).connect_by_config(config)
     37 
     38         if self.can_sign():
     39             nonce = None
     40             try:
     41                 nonce = config.get('_NONCE')
     42             except KeyError:
     43                 pass
     44             if nonce != None:
     45                 self.nonce_oracle = OverrideNonceOracle(self.get_sender_address(), nonce, confirmed=nonce_confirmed, id_generator=self.id_generator)
     46             else:
     47                 self.nonce_oracle = RPCNonceOracle(self.get_sender_address(), self.conn, confirmed=nonce_confirmed, id_generator=self.id_generator)
     48         
     49         fee_price = None
     50         fee_limit = None
     51         try:
     52             fee_price = config.get('_FEE_PRICE')
     53         except KeyError:
     54             pass
     55 
     56         try:
     57             fee_limit = config.get('_FEE_LIMIT')
     58         except KeyError:
     59             pass
     60 
     61         if fee_price != None or fee_limit != None:
     62             self.fee_oracle = OverrideGasOracle(price=fee_price, limit=fee_limit, conn=self.conn, id_generator=self.id_generator)
     63         else:
     64             self.fee_oracle = RPCGasOracle(self.conn, id_generator=self.id_generator)
     65 
     66         # todo move to separate repo for dialect apply
     67         #error_parser = None
     68         #if config.get('RPC_DIALECT') == 'openethereum':
     69         #    from chainlib.eth.dialect.openethereum import DialectErrorParser
     70         #    self.error_parser = DialectErrorParser()
     71 
     72         return self.conn
     73 
     74 
     75     def get_gas_oracle(self):
     76         return self.get_fee_oracle()