Bump prerelease
This commit is contained in:
parent
f7c1f05a1f
commit
347e117eb9
@ -1,5 +1,6 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
# third-party imports
|
# third-party imports
|
||||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
||||||
@ -12,7 +13,7 @@ logg = logging.getLogger()
|
|||||||
|
|
||||||
class TxExecutor:
|
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.sender = sender
|
||||||
self.nonce = nonce
|
self.nonce = nonce
|
||||||
self.signer = signer
|
self.signer = signer
|
||||||
@ -21,8 +22,27 @@ class TxExecutor:
|
|||||||
self.block = bool(block)
|
self.block = bool(block)
|
||||||
self.chain_id = chain_id
|
self.chain_id = chain_id
|
||||||
self.tx_hashes = []
|
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
|
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):
|
def sign_and_send(self, builder, force_wait=False):
|
||||||
@ -31,13 +51,14 @@ class TxExecutor:
|
|||||||
tx_tpl = {
|
tx_tpl = {
|
||||||
'from': self.sender,
|
'from': self.sender,
|
||||||
'chainId': self.chain_id,
|
'chainId': self.chain_id,
|
||||||
'fee': fee_units,
|
'feeUnits': fee_units,
|
||||||
'feePrice': self.fee_price_helper(),
|
'feePrice': self.fee_price_helper(),
|
||||||
'nonce': self.nonce,
|
'nonce': self.nonce,
|
||||||
}
|
}
|
||||||
tx = None
|
|
||||||
|
tx = tx_tpl
|
||||||
for b in builder:
|
for b in builder:
|
||||||
tx = b(tx_tpl, tx)
|
tx = b(tx)
|
||||||
|
|
||||||
logg.debug('from {} nonce {} tx {}'.format(self.sender, self.nonce, tx))
|
logg.debug('from {} nonce {} tx {}'.format(self.sender, self.nonce, tx))
|
||||||
|
|
||||||
@ -50,7 +71,6 @@ class TxExecutor:
|
|||||||
rcpt = None
|
rcpt = None
|
||||||
if self.block or force_wait:
|
if self.block or force_wait:
|
||||||
rcpt = self.wait_for(tx_hash)
|
rcpt = self.wait_for(tx_hash)
|
||||||
logg.info('tx {} fee used: {}'.format(tx_hash.hex(), rcpt['feeUsed']))
|
|
||||||
return (tx_hash.hex(), rcpt)
|
return (tx_hash.hex(), rcpt)
|
||||||
|
|
||||||
|
|
||||||
@ -62,10 +82,8 @@ class TxExecutor:
|
|||||||
try:
|
try:
|
||||||
#return self.w3.eth.getTransactionReceipt(tx_hash)
|
#return self.w3.eth.getTransactionReceipt(tx_hash)
|
||||||
return self.reporter(tx_hash)
|
return self.reporter(tx_hash)
|
||||||
except web3.exceptions.TransactionNotFound:
|
except Exception:
|
||||||
logg.debug('poll #{} for {}'.format(i, tx_hash.hex()))
|
logg.debug('poll #{} for {}'.format(i, tx_hash.hex()))
|
||||||
i += 1
|
i += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if rcpt['status'] == 0:
|
return self.verifier(rcpt)
|
||||||
raise TransactionRevertError(tx_hash)
|
|
||||||
return rcpt
|
|
||||||
|
3
setup.py
3
setup.py
@ -24,7 +24,7 @@ f.close()
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="crypto-dev-signer",
|
name="crypto-dev-signer",
|
||||||
version="0.4.13a4",
|
version="0.4.13b1",
|
||||||
description="A signer and keystore daemon and library for cryptocurrency software development",
|
description="A signer and keystore daemon and library for cryptocurrency software development",
|
||||||
author="Louis Holbrook",
|
author="Louis Holbrook",
|
||||||
author_email="dev@holbrook.no",
|
author_email="dev@holbrook.no",
|
||||||
@ -34,6 +34,7 @@ setup(
|
|||||||
'crypto_dev_signer.eth',
|
'crypto_dev_signer.eth',
|
||||||
'crypto_dev_signer.keystore',
|
'crypto_dev_signer.keystore',
|
||||||
'crypto_dev_signer.runnable',
|
'crypto_dev_signer.runnable',
|
||||||
|
'crypto_dev_signer.helper',
|
||||||
'crypto_dev_signer',
|
'crypto_dev_signer',
|
||||||
],
|
],
|
||||||
install_requires=requirements,
|
install_requires=requirements,
|
||||||
|
@ -23,6 +23,9 @@ class MockEthTxBackend:
|
|||||||
def reporter(self, tx):
|
def reporter(self, tx):
|
||||||
logg.debug('reporter {}'.format(tx))
|
logg.debug('reporter {}'.format(tx))
|
||||||
|
|
||||||
|
def verifier(self, rcpt):
|
||||||
|
logg.debug('reporter {}'.format(rcpt))
|
||||||
|
|
||||||
def fee_price_helper(self):
|
def fee_price_helper(self):
|
||||||
return 21
|
return 21
|
||||||
|
|
||||||
@ -30,19 +33,18 @@ class MockEthTxBackend:
|
|||||||
logg.debug('fee helper code {} inputs {}'.format(code, inputs))
|
logg.debug('fee helper code {} inputs {}'.format(code, inputs))
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
def builder(self, a, b):
|
def builder(self, tx):
|
||||||
b = {
|
return {
|
||||||
'from': a['from'],
|
'from': tx['from'],
|
||||||
'to': '0x' + os.urandom(20).hex(),
|
'to': '0x' + os.urandom(20).hex(),
|
||||||
'data': '',
|
'data': '',
|
||||||
'gasPrice': a['feePrice'],
|
'gasPrice': tx['feePrice'],
|
||||||
'gas': a['fee'],
|
'gas': tx['feeUnits'],
|
||||||
}
|
}
|
||||||
return b
|
|
||||||
|
|
||||||
def builder_two(self, a, b):
|
def builder_two(self, tx):
|
||||||
b['value'] = 1024
|
tx['value'] = 1024
|
||||||
return b
|
return tx
|
||||||
|
|
||||||
|
|
||||||
class TestHelper(unittest.TestCase):
|
class TestHelper(unittest.TestCase):
|
||||||
@ -50,8 +52,9 @@ class TestHelper(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
logg.debug('setup')
|
logg.debug('setup')
|
||||||
self.db = DictKeystore()
|
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.address_hex = self.db.import_keystore_file(keystore_filepath, '')
|
||||||
self.signer = ReferenceSigner(self.db)
|
self.signer = ReferenceSigner(self.db)
|
||||||
@ -63,7 +66,7 @@ class TestHelper(unittest.TestCase):
|
|||||||
|
|
||||||
def test_helper(self):
|
def test_helper(self):
|
||||||
backend = MockEthTxBackend()
|
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}
|
tx_ish = {'from': self.address_hex}
|
||||||
executor.sign_and_send([backend.builder, backend.builder_two])
|
executor.sign_and_send([backend.builder, backend.builder_two])
|
||||||
|
Loading…
Reference in New Issue
Block a user