funga

Signer and keystore daemon and library for cryptocurrency software development
Log | Files | Refs | README | LICENSE

commit 347e117eb95db40afded7fa333d336d78f9ede09
parent f7c1f05a1fc939943abf340d6da67bedb9e6d90a
Author: nolash <dev@holbrook.no>
Date:   Sat,  9 Jan 2021 22:59:27 +0100

Bump prerelease

Diffstat:
Mcrypto_dev_signer/helper/tx.py | 38++++++++++++++++++++++++++++----------
Msetup.py | 3++-
Mtest/test_helper.py | 27+++++++++++++++------------
3 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/crypto_dev_signer/helper/tx.py b/crypto_dev_signer/helper/tx.py @@ -1,5 +1,6 @@ # standard imports import logging +import time # third-party imports from crypto_dev_signer.eth.transaction import EIP155Transaction @@ -12,7 +13,7 @@ logg = logging.getLogger() class TxExecutor: - def __init__(self, sender, signer, dispatcher, reporter, nonce, chain_id, fee_helper, fee_price_helper, block=False): + def __init__(self, sender, signer, dispatcher, reporter, nonce, chain_id, fee_helper=None, fee_price_helper=None, verifier=None, block=False): self.sender = sender self.nonce = nonce self.signer = signer @@ -21,8 +22,27 @@ class TxExecutor: self.block = bool(block) self.chain_id = chain_id self.tx_hashes = [] - self.fee_price_helper = fee_price_helper + if fee_helper == None: + fee_helper = self.noop_fee_helper self.fee_helper = fee_helper + if fee_price_helper == None: + fee_price_helper = self.noop_fee_price_helper + self.fee_price_helper = fee_price_helper + if verifier == None: + verifier = self.noop_verifier + self.verifier = verifier + + + def noop_fee_helper(self, sender, code, inputs): + return 1 + + + def noop_fee_price_helper(self): + return 1 + + + def noop_verifier(self, rcpt): + return rcpt def sign_and_send(self, builder, force_wait=False): @@ -31,13 +51,14 @@ class TxExecutor: tx_tpl = { 'from': self.sender, 'chainId': self.chain_id, - 'fee': fee_units, + 'feeUnits': fee_units, 'feePrice': self.fee_price_helper(), 'nonce': self.nonce, } - tx = None + + tx = tx_tpl for b in builder: - tx = b(tx_tpl, tx) + tx = b(tx) logg.debug('from {} nonce {} tx {}'.format(self.sender, self.nonce, tx)) @@ -50,7 +71,6 @@ class TxExecutor: rcpt = None if self.block or force_wait: rcpt = self.wait_for(tx_hash) - logg.info('tx {} fee used: {}'.format(tx_hash.hex(), rcpt['feeUsed'])) return (tx_hash.hex(), rcpt) @@ -62,10 +82,8 @@ class TxExecutor: try: #return self.w3.eth.getTransactionReceipt(tx_hash) return self.reporter(tx_hash) - except web3.exceptions.TransactionNotFound: + except Exception: logg.debug('poll #{} for {}'.format(i, tx_hash.hex())) i += 1 time.sleep(1) - if rcpt['status'] == 0: - raise TransactionRevertError(tx_hash) - return rcpt + return self.verifier(rcpt) diff --git a/setup.py b/setup.py @@ -24,7 +24,7 @@ f.close() setup( name="crypto-dev-signer", - version="0.4.13a4", + version="0.4.13b1", description="A signer and keystore daemon and library for cryptocurrency software development", author="Louis Holbrook", author_email="dev@holbrook.no", @@ -34,6 +34,7 @@ setup( 'crypto_dev_signer.eth', 'crypto_dev_signer.keystore', 'crypto_dev_signer.runnable', + 'crypto_dev_signer.helper', 'crypto_dev_signer', ], install_requires=requirements, diff --git a/test/test_helper.py b/test/test_helper.py @@ -23,6 +23,9 @@ class MockEthTxBackend: def reporter(self, tx): logg.debug('reporter {}'.format(tx)) + def verifier(self, rcpt): + logg.debug('reporter {}'.format(rcpt)) + def fee_price_helper(self): return 21 @@ -30,19 +33,18 @@ class MockEthTxBackend: logg.debug('fee helper code {} inputs {}'.format(code, inputs)) return 2 - def builder(self, a, b): - b = { - 'from': a['from'], + def builder(self, tx): + return { + 'from': tx['from'], 'to': '0x' + os.urandom(20).hex(), 'data': '', - 'gasPrice': a['feePrice'], - 'gas': a['fee'], + 'gasPrice': tx['feePrice'], + 'gas': tx['feeUnits'], } - return b - def builder_two(self, a, b): - b['value'] = 1024 - return b + def builder_two(self, tx): + tx['value'] = 1024 + return tx class TestHelper(unittest.TestCase): @@ -50,8 +52,9 @@ class TestHelper(unittest.TestCase): def setUp(self): logg.debug('setup') self.db = DictKeystore() - - keystore_filepath = os.path.join(script_dir, 'testdata', 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72') + + keystore_filename = 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72' + keystore_filepath = os.path.join(script_dir, 'testdata', keystore_filename) self.address_hex = self.db.import_keystore_file(keystore_filepath, '') self.signer = ReferenceSigner(self.db) @@ -63,7 +66,7 @@ class TestHelper(unittest.TestCase): def test_helper(self): backend = MockEthTxBackend() - executor = TxExecutor(self.address_hex, self.signer, backend.dispatcher, backend.reporter, 666, 13, backend.fee_helper, backend.fee_price_helper) + executor = TxExecutor(self.address_hex, self.signer, backend.dispatcher, backend.reporter, 666, 13, backend.fee_helper, backend.fee_price_helper, backend.verifier) tx_ish = {'from': self.address_hex} executor.sign_and_send([backend.builder, backend.builder_two])