Remove eth specific nonce gas oracle stuff

This commit is contained in:
nolash 2021-08-24 17:49:35 +02:00
parent dcf03b2708
commit 719d7f7c96
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
7 changed files with 97 additions and 26 deletions

View File

@ -5,14 +5,8 @@ import logging
from chainlib.chain import ChainSpec
from chainlib.connection import RPCConnection
from chainlib.jsonrpc import IntSequenceGenerator
from chainlib.eth.nonce import (
RPCNonceOracle,
OverrideNonceOracle,
)
from chainlib.eth.fee import (
RPCGasOracle,
OverrideGasOracle,
)
from chainlib.nonce import NonceOracle
from chainlib.fee import FeeOracle
from chainlib.error import SignerMissingException
logg = logging.getLogger(__name__)
@ -44,9 +38,8 @@ class Rpc:
The "CHAIN_SPEC" value is used for the chain context of the connection.
If the sequence flag was set in the confiruation (which generates the configuration key "_SEQ"), a sequential integer generator will be used for rpc ids. Otherwise uuids will be used.
If the sequence flag was set in the configuration (which generates the configuration key "_SEQ"), a sequential integer generator will be used for rpc ids. Otherwise uuids will be used.
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.
:param config: Processed configuration
:type config: confini.Config
@ -65,20 +58,6 @@ class Rpc:
self.chain_spec = config.get('CHAIN_SPEC')
self.conn = self.constructor(url=config.get('RPC_HTTP_PROVIDER'), chain_spec=self.chain_spec, auth=auth)
if self.can_sign():
nonce = config.get('_NONCE')
if nonce != None:
self.nonce_oracle = OverrideNonceOracle(self.get_sender_address(), nonce, id_generator=self.id_generator)
else:
self.nonce_oracle = RPCNonceOracle(self.get_sender_address(), self.conn, id_generator=self.id_generator)
fee_price = config.get('_FEE_PRICE')
fee_limit = config.get('_FEE_LIMIT')
if fee_price != None or fee_limit != None:
self.fee_oracle = OverrideGasOracle(price=fee_price, limit=fee_limit, conn=self.conn, id_generator=self.id_generator)
else:
self.fee_oracle = RPCGasOracle(self.conn, id_generator=self.id_generator)
return self.conn

View File

@ -8,6 +8,16 @@ logg = logging.getLogger(__name__)
class Wallet:
"""Provides a unified wallet factory for both read and write operations, and a convenience instantiator using rendered configurations from chainlib.cli.config.Config
:param signer_cls: Class to use for signer instantiation
:type signer_cls: TODO - define signer interface in chainlib
:param keystore: Keystore object
:type keystore: TODO - define keystore interface in chainlib
:param checksummer: If define any address returned from instance methods will be checksummed using the given function unless explicitly told otherwise
:type checksummer: TODO - define checksummer interface in chainlib
:todo: sign_transaction_to_rlp from chainlib-eth must be renamed to sign_transaction_to_wire, and included as part of signer interface
"""
def __init__(self, signer_cls, keystore=DictKeystore(), checksummer=None):
self.signer_constructor = signer_cls
@ -21,14 +31,37 @@ class Wallet:
def from_config(self, config):
"""Instantiates a signer from the registered signer class, using parameters from a processed configuration.
Currently only keyfile loader is implemented, and defers processing to chainlib.cli.wallet.Wallet.from_keyfile. The keyfile path is read from the "WALLET_KEY_FILE" value.
Keyfile passphrase is value of "WALLET_PASSPHRASE" configuration parameter, or empty string by default.
If the "_UNSAFE" configuration parameter is set to True, address checksumming will be deactivated.
:param config: Configuration to load wallet with
:type config: confini.Config
:rtype: TODO - signer interface
:returns: Signer
"""
wallet_keyfile = config.get('WALLET_KEY_FILE')
if wallet_keyfile:
logg.debug('keyfile {}'.format(wallet_keyfile))
self.from_keyfile(wallet_keyfile, passphrase=config.get('WALLET_PASSPHRASE', ''))
self.use_checksum = not config.true('_UNSAFE')
return self.signer
def from_keyfile(self, key_file, passphrase=''):
"""Instantiates a signer from the registered signer class, with private key from the given keyfile.
:param key_file: Keyfile path
:type key_file: str
:param passphrase: Private key passphrase
:type passphrase: str
:rtype: TODO - signer interface
:returns: Signer
"""
logg.debug('importing key from keystore file {}'.format(key_file))
self.signer_address = self.keystore.import_keystore_file(key_file, password=passphrase)
self.signer = self.signer_constructor(self.keystore)
@ -37,6 +70,17 @@ class Wallet:
def from_address(self, address):
"""Instantiates a read-only wallet with the given address.
If checksummer is defined and active, the address argument must be a valid checksum address.
:param address: Wallet address
:type address: str
:raises AttributeError: Checksum requested but no checksummer assigned
:raises ValueError: Invalid checksum address
:rtype: str
:returns: Checksummed address
"""
self.signer_address = address
if self.use_checksum:
if self.checksummer == None:
@ -50,8 +94,18 @@ class Wallet:
def get_signer(self):
"""Signer interface getter.
:rtype: TODO - signer interface
:returns: Signer
"""
return self.signer
def get_signer_address(self):
"""Wallet address getter.
:rtype: str
:returns: Wallet address
"""
return self.signer_address

8
chainlib/fee.py Normal file
View File

@ -0,0 +1,8 @@
class FeeOracle:
def __init__(self, code_callback=None):
self.code_callback = code_callback
def get_fee(self, code_data=None, input_data=None, *args, **kwargs):
raise NotImplementedError()

13
chainlib/nonce.py Normal file
View File

@ -0,0 +1,13 @@
class NonceOracle:
def __init__(self, address):
self.address = address
self.nonce = self.get_nonce()
def get_nonce(self):
raise NotImplementedError()
def next_nonce(self):
raise NotImplementedError()

16
chainlib/sign.py Normal file
View File

@ -0,0 +1,16 @@
class Signer:
def sign_transaction(self):
raise NotImplementedError()
def sign_transaction_to_wire(self):
raise NotImplementedError()
def sign_message(self):
raise NotImplementedError()
def sign_message_to_wire(self):
raise NotImplementedError()

View File

@ -1,3 +1,3 @@
crypto-dev-signer>=0.4.14b7,<=0.4.14
crypto-dev-signer>=0.4.15a1,<=0.4.15
pysha3==1.0.2
hexathon~=0.0.1a8

View File

@ -1,5 +1,6 @@
[metadata]
version = 0.0.8a2
name = chainlib
version = 0.0.9a2
description = Generic blockchain access library and tooling
author = Louis Holbrook
author_email = dev@holbrook.no