Compare commits

..

7 Commits

Author SHA1 Message Date
lash
a71b3d6388
Add changelog detail 2022-04-26 21:36:44 +00:00
lash
2dd92fe74b
Add fee limit, fee price to Tx object 2022-04-19 19:46:11 +00:00
lash
129e25bbf5
Bump chainlib dep 2022-04-10 19:05:58 +00:00
lash
a76020b13b
Add dict output 2022-04-10 19:04:50 +00:00
lash
3cfeb9ce84
Upgrade deps 2022-03-06 19:33:09 +00:00
lash
601db731d9
Handle int instead of hex signature values in pack from eth_tester 2022-03-01 14:43:43 +00:00
lash
c954f4d1b4
Allow encode without nonce when not tx, add rcpt src to tx 2022-03-01 07:50:30 +00:00
6 changed files with 48 additions and 12 deletions

View File

@ -1,3 +1,8 @@
- 0.1.1
* Add fee_limit, fee_price alias to Tx object
- 0.1.0:
* Allow nonce ommission in encode when not tx mode
* Add rcpt src to tx object
- 0.0.27: - 0.0.27:
* Add man pages with chainlib man page generator helper * Add man pages with chainlib man page generator helper
* Remove redundant arg flags from runnables: get * Remove redundant arg flags from runnables: get

View File

@ -11,8 +11,7 @@ import urllib
import sha3 import sha3
# external imports # external imports
import chainlib.eth.cli from chainlib.cli import flag_reset
from chainlib.eth.cli.encode import CLIEncoder
from funga.eth.signer import EIP155Signer from funga.eth.signer import EIP155Signer
from funga.eth.keystore.dict import DictKeystore from funga.eth.keystore.dict import DictKeystore
from hexathon import ( from hexathon import (
@ -21,6 +20,8 @@ from hexathon import (
) )
# local imports # local imports
import chainlib.eth.cli
from chainlib.eth.cli.encode import CLIEncoder
from chainlib.eth.constant import ZERO_ADDRESS from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.eth.address import to_checksum from chainlib.eth.address import to_checksum
from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.connection import EthHTTPConnection
@ -47,6 +48,7 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC | chainlib.eth.cli.Flag.FEE | chainlib.eth.cli.Flag.FMT_HUMAN | chainlib.eth.cli.Flag.FMT_WIRE | chainlib.eth.cli.Flag.FMT_RPC arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC | chainlib.eth.cli.Flag.FEE | chainlib.eth.cli.Flag.FMT_HUMAN | chainlib.eth.cli.Flag.FMT_WIRE | chainlib.eth.cli.Flag.FMT_RPC
arg_flags = flag_reset(arg_flags, chainlib.cli.Flag.NO_TARGET)
argparser = chainlib.eth.cli.ArgumentParser(arg_flags) argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
argparser.add_argument('--mode', type=str, choices=['tx', 'call', 'arg'], help='Mode of operation') argparser.add_argument('--mode', type=str, choices=['tx', 'call', 'arg'], help='Mode of operation')
argparser.add_argument('--signature', type=str, help='Method signature to encode') argparser.add_argument('--signature', type=str, help='Method signature to encode')
@ -131,9 +133,10 @@ def main():
if not config.get('_FEE_LIMIT'): if not config.get('_FEE_LIMIT'):
config.add(limit, '_FEE_LIMIT') config.add(limit, '_FEE_LIMIT')
if not config.get('_NONCE'): if mode == 'tx':
nonce_oracle = rpc.get_nonce_oracle() if not config.get('_NONCE'):
config.add(nonce_oracle.get_nonce(), '_NONCE') nonce_oracle = rpc.get_nonce_oracle()
config.add(nonce_oracle.get_nonce(), '_NONCE')
else: else:
for arg in [ for arg in [
'_FEE_PRICE', '_FEE_PRICE',

View File

@ -95,7 +95,11 @@ def pack(tx_src, chain_spec):
tx_src['r'], tx_src['r'],
tx_src['s'], tx_src['s'],
]: ]:
for b in bytes.fromhex(strip_0x(a)): try:
a = strip_0x(a)
except TypeError:
a = strip_0x(hex(a)) # believe it or not, eth_tester returns signatures as ints not hex
for b in bytes.fromhex(a):
signature[cursor] = b signature[cursor] = b
cursor += 1 cursor += 1
@ -425,6 +429,8 @@ class TxFactory:
return self.build_raw(tx) return self.build_raw(tx)
elif tx_format == TxFormat.RAW_ARGS: elif tx_format == TxFormat.RAW_ARGS:
return strip_0x(tx['data']) return strip_0x(tx['data'])
elif tx_format == TxFormat.DICT:
return tx
raise NotImplementedError('tx formatting {} not implemented'.format(tx_format)) raise NotImplementedError('tx formatting {} not implemented'.format(tx_format))
@ -550,6 +556,9 @@ class Tx(BaseTx):
self.outputs = [to_checksum(address_from)] self.outputs = [to_checksum(address_from)]
self.contract = None self.contract = None
self.fee_limit = self.gas_limit
self.fee_price = self.gas_price
try: try:
inpt = src['input'] inpt = src['input']
except KeyError: except KeyError:
@ -571,11 +580,12 @@ class Tx(BaseTx):
try: try:
self.wire = src['raw'] self.wire = src['raw']
except KeyError: except KeyError:
logg.warning('no inline raw tx src, and no raw rendering implemented, field will be "None"') logg.debug('no inline raw tx src, and no raw rendering implemented, field will be "None"')
self.status = Status.PENDING self.status = Status.PENDING
self.logs = None self.logs = None
self.tx_rcpt_src = None
if rcpt != None: if rcpt != None:
self.apply_receipt(rcpt, strict=strict) self.apply_receipt(rcpt, strict=strict)
@ -620,6 +630,10 @@ class Tx(BaseTx):
return self.src() return self.src()
def rcpt_src(self):
return self.tx_rcpt_src
def apply_receipt(self, rcpt, strict=False): def apply_receipt(self, rcpt, strict=False):
"""Apply receipt data to transaction object. """Apply receipt data to transaction object.
@ -630,6 +644,7 @@ class Tx(BaseTx):
""" """
rcpt = self.src_normalize(rcpt) rcpt = self.src_normalize(rcpt)
logg.debug('rcpt {}'.format(rcpt)) logg.debug('rcpt {}'.format(rcpt))
self.tx_rcpt_src = rcpt
tx_hash = add_0x(rcpt['transaction_hash']) tx_hash = add_0x(rcpt['transaction_hash'])
if rcpt['transaction_hash'] != add_0x(self.hash): if rcpt['transaction_hash'] != add_0x(self.hash):
@ -647,7 +662,7 @@ class Tx(BaseTx):
except KeyError as e: except KeyError as e:
if strict: if strict:
raise(e) raise(e)
logg.warning('setting "sucess" status on missing status property for {}'.format(self.hash)) logg.debug('setting "success" status on missing status property for {}'.format(self.hash))
status_number = 1 status_number = 1
if rcpt['block_number'] == None: if rcpt['block_number'] == None:

View File

@ -1,7 +1,7 @@
funga-eth~=0.5.6 funga-eth~=0.6.0
pysha3==1.0.2 pysha3==1.0.2
hexathon~=0.1.5 hexathon~=0.1.5
websocket-client==0.57.0 websocket-client==0.57.0
potaahto~=0.1.1 potaahto~=0.1.1
chainlib~=0.0.23 chainlib~=0.1.0
confini~=0.5.7 confini~=0.6.0

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chainlib-eth name = chainlib-eth
version = 0.0.27 version = 0.1.1
description = Ethereum implementation of the chainlib interface description = Ethereum implementation of the chainlib interface
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -50,6 +50,19 @@ class TxTestCase(EthTesterCase):
self.assertTrue(is_same_address(tx['to'], self.accounts[1])) self.assertTrue(is_same_address(tx['to'], self.accounts[1]))
def test_tx_repack(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
gas_oracle = RPCGasOracle(self.rpc)
c = Gas(signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle, chain_spec=self.chain_spec)
(tx_hash_hex, o) = c.create(self.accounts[0], self.accounts[1], 1024)
self.rpc.do(o)
o = transaction(tx_hash_hex)
tx_src = self.rpc.do(o)
tx = Tx(tx_src)
tx_bin = pack(tx.src(), self.chain_spec)
def test_tx_pack(self): def test_tx_pack(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
gas_oracle = RPCGasOracle(self.rpc) gas_oracle = RPCGasOracle(self.rpc)