Compare commits
31 Commits
lash/old-t
...
dev-0.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f90eb632f
|
||
|
|
7b7496a374
|
||
|
|
23f977482c
|
||
|
|
20dfb641ff
|
||
|
|
972535f1f9
|
||
|
|
a2168a50e3
|
||
|
|
9548ed5d1b
|
||
|
|
e499770d6d
|
||
|
|
e49fae9717
|
||
|
|
84c4a82abb
|
||
|
|
a71b3d6388
|
||
|
|
2dd92fe74b
|
||
|
|
129e25bbf5
|
||
|
|
a76020b13b
|
||
|
|
3cfeb9ce84
|
||
|
|
601db731d9
|
||
|
|
c954f4d1b4
|
||
|
|
b59eebe181
|
||
|
|
2f906037a9
|
||
|
|
1362c9aac6
|
||
|
|
e5e8680fc6
|
||
|
|
90d4c4eb95
|
||
|
|
edf8c4b604
|
||
|
|
f61ac91205
|
||
|
|
7e6daa0be3
|
||
|
|
a3081367db
|
||
|
|
d49e3dd6ec
|
||
|
|
d3f2b1f1fa
|
||
|
|
79a1123dc8
|
||
|
|
5c09630b6e
|
||
|
|
e9f31ed7f1
|
23
CHANGELOG
23
CHANGELOG
@@ -1,5 +1,28 @@
|
||||
- 0.2.0
|
||||
* Implement chainlib generic tx, block and tx result objects
|
||||
- 0.1.3
|
||||
* Add block author field
|
||||
- 0.1.2
|
||||
* Upgrade chainlib dep
|
||||
- 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:
|
||||
* Add man pages with chainlib man page generator helper
|
||||
* Remove redundant arg flags from runnables: get
|
||||
- 0.0.26:
|
||||
* Remove manual 0x handling bug in tx
|
||||
- 0.0.25:
|
||||
* Upgrade chainlib to get passphrase file for wallet keyfile
|
||||
- 0.0.24:
|
||||
* Upgrade from hexathon bug breaking compact hex function
|
||||
- 0.0.23:
|
||||
* Make get block args and responses compatible with picky golang marhaling in geth
|
||||
- 0.0.22:
|
||||
* Enable unpack of pre EIP-155 transactions
|
||||
* Allow missing status property of receipts in non-strict modes
|
||||
- 0.0.21:
|
||||
* Remove warnings from cytoolz/rlp in funga-eth
|
||||
- 0.0.15:
|
||||
|
||||
16
Makefile
Normal file
16
Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
PREFIX ?= /usr/local
|
||||
BUILD_DIR = build/$(PREFIX)/share/man
|
||||
|
||||
man:
|
||||
mkdir -vp $(BUILD_DIR)
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py gas` -v -n eth-gas -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py info` -v -n eth-info -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py get` -v -n eth-get -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py decode` -v -n eth-decode -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py encode` -v -n eth-encode -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py count` -v -n eth-count -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py raw` -v -n eth-raw -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py wait` -v -n eth-wait -d $(BUILD_DIR)/ man
|
||||
chainlib-man.py -b `PYTHONPATH=. python chainlib/eth/runnable/flags.py balance` -v -n eth-balance -d $(BUILD_DIR)/ man
|
||||
|
||||
.PHONY: man
|
||||
@@ -1,14 +1,16 @@
|
||||
import sys
|
||||
# external imports
|
||||
from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.block import Block as BaseBlock
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
even,
|
||||
compact,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from chainlib.eth.tx import Tx
|
||||
from .src import Src
|
||||
|
||||
|
||||
def block_latest(id_generator=None):
|
||||
@@ -34,7 +36,8 @@ def block_by_hash(hsh, include_tx=True, id_generator=None):
|
||||
def block_by_number(n, include_tx=True, id_generator=None):
|
||||
"""Implements chainlib.interface.ChainInterface method
|
||||
"""
|
||||
nhx = add_0x(even(hex(n)[2:]))
|
||||
hx = strip_0x(hex(n))
|
||||
nhx = add_0x(compact(hx), compact_value=True)
|
||||
j = JSONRPCRequest(id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_getBlockByNumber'
|
||||
@@ -74,7 +77,7 @@ def syncing(id_generator=None):
|
||||
return j.finalize(o)
|
||||
|
||||
|
||||
class Block(BaseBlock):
|
||||
class Block(BaseBlock, Src):
|
||||
"""Encapsulates an Ethereum block
|
||||
|
||||
:param src: Block representation data
|
||||
@@ -85,7 +88,9 @@ class Block(BaseBlock):
|
||||
tx_generator = Tx
|
||||
|
||||
def __init__(self, src):
|
||||
self.hash = src['hash']
|
||||
super(Block, self).__init__(src)
|
||||
import sys
|
||||
self.set_hash(src['hash'])
|
||||
try:
|
||||
self.number = int(strip_0x(src['number']), 16)
|
||||
except TypeError:
|
||||
@@ -96,9 +101,10 @@ class Block(BaseBlock):
|
||||
self.timestamp = int(strip_0x(src['timestamp']), 16)
|
||||
except TypeError:
|
||||
self.timestamp = int(src['timestamp'])
|
||||
self.author = src['author']
|
||||
|
||||
|
||||
def get_tx(self, tx_hash):
|
||||
def tx_index_by_hash(self, tx_hash):
|
||||
i = 0
|
||||
idx = -1
|
||||
tx_hash = add_0x(tx_hash)
|
||||
@@ -115,4 +121,3 @@ class Block(BaseBlock):
|
||||
if idx == -1:
|
||||
raise AttributeError('tx {} not found in block {}'.format(tx_hash, self.hash))
|
||||
return idx
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from chainlib.cli import (
|
||||
argflag_std_read,
|
||||
argflag_std_write,
|
||||
argflag_std_base,
|
||||
reset as argflag_reset,
|
||||
argflag_std_base_read,
|
||||
flag_reset as argflag_reset,
|
||||
Flag,
|
||||
)
|
||||
|
||||
2
chainlib/eth/data/env/env.ini
vendored
Normal file
2
chainlib/eth/data/env/env.ini
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
[rpc]
|
||||
provider = Fully-qualified URL to EVM node's RPC endpoint.
|
||||
@@ -25,7 +25,7 @@ logg = logging.getLogger()
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||
|
||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
||||
arg_flags = chainlib.eth.cli.argflag_std_base_read | chainlib.eth.cli.Flag.WALLET
|
||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||
argparser.add_positional('address', type=str, help='Ethereum address of recipient')
|
||||
args = argparser.parse_args()
|
||||
|
||||
@@ -11,8 +11,7 @@ import urllib
|
||||
import sha3
|
||||
|
||||
# external imports
|
||||
import chainlib.eth.cli
|
||||
from chainlib.eth.cli.encode import CLIEncoder
|
||||
from chainlib.cli import flag_reset
|
||||
from funga.eth.signer import EIP155Signer
|
||||
from funga.eth.keystore.dict import DictKeystore
|
||||
from hexathon import (
|
||||
@@ -21,6 +20,8 @@ from hexathon import (
|
||||
)
|
||||
|
||||
# local imports
|
||||
import chainlib.eth.cli
|
||||
from chainlib.eth.cli.encode import CLIEncoder
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from chainlib.eth.address import to_checksum
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
@@ -28,14 +29,6 @@ from chainlib.jsonrpc import (
|
||||
JSONRPCRequest,
|
||||
IntSequenceGenerator,
|
||||
)
|
||||
from chainlib.eth.nonce import (
|
||||
RPCNonceOracle,
|
||||
OverrideNonceOracle,
|
||||
)
|
||||
from chainlib.eth.gas import (
|
||||
RPCGasOracle,
|
||||
OverrideGasOracle,
|
||||
)
|
||||
from chainlib.eth.tx import (
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
@@ -53,18 +46,20 @@ logg = logging.getLogger()
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
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
|
||||
|
||||
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.add_argument('--notx', action='store_true', help='Network send is not a transaction')
|
||||
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('contract_args', type=str, nargs='*', help='arguments to encode')
|
||||
args = argparser.parse_args()
|
||||
extra_args = {
|
||||
'signature': None,
|
||||
'contract_args': None,
|
||||
'notx': None,
|
||||
}
|
||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_config_dir=config_dir)
|
||||
logg.debug('config loaded:\n{}'.format(config))
|
||||
|
||||
block_all = args.ww
|
||||
block_last = args.w or block_all
|
||||
@@ -102,28 +97,64 @@ def main():
|
||||
|
||||
code += cli_encoder.get()
|
||||
|
||||
if not config.get('_SIGNATURE'):
|
||||
print(strip_0x(code))
|
||||
return
|
||||
|
||||
exec_address = config.get('_EXEC_ADDRESS')
|
||||
if exec_address:
|
||||
exec_address = add_0x(to_checksum_address(exec_address))
|
||||
|
||||
if signer == None or config.true('_NOTX'):
|
||||
if config.true('_RAW'):
|
||||
print(strip_0x(code))
|
||||
return
|
||||
mode = args.mode
|
||||
if mode == None:
|
||||
if signer == None:
|
||||
mode = 'call'
|
||||
else:
|
||||
mode = 'tx'
|
||||
|
||||
if not exec_address:
|
||||
argparser.error('exec address (-e) must be defined')
|
||||
if not config.get('_SIGNATURE'):
|
||||
if mode != 'arg':
|
||||
logg.error('mode tx without contract method signature makes no sense. Use eth-get with --data instead.')
|
||||
sys.exit(1)
|
||||
if args.format == 'rpc':
|
||||
logg.error('rpc format with arg put does not make sense')
|
||||
sys.exit(1)
|
||||
|
||||
if mode == 'arg':
|
||||
print(strip_0x(code))
|
||||
return
|
||||
elif not exec_address:
|
||||
logg.error('exec address (-e) must be defined with mode "{}"'.format(args.mode))
|
||||
sys.exit(1)
|
||||
|
||||
if config.get('RPC_PROVIDER'):
|
||||
logg.debug('provider {}'.format(config.get('RPC_PROVIDER')))
|
||||
if not config.get('_FEE_LIMIT') or not config.get('_FEE_PRICE'):
|
||||
gas_oracle = rpc.get_gas_oracle()
|
||||
(price, limit) = gas_oracle.get_gas()
|
||||
if not config.get('_FEE_PRICE'):
|
||||
config.add(price, '_FEE_PRICE')
|
||||
if not config.get('_FEE_LIMIT'):
|
||||
config.add(limit, '_FEE_LIMIT')
|
||||
|
||||
if mode == 'tx':
|
||||
if not config.get('_NONCE'):
|
||||
nonce_oracle = rpc.get_nonce_oracle()
|
||||
config.add(nonce_oracle.get_nonce(), '_NONCE')
|
||||
else:
|
||||
for arg in [
|
||||
'_FEE_PRICE',
|
||||
'_FEE_LIMIT',
|
||||
'_NONCE',
|
||||
]:
|
||||
if not config.get(arg):
|
||||
logg.error('--{} must be specified when no rpc provider has been set.'.format(arg.replace('_', '-').lower()))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if mode == 'call': #signer == None or config.true('_NOTX'):
|
||||
c = TxFactory(chain_spec)
|
||||
j = JSONRPCRequest(id_generator=rpc.id_generator)
|
||||
o = j.template()
|
||||
o['method'] = 'eth_call'
|
||||
gas_limit = add_0x(int.to_bytes(config.get('_FEE_LIMIT'), 8, byteorder='big').hex(), compact_value=True)
|
||||
gas_price = add_0x(int.to_bytes(config.get('_FEE_PRICE'), 8, byteorder='big').hex(), compact_value=True)
|
||||
o['method'] = 'eth_call'
|
||||
o['params'].append({
|
||||
'to': exec_address,
|
||||
'from': signer_address,
|
||||
@@ -135,16 +166,22 @@ def main():
|
||||
height = to_blockheight_param(config.get('_HEIGHT'))
|
||||
o['params'].append(height)
|
||||
o = j.finalize(o)
|
||||
r = conn.do(o)
|
||||
try:
|
||||
print(strip_0x(r))
|
||||
return
|
||||
except ValueError:
|
||||
sys.stderr.write('query returned an empty value ({})\n'.format(r))
|
||||
sys.exit(1)
|
||||
|
||||
if not exec_address:
|
||||
argparser.error('exec address (-e) must be defined')
|
||||
if config.get('_RPC_SEND'):
|
||||
r = conn.do(o)
|
||||
try:
|
||||
print(strip_0x(r))
|
||||
return
|
||||
except ValueError:
|
||||
sys.stderr.write('query returned an empty value ({})\n'.format(r))
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(o)
|
||||
return
|
||||
|
||||
if signer == None:
|
||||
logg.error('mode "tx" without signer does not make sense. Please specify a key file with -y.')
|
||||
sys.exit(1)
|
||||
|
||||
if chain_spec == None:
|
||||
raise ValueError('chain spec must be specified')
|
||||
|
||||
23
chainlib/eth/runnable/flags.py
Normal file
23
chainlib/eth/runnable/flags.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# standard imports
|
||||
import sys
|
||||
|
||||
# external imports
|
||||
import chainlib.eth.cli
|
||||
from hexathon import add_0x
|
||||
|
||||
cmds = {
|
||||
'gas': chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.WALLET,
|
||||
'info': chainlib.eth.cli.argflag_reset(chainlib.cli.argflag_std_base_read, chainlib.eth.cli.Flag.CHAIN_SPEC),
|
||||
'get': chainlib.eth.cli.argflag_reset(chainlib.cli.argflag_std_base_read, chainlib.eth.cli.Flag.CHAIN_SPEC),
|
||||
'decode': chainlib.cli.argflag_std_base | chainlib.eth.cli.Flag.CHAIN_SPEC,
|
||||
'encode': 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,
|
||||
'count': chainlib.eth.cli.argflag_std_base_read | chainlib.eth.cli.Flag.WALLET,
|
||||
'raw': chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC,
|
||||
'balance': chainlib.eth.cli.argflag_std_base | chainlib.eth.cli.Flag.WALLET,
|
||||
'wait': chainlib.eth.cli.argflag_reset(chainlib.eth.cli.argflag_std_base_read | chainlib.eth.cli.Flag.NO_TARGET | chainlib.eth.cli.Flag.RPC_AUTH, chainlib.eth.cli.Flag.CHAIN_SPEC | chainlib.eth.cli.Flag.RAW),
|
||||
'checksum': 0,
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
b = cmds[sys.argv[1]]
|
||||
print(add_0x(hex(b)))
|
||||
@@ -48,7 +48,8 @@ logg = logging.getLogger()
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||
|
||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
||||
arg_flags = chainlib.eth.cli.argflag_std_base_read
|
||||
arg_flags = chainlib.eth.cli.argflag_reset(arg_flags, chainlib.eth.cli.Flag.CHAIN_SPEC)
|
||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||
argparser.add_positional('item', type=str, help='Address or transaction to retrieve data for')
|
||||
args = argparser.parse_args()
|
||||
|
||||
@@ -105,7 +105,10 @@ def main():
|
||||
|
||||
o = block_latest(id_generator=rpc.id_generator)
|
||||
r = conn.do(o)
|
||||
n = int(r, 16)
|
||||
try:
|
||||
n = int(r, 16)
|
||||
except ValueError:
|
||||
n = int(r)
|
||||
first_block_number = n
|
||||
if human:
|
||||
n = format(n, ',')
|
||||
|
||||
@@ -51,6 +51,7 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
|
||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||
argparser.add_argument('--deploy', action='store_true', help='Deploy data as contract')
|
||||
argparser.add_argument('--mode', choices=['tx', 'call'], type=str, help='Mode of operation')
|
||||
argparser.add_positional('data', type=str, help='Transaction data')
|
||||
args = argparser.parse_args()
|
||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, default_config_dir=config_dir)
|
||||
|
||||
48
chainlib/eth/src.py
Normal file
48
chainlib/eth/src.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from potaahto.symbols import snake_and_camel
|
||||
from hexathon import (
|
||||
uniform,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from chainlib.src import (
|
||||
Src as BaseSrc,
|
||||
SrcItem,
|
||||
)
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Src(BaseSrc):
|
||||
|
||||
@classmethod
|
||||
def src_normalize(self, v):
|
||||
src = snake_and_camel(v)
|
||||
logg.debug('normalize has {}'.format(src))
|
||||
if isinstance(src.get('v'), str):
|
||||
try:
|
||||
src['v'] = int(src['v'])
|
||||
except ValueError:
|
||||
src['v'] = int(src['v'], 16)
|
||||
return src
|
||||
|
||||
|
||||
def normal(self, v, typ=SrcItem.AUTO):
|
||||
if typ == SrcItem.SRC:
|
||||
return self.src_normalize(v)
|
||||
|
||||
if typ == SrcItem.HASH:
|
||||
v = strip_0x(v, pad=False)
|
||||
v = uniform(v, compact_value=True)
|
||||
elif typ == SrcItem.ADDRESS:
|
||||
v = strip_0x(v, pad=False)
|
||||
v = uniform(v, compact_value=True)
|
||||
elif typ == SrcItem.PAYLOAD:
|
||||
v = strip_0x(v, pad=False, allow_empty=True)
|
||||
v = uniform(v, compact_value=False, allow_empty=True)
|
||||
|
||||
return v
|
||||
@@ -10,6 +10,8 @@ from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
compact,
|
||||
to_int as hex_to_int,
|
||||
same as hex_same,
|
||||
)
|
||||
from rlp import decode as rlp_decode
|
||||
from rlp import encode as rlp_encode
|
||||
@@ -22,12 +24,17 @@ from potaahto.symbols import snake_and_camel
|
||||
from chainlib.hash import keccak256_hex_to_hex
|
||||
from chainlib.status import Status
|
||||
from chainlib.jsonrpc import JSONRPCRequest
|
||||
from chainlib.tx import Tx as BaseTx
|
||||
from chainlib.tx import (
|
||||
Tx as BaseTx,
|
||||
TxResult as BaseTxResult,
|
||||
)
|
||||
from chainlib.eth.nonce import (
|
||||
nonce as nonce_query,
|
||||
nonce_confirmed as nonce_query_confirmed,
|
||||
)
|
||||
from chainlib.eth.address import is_same_address
|
||||
from chainlib.block import BlockSpec
|
||||
from chainlib.src import SrcItem
|
||||
|
||||
# local imports
|
||||
from .address import to_checksum
|
||||
@@ -39,6 +46,7 @@ from .constant import (
|
||||
)
|
||||
from .contract import ABIContractEncoder
|
||||
from .jsonrpc import to_blockheight_param
|
||||
from .src import Src
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
@@ -95,7 +103,11 @@ def pack(tx_src, chain_spec):
|
||||
tx_src['r'],
|
||||
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
|
||||
cursor += 1
|
||||
|
||||
@@ -397,11 +409,13 @@ class TxFactory:
|
||||
"""
|
||||
txe = EIP155Transaction(tx, tx['nonce'], tx['chainId'])
|
||||
txes = txe.serialize()
|
||||
gas_price = strip_0x(txes['gasPrice'])
|
||||
gas = strip_0x(txes['gas'])
|
||||
return {
|
||||
'from': tx['from'],
|
||||
'to': txes['to'],
|
||||
'gasPrice': '0x' + compact(txes['gasPrice']),
|
||||
'gas': '0x' + compact(txes['gas']),
|
||||
'gasPrice': add_0x(compact(gas_price)),
|
||||
'gas': add_0x(compact(gas)),
|
||||
'data': txes['data'],
|
||||
}
|
||||
|
||||
@@ -423,6 +437,8 @@ class TxFactory:
|
||||
return self.build_raw(tx)
|
||||
elif tx_format == TxFormat.RAW_ARGS:
|
||||
return strip_0x(tx['data'])
|
||||
elif tx_format == TxFormat.DICT:
|
||||
return tx
|
||||
raise NotImplementedError('tx formatting {} not implemented'.format(tx_format))
|
||||
|
||||
|
||||
@@ -502,7 +518,51 @@ class TxFactory:
|
||||
return o
|
||||
|
||||
|
||||
class Tx(BaseTx):
|
||||
class TxResult(BaseTxResult, Src):
|
||||
|
||||
def apply_src(self, v):
|
||||
self.contract = None
|
||||
|
||||
v = super(TxResult, self).apply_src(v)
|
||||
|
||||
self.set_hash(v['transaction_hash'])
|
||||
try:
|
||||
status_number = int(v['status'], 16)
|
||||
except TypeError:
|
||||
status_number = int(v['status'])
|
||||
except KeyError as e:
|
||||
if strict:
|
||||
raise(e)
|
||||
logg.debug('setting "success" status on missing status property for {}'.format(self.hash))
|
||||
status_number = 1
|
||||
|
||||
if v['block_number'] == None:
|
||||
self.status = Status.PENDING
|
||||
else:
|
||||
if status_number == 1:
|
||||
self.status = Status.SUCCESS
|
||||
elif status_number == 0:
|
||||
self.status = Status.ERROR
|
||||
try:
|
||||
self.tx_index = hex_to_int(v['transaction_index'])
|
||||
except TypeError:
|
||||
self.tx_index = int(v['transaction_index'])
|
||||
self.block_hash = v['block_hash']
|
||||
|
||||
|
||||
# TODO: replace with rpc receipt/transaction translator when available
|
||||
contract_address = v.get('contract_address')
|
||||
if contract_address != None:
|
||||
self.contract = contract_address
|
||||
|
||||
self.logs = v['logs']
|
||||
try:
|
||||
self.fee_cost = hex_to_int(v['gas_used'])
|
||||
except TypeError:
|
||||
self.fee_cost = int(v['gas_used'])
|
||||
|
||||
|
||||
class Tx(BaseTx, Src):
|
||||
"""Wraps transaction data, transaction receipt data and block data, enforces local standardization of fields, and provides useful output formats for viewing transaction contents.
|
||||
|
||||
If block is applied, the transaction data or transaction hash must exist in its transactions array.
|
||||
@@ -519,106 +579,88 @@ class Tx(BaseTx):
|
||||
#:todo: divide up constructor method
|
||||
"""
|
||||
|
||||
def __init__(self, src, block=None, rcpt=None):
|
||||
self.__rcpt_block_hash = None
|
||||
|
||||
src = self.src_normalize(src)
|
||||
self.index = -1
|
||||
tx_hash = add_0x(src['hash'])
|
||||
self.hash = strip_0x(tx_hash)
|
||||
if block != None:
|
||||
self.apply_block(block)
|
||||
try:
|
||||
self.value = int(strip_0x(src['value']), 16)
|
||||
except TypeError:
|
||||
self.value = int(src['value'])
|
||||
try:
|
||||
self.nonce = int(strip_0x(src['nonce']), 16)
|
||||
except TypeError:
|
||||
self.nonce = int(src['nonce'])
|
||||
address_from = strip_0x(src['from'])
|
||||
try:
|
||||
self.gas_price = int(strip_0x(src['gasPrice']), 16)
|
||||
except TypeError:
|
||||
self.gas_price = int(src['gasPrice'])
|
||||
try:
|
||||
self.gas_limit = int(strip_0x(src['gas']), 16)
|
||||
except TypeError:
|
||||
self.gas_limit = int(src['gas'])
|
||||
self.outputs = [to_checksum(address_from)]
|
||||
def __init__(self, src, block=None, result=None, strict=False, rcpt=None):
|
||||
# backwards compat
|
||||
self.gas_price = None
|
||||
self.gas_limit = None
|
||||
self.contract = None
|
||||
self.v = None
|
||||
self.r = None
|
||||
self.s = None
|
||||
|
||||
super(Tx, self).__init__(src, block=block, result=result, strict=strict)
|
||||
|
||||
if result == None and rcpt != None:
|
||||
self.apply_receipt(rcpt)
|
||||
|
||||
|
||||
def apply_src(self, src):
|
||||
try:
|
||||
inpt = src['input']
|
||||
except KeyError:
|
||||
inpt = src['data']
|
||||
src['input'] = src['data']
|
||||
|
||||
if inpt != '0x':
|
||||
inpt = strip_0x(inpt)
|
||||
else:
|
||||
inpt = ''
|
||||
self.payload = inpt
|
||||
src = super(Tx, self).apply_src(src)
|
||||
|
||||
hsh = self.normal(src['hash'], SrcItem.HASH)
|
||||
self.set_hash(hsh)
|
||||
|
||||
try:
|
||||
self.value = hex_to_int(src['value'])
|
||||
except TypeError:
|
||||
self.value = int(src['value'])
|
||||
|
||||
try:
|
||||
self.nonce = hex_to_int(src['nonce'])
|
||||
except TypeError:
|
||||
self.nonce = int(src['nonce'])
|
||||
|
||||
try:
|
||||
self.fee_limit = hex_to_int(src['gas'])
|
||||
except TypeError:
|
||||
self.fee_limit = int(src['gas'])
|
||||
|
||||
try:
|
||||
self.fee_price = hex_to_int(src['gas_price'])
|
||||
except TypeError:
|
||||
self.fee_price = int(src['gas_price'])
|
||||
|
||||
self.gas_price = self.fee_price
|
||||
self.gas_limit = self.fee_limit
|
||||
|
||||
address_from = self.normal(src['from'], SrcItem.ADDRESS)
|
||||
self.outputs = [to_checksum(address_from)]
|
||||
|
||||
to = src['to']
|
||||
if to == None:
|
||||
to = ZERO_ADDRESS
|
||||
self.inputs = [to_checksum(strip_0x(to))]
|
||||
|
||||
self.block = block
|
||||
self.payload = self.normal(src['input'], SrcItem.PAYLOAD)
|
||||
|
||||
try:
|
||||
self.wire = src['raw']
|
||||
self.set_wire(src['raw'])
|
||||
except KeyError:
|
||||
logg.warning('no inline raw tx src, and no raw rendering implemented, field will be "None"')
|
||||
|
||||
self.status = Status.PENDING
|
||||
self.logs = None
|
||||
|
||||
if rcpt != None:
|
||||
self.apply_receipt(rcpt)
|
||||
logg.debug('no inline raw tx src, and no raw rendering implemented, field will be "None"')
|
||||
|
||||
self.v = src.get('v')
|
||||
self.r = src.get('r')
|
||||
self.s = src.get('s')
|
||||
|
||||
self.wire = None
|
||||
|
||||
self.tx_src = src
|
||||
|
||||
|
||||
def src(self):
|
||||
"""Retrieve normalized representation source used to construct transaction object.
|
||||
|
||||
:rtype: dict
|
||||
:returns: Transaction representation
|
||||
"""
|
||||
return self.tx_src
|
||||
|
||||
|
||||
@classmethod
|
||||
def src_normalize(self, src):
|
||||
"""Normalizes transaction representation source data.
|
||||
|
||||
:param src: Transaction representation
|
||||
:type src: dict
|
||||
:rtype: dict
|
||||
:returns: Transaction representation, normalized
|
||||
"""
|
||||
src = snake_and_camel(src)
|
||||
|
||||
if isinstance(src.get('v'), str):
|
||||
try:
|
||||
src['v'] = int(src['v'])
|
||||
except ValueError:
|
||||
src['v'] = int(src['v'], 16)
|
||||
return src
|
||||
#self.status = Status.PENDING
|
||||
|
||||
|
||||
def as_dict(self):
|
||||
return self.src()
|
||||
return self.src
|
||||
|
||||
|
||||
def apply_receipt(self, rcpt):
|
||||
def apply_receipt(self, rcpt, strict=False):
|
||||
result = TxResult(rcpt)
|
||||
self.apply_result(result)
|
||||
|
||||
|
||||
def apply_result(self, result, strict=False):
|
||||
"""Apply receipt data to transaction object.
|
||||
|
||||
Effect is the same as passing a receipt at construction.
|
||||
@@ -626,46 +668,14 @@ class Tx(BaseTx):
|
||||
:param rcpt: Receipt data
|
||||
:type rcpt: dict
|
||||
"""
|
||||
rcpt = self.src_normalize(rcpt)
|
||||
logg.debug('rcpt {}'.format(rcpt))
|
||||
if not hex_same(result.hash, self.hash):
|
||||
raise ValueError('result hash {} does not match transaction hash {}'.format(result.hash, self.hash))
|
||||
|
||||
tx_hash = add_0x(rcpt['transaction_hash'])
|
||||
if rcpt['transaction_hash'] != add_0x(self.hash):
|
||||
raise ValueError('rcpt hash {} does not match transaction hash {}'.format(rcpt['transaction_hash'], self.hash))
|
||||
|
||||
block_hash = add_0x(rcpt['block_hash'])
|
||||
if self.block != None:
|
||||
if block_hash != add_0x(self.block.hash):
|
||||
raise ValueError('rcpt block hash {} does not match transaction block hash {}'.format(rcpt['block_hash'], self.block.hash))
|
||||
if not hex_same(result.block_hash, self.block.hash):
|
||||
raise ValueError('result block hash {} does not match transaction block hash {}'.format(result.block_hash, self.block.hash))
|
||||
|
||||
try:
|
||||
status_number = int(rcpt['status'], 16)
|
||||
except TypeError:
|
||||
status_number = int(rcpt['status'])
|
||||
if rcpt['block_number'] == None:
|
||||
self.status = Status.PENDING
|
||||
else:
|
||||
if status_number == 1:
|
||||
self.status = Status.SUCCESS
|
||||
elif status_number == 0:
|
||||
self.status = Status.ERROR
|
||||
try:
|
||||
self.tx_index = int(rcpt['transaction_index'], 16)
|
||||
except TypeError:
|
||||
self.tx_index = int(rcpt['transaction_index'])
|
||||
# TODO: replace with rpc receipt/transaction translator when available
|
||||
contract_address = rcpt.get('contractAddress')
|
||||
if contract_address == None:
|
||||
contract_address = rcpt.get('contract_address')
|
||||
if contract_address != None:
|
||||
self.contract = contract_address
|
||||
self.logs = rcpt['logs']
|
||||
try:
|
||||
self.gas_used = int(rcpt['gasUsed'], 16)
|
||||
except TypeError:
|
||||
self.gas_used = int(rcpt['gasUsed'])
|
||||
|
||||
self.__rcpt_block_hash = rcpt['block_hash']
|
||||
super(Tx, self).apply_result(result)
|
||||
|
||||
|
||||
def apply_block(self, block):
|
||||
@@ -674,9 +684,6 @@ class Tx(BaseTx):
|
||||
:param block: Block object
|
||||
:type block: chainlib.block.Block
|
||||
"""
|
||||
if self.__rcpt_block_hash != None:
|
||||
if block.hash != self.__rcpt_block_hash:
|
||||
raise ValueError('block hash {} does not match already applied receipt block hash {}'.format(block.hash, self.__rcpt_block_hash))
|
||||
self.index = block.get_tx(self.hash)
|
||||
self.block = block
|
||||
|
||||
@@ -690,18 +697,18 @@ class Tx(BaseTx):
|
||||
:returns: Wire format, in hex
|
||||
"""
|
||||
if self.wire == None:
|
||||
b = pack(self.src(), chain_spec)
|
||||
self.wire = add_0x(b.hex())
|
||||
b = pack(self.src, chain_spec)
|
||||
self.set_wire(add_0x(b.hex()))
|
||||
return self.wire
|
||||
|
||||
|
||||
@staticmethod
|
||||
def from_src(src, block=None, rcpt=None):
|
||||
def from_src(src, block=None, rcpt=None, strict=False):
|
||||
"""Creates a new Tx object.
|
||||
|
||||
Alias of constructor.
|
||||
"""
|
||||
return Tx(src, block=block, rcpt=rcpt)
|
||||
return Tx(src, block=block, rcpt=rcpt, strict=strict)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
@@ -743,7 +750,7 @@ input {}
|
||||
if self.status != Status.PENDING:
|
||||
s += """gas_used {}
|
||||
""".format(
|
||||
self.gas_used,
|
||||
self.result.fee_cost,
|
||||
)
|
||||
|
||||
s += 'status ' + self.status.name + '\n'
|
||||
@@ -755,7 +762,7 @@ tx_index {}
|
||||
""".format(
|
||||
self.block.number,
|
||||
self.block.hash,
|
||||
self.tx_index,
|
||||
self.result.tx_index,
|
||||
)
|
||||
|
||||
|
||||
@@ -768,7 +775,9 @@ tx_index {}
|
||||
if self.wire != None:
|
||||
s += """src {}
|
||||
""".format(
|
||||
self.wire,
|
||||
str(self.wire),
|
||||
)
|
||||
|
||||
return s
|
||||
|
||||
|
||||
|
||||
16
man/eth-balance.head.groff
Normal file
16
man/eth-balance.head.groff
Normal file
@@ -0,0 +1,16 @@
|
||||
.TH eth-balance 1
|
||||
|
||||
.SH NAME
|
||||
eth-balance \- Get network gas token balance for an address
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBeth-balance\fP [ -p \fIrpc_provider\fP ] \fIaddress\fP
|
||||
|
||||
.SH DESCRIPTION
|
||||
.P
|
||||
Query the network for the gas token balance of an account.
|
||||
.P
|
||||
The balance will be returned as an integer value denominated in the gas unit.
|
||||
|
||||
|
||||
.SS OPTION
|
||||
1
man/eth-balance.overrides
Normal file
1
man/eth-balance.overrides
Normal file
@@ -0,0 +1 @@
|
||||
a Address to get balance for. -a, --address
|
||||
7
man/eth-checksum.custom.groff
Normal file
7
man/eth-checksum.custom.groff
Normal file
@@ -0,0 +1,7 @@
|
||||
.SH ABOUT THE CHECKSUM
|
||||
.P
|
||||
Checksum protection may be used as protection against address typos.
|
||||
.P
|
||||
It uses the value of the address itself as input to an algorithm, which results in altering the case of the letters in the hexadecimal address.
|
||||
.P
|
||||
A checksum address consisting of only numbers will always pass checksum.
|
||||
11
man/eth-checksum.head.groff
Normal file
11
man/eth-checksum.head.groff
Normal file
@@ -0,0 +1,11 @@
|
||||
.TH eth-checksum 1
|
||||
|
||||
.SH NAME
|
||||
eth-checksum \- Calculate checksum address
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBeth-checksum\fP \fIaddress\fP
|
||||
|
||||
.SH DESCRIPTION
|
||||
.P
|
||||
Converts \fIaddress\fP into a checksum-protected address.
|
||||
15
man/eth-count.head.groff
Normal file
15
man/eth-count.head.groff
Normal file
@@ -0,0 +1,15 @@
|
||||
.TH eth-count 1
|
||||
|
||||
.SH NAME
|
||||
eth-count \- Get transaction count for an address
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBeth-count\fP [ -p \fIrpc_provider\fP ] \fIaddress\fP
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
.P
|
||||
Query the network for the number of transactions known for an account. The result can be used as the \fInonce\fP value for a consecutive transaction.
|
||||
|
||||
|
||||
.SS OPTIONS
|
||||
1
man/eth-count.overrides
Normal file
1
man/eth-count.overrides
Normal file
@@ -0,0 +1 @@
|
||||
a Address to count transactions for. -a, --address
|
||||
14
man/eth-decode.head.groff
Normal file
14
man/eth-decode.head.groff
Normal file
@@ -0,0 +1,14 @@
|
||||
.TH eth-decode 1
|
||||
|
||||
.SH NAME
|
||||
eth-decode \- Decode a transaction in wire-format to human readable form
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBeth-decode\fI [ -i \fIchain_spec\fP ] encoded_tx
|
||||
|
||||
.SH DESCRIPTION
|
||||
.P
|
||||
This tool deserializes a wire-format transaction and outputs its fields in human-readable form. It does not require a node to operate, and does not apply transaction state.
|
||||
.P
|
||||
The transaction wire-format is an ordered concatenation of transaction values, which in turn is serialized using the Recurive Length Prefix (RLP) format. \fBeth-decode\fP accepts the RLP-encoded transaction as a hex string.
|
||||
.P
|
||||
31
man/eth-encode.custom.groff
Normal file
31
man/eth-encode.custom.groff
Normal file
@@ -0,0 +1,31 @@
|
||||
.SH MODES
|
||||
|
||||
The modes parameter specifies what kind of operaion the encoding should be generated for. There are three valid modes:
|
||||
|
||||
.SS tx
|
||||
Generates a transaction that changes state. Used with \fB--format\fP \fIrpc\fP it will generate an \fIeth_sendRawTransaction\fP jsonrpc object. Used with \fB--format\fP \fIbin\fP it outputs signed RLP only in hexdecimal.
|
||||
|
||||
.SS call
|
||||
Generates a query that reads state. Used with \fB--format\fP \fIrpc\fP it will generate a \fIeth_call\fP jsonrpc object with applicable fields filled out from environment, arguments and/or rpc retrieval. \fB--format\fP \fIbin\fP is not valid for this mode.
|
||||
|
||||
.SS arg
|
||||
Encodes the argument part only, optionally with a method signature. \fB--format\fP \fIrpc\fP is not valid for this mode.
|
||||
|
||||
.SH SPECIFYING VALUES
|
||||
Dynamic value types are not yet supported.
|
||||
|
||||
.SS Specifying an unsigned integer:
|
||||
.IP u:1024
|
||||
|
||||
.SS Specifying an address:
|
||||
.IP a:19062190B1925b5b6689D7073fDfC8c2976EF8Cb
|
||||
|
||||
.SS Specifying bytes values:
|
||||
|
||||
.IP b:deadbeef
|
||||
.IP b4:deadbeef
|
||||
.IP b32:deadbeef
|
||||
|
||||
.SS Specifying a string value:
|
||||
|
||||
.IP s:foobar
|
||||
22
man/eth-encode.examples.groff
Normal file
22
man/eth-encode.examples.groff
Normal file
@@ -0,0 +1,22 @@
|
||||
.SS Build a signed ERC20 transfer in wire format, setting nonce and fee details manually.
|
||||
.EX
|
||||
$ eth-encode -f bin -y <\fIkey_file_path\fP> -e <\fItoken_address\fP> --fee-price 1000000000 --fee-limit 100000 --nonce 42 --signature transfer a:00000000000000000000000000000000DeaDBeef u:1024
|
||||
.EE
|
||||
|
||||
.SS Build Smart contract call with method signature, retrieving fee and nonce settings from rpc
|
||||
|
||||
\fBeth-encode\fP --mode call -f rpc -e <\fItoken_address\fP> --signature balanceOf -p <\fIrpc_endpoint\fP> a:deadbeef
|
||||
|
||||
.SS Build smart contract ERC20 transfer argument with signature
|
||||
.EX
|
||||
\fBeth-encode\fP --mode arg --signature transfer a:00000000000000000000000000000000DeaDBeef u:1024
|
||||
.TP Outupt
|
||||
a9059cbb00000000000000000000000000000000000000000000000000000000deadbeef0000000000000000000000000000000000000000000000000000000000000400
|
||||
.EE
|
||||
|
||||
.SS Build smart contract ERC20 transfer argument types without signature
|
||||
.EX
|
||||
\fBeth-encode\fP --mode arg a:00000000000000000000000000000000DeaDBeef u:1024
|
||||
.TP Output
|
||||
00000000000000000000000000000000000000000000000000000000deadbeef0000000000000000000000000000000000000000000000000000000000000400
|
||||
.EE
|
||||
17
man/eth-encode.head.groff
Normal file
17
man/eth-encode.head.groff
Normal file
@@ -0,0 +1,17 @@
|
||||
.TH eth-encode 1
|
||||
|
||||
.SH NAME
|
||||
eth-encode \- Encode arbitrary contract calls and transactions
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBeth-encode\fP [ --mode \fImode\fP ] [ -f \fIformat\fP ] [ -p \fIrpc_provider\fP ] [ -i \fIchain_Spec\fP] [ -s ] [ -w ] [ -e \fIsmart_contract_address\fP ] --signature \fIcontract_method_name\fP [ \fIvalue_specifiers\fP ... ]
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
Generate wire-format or rpc query any EVM smart contract call or transaction by specifying method and arguments.
|
||||
|
||||
The resulting call or transaction can either be stored offline for later use, or directly sent to the network using the \fB-s\fP option.
|
||||
|
||||
A description of value formatting is given in the \fBSPECIFYING VALUES\fP section below. Usage is demonstrated in the \fBEXAMPLES\fP section.
|
||||
|
||||
.SS OPTIONS
|
||||
1
man/eth-encode.overrides
Normal file
1
man/eth-encode.overrides
Normal file
@@ -0,0 +1 @@
|
||||
mode Mode of operation encoding is for. Must be one of "tx," "call," or "arg." See \fBMODES\fP below. --mode mode
|
||||
75
man/eth-gas.examples.groff
Normal file
75
man/eth-gas.examples.groff
Normal file
@@ -0,0 +1,75 @@
|
||||
.P
|
||||
In the follwing we willconsaider transactions signed by the private key for address Eb3907eCad74a0013c259D5874AE7f22DcBcC95C:
|
||||
|
||||
.SS Offline transaction
|
||||
|
||||
.EX
|
||||
$ eth-gas -y <\fIkey_file_path\fP> -a 00000000000000000000000000000000DeaDBeef --fee-price 100000000000 --fee-limit 21000 --nonce 42 1024
|
||||
from: Eb3907eCad74a0013c259D5874AE7f22DcBcC95C
|
||||
to: 00000000000000000000000000000000DeaDBeef
|
||||
nonce: 42
|
||||
gasPrice: 100000000000 (100 gwei)
|
||||
gas: 21000
|
||||
value: 1024 (0.000000000000001024 eth)
|
||||
data: 0x
|
||||
v: 37
|
||||
recovery_byte: 0
|
||||
r: 0x0c97432d4db724e66a56f7ced04174cf6129e2555709f206dd6d3a156b4af23a
|
||||
s: 0x287862548314a59c7ca6139eee8b51400eb40a67b08b8dc13d67302abecccae0
|
||||
chainId: 1
|
||||
hash: 0x003030af05460633e85b16fff7a17607818dc67e58f89396e5491ad6f5438971
|
||||
hash_unsigned: 0xa59cf9e5438b186de381892b7879ce66476d5469478c7148880da5d553ade651
|
||||
src: 0xf8662a85174876e8008252089400000000000000000000000000000000deadbeef8204008025a00c97432d4db724e66a56f7ced04174cf6129e2555709f206dd6d3a156b4af23aa0287862548314a59c7ca6139eee8b51400eb40a67b08b8dc13d67302abecccae0
|
||||
.EE
|
||||
|
||||
.SS Offline transaction with arbitrary data
|
||||
|
||||
.EX
|
||||
$ eth-gas -y <\fIkey_file_path\fP> -a 00000000000000000000000000000000DeaDBeef --fee-price 100000000000 --fee-limit 21000 --nonce 42 --data 0x2a 1024
|
||||
from: Eb3907eCad74a0013c259D5874AE7f22DcBcC95C
|
||||
to: 00000000000000000000000000000000DeaDBeef
|
||||
nonce: 42
|
||||
gasPrice: 100000000000 (100 gwei)
|
||||
gas: 21000
|
||||
value: 1024 (0.000000000000001024 eth)
|
||||
data: 0x2a
|
||||
v: 37
|
||||
recovery_byte: 0
|
||||
r: 0x800b6982d3f178201d7e7e7693b9c90b3fbcd54d04b6fff5284c81101fad54dd
|
||||
s: 0x3b86d710d31ac74b58f0040b0f51fdb6bdbabea62a68cf99c05e765e7e81de87
|
||||
chainId: 1
|
||||
hash: 0xede30052befd80760c5ab543babdccc3d97fe90523e5710d77220155a82faa47
|
||||
hash_unsigned: 0xad82d8cf1a412541c8a94ef71c50e9172c3a37853af036adee2f55c577da9770
|
||||
src: 0xf8662a85174876e8008252089400000000000000000000000000000000deadbeef8204002a25a0800b6982d3f178201d7e7e7693b9c90b3fbcd54d04b6fff5284c81101fad54dda03b86d710d31ac74b58f0040b0f51fdb6bdbabea62a68cf99c05e765e7e81de87
|
||||
.EE
|
||||
|
||||
.SS Offline transaction with wire-format output
|
||||
|
||||
.EX
|
||||
$ eth-gas -y <\fIkey_file_path\fP> -a 00000000000000000000000000000000DeaDBeef --fee-price 100000000000 --fee-limit 21000 --nonce 42 --raw 1024
|
||||
0xf8662a85174876e8008252089400000000000000000000000000000000deadbeef8204008025a00c97432d4db724e66a56f7ced04174cf6129e2555709f206dd6d3a156b4af23aa0287862548314a59c7ca6139eee8b51400eb40a67b08b8dc13d67302abecccae0
|
||||
.EE
|
||||
|
||||
.SS Sign transaction for a different network
|
||||
|
||||
.EX
|
||||
$ eth-gas -i evm:london:3:rinkeby -y /home/lash/src/contrib/grassrootseconomics/cic-dev/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c -a 00000000000000000000000000000000DeaDBeef --fee-price 100000000000 --fee-limit 21000 --nonce 42 --data 0x2a 1024
|
||||
from: Eb3907eCad74a0013c259D5874AE7f22DcBcC95C
|
||||
to: 00000000000000000000000000000000DeaDBeef
|
||||
nonce: 42
|
||||
gasPrice: 100000000000 (100 gwei)
|
||||
gas: 21000
|
||||
value: 1024 (0.000000000000001024 eth)
|
||||
data: 0x2a
|
||||
v: 41
|
||||
recovery_byte: 0
|
||||
r: 0xe522c25784111a512cbf46f883e3bdacffc2cdbd465fa1042892c28fc10ee054
|
||||
s: 0x5f84eb51a0c9871cfcedaba4e6274b300014899b3a2fec9292de6fe5919bcd07
|
||||
chainId: 3
|
||||
hash: 0x771200a20072294a6a843b89b98d5f868c9aa94da75dacf6a9f5834dfd241199
|
||||
hash_unsigned: 0xa5f9e8a5cda6985d81f4129955b7529f48ecb54728badac16ec550384e3a2bcc
|
||||
src: 0xf8662a85174876e8008252089400000000000000000000000000000000deadbeef8204002a29a0e522c25784111a512cbf46f883e3bdacffc2cdbd465fa1042892c28fc10ee054a05f84eb51a0c9871cfcedaba4e6274b300014899b3a2fec9292de6fe5919bcd07
|
||||
.EE
|
||||
|
||||
.P
|
||||
The wire-format can in turn be decoded using the \fBeth-decode\fP tool)
|
||||
19
man/eth-gas.head.groff
Normal file
19
man/eth-gas.head.groff
Normal file
@@ -0,0 +1,19 @@
|
||||
.TH eth-gas 1
|
||||
.SH NAME
|
||||
eth-gas - Create EVM gas token transaction
|
||||
.SH SYNOPSIS
|
||||
.P
|
||||
\fBeth-gas\fP -a RECIPIENT -y KEYFILE [ -p \fIrpc_provider ] [ -s ] [ -u ] AMOUNT
|
||||
.P
|
||||
\fBeth-gas\fP -a RECIPIENT -y KEYFILE [ --fee-price PRICE ] [ --fee-limit LIMIT ] [ --nonce NONCE ] [ -s ] [ -u ] AMOUNT
|
||||
.SH DESCRIPTION
|
||||
\fBeth-gas\fP generates serialized gas token transactions in various output formats.
|
||||
|
||||
If an \fIrpc_provider\fP is available, the valuess \fIfee_price\fP and \fInonce\fP will be automatically retrieved if they are not explicitly specified. If missing values cannot be retrieved, an error will occur.
|
||||
|
||||
Providing all arguments enables fully offline creation of the transaction.
|
||||
|
||||
See \fBEXAMPLES\fP for more details on inputs and outputs.
|
||||
|
||||
|
||||
.SS OPTIONS
|
||||
1
man/eth-gas.overrides
Normal file
1
man/eth-gas.overrides
Normal file
@@ -0,0 +1 @@
|
||||
a Beneficiary of the gas token transaction.
|
||||
19
man/eth-get.head.groff
Normal file
19
man/eth-get.head.groff
Normal file
@@ -0,0 +1,19 @@
|
||||
.TH eth-get 1
|
||||
|
||||
.SH NAME
|
||||
eth-get \- Retrieve transaction and transaction state from network
|
||||
|
||||
.SH SYNOPSIS
|
||||
.PP
|
||||
\fBeth-get\fP [ -p \fIrpc_provider\fP] \fItx_hash\fP
|
||||
.PP
|
||||
\fBeth-get\fP [ -p \fIrpc_provider\fP] \fIaddress\fP
|
||||
|
||||
.SH DESCRIPTION
|
||||
.P
|
||||
Retrieve a transaction by its transaction hash, or contract code by its address.
|
||||
.P
|
||||
In the context of transaction, \fBeth-get\fP retrieves the state of the transaction (the "receipt") and applies it to the output. It also re-serializes the transaction wire format for reference.
|
||||
|
||||
|
||||
.SS OPTIONS
|
||||
27
man/eth-info.head.groff
Normal file
27
man/eth-info.head.groff
Normal file
@@ -0,0 +1,27 @@
|
||||
.TH eth-info 1
|
||||
|
||||
.SH NAME
|
||||
eth-info - Return key metrics from the current state of the EVM network.
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBeth-info\fP [ -p \fIrpc_provider\fP ] [ \fIkey\fP ]
|
||||
|
||||
.SH DESCRIPTION
|
||||
\fBeth-info\fP reports statistics from the current state of the EVM network:
|
||||
|
||||
.EX
|
||||
$ eth-info
|
||||
Block: 1024478
|
||||
Gas price: 1000000000
|
||||
.EE
|
||||
|
||||
An individual data item may be specified using the \fIkey\fP positional argument:
|
||||
|
||||
.EX
|
||||
$ eth-info block
|
||||
Block: 1024478
|
||||
$ eth-info --raw gas_price
|
||||
1000000000
|
||||
.EE
|
||||
|
||||
.SS OPTIONS
|
||||
8
man/eth-raw.examples.groff
Normal file
8
man/eth-raw.examples.groff
Normal file
@@ -0,0 +1,8 @@
|
||||
.SH EXAMPLES
|
||||
|
||||
Outputs of \fBeth-gas\fP and \fBeth-encode\fP map directly to inputs for \fBeth-raw\fP.
|
||||
|
||||
.SS Encapsulate a gas transaction
|
||||
|
||||
.EX
|
||||
$ eth-gas -y <\fIkey_file_path\fP> -a 00000000000000000000000000000000DeaDBeef --fee-price 100000000000 --fee-limit 21000 --nonce 42 --raw 1024 | eth-raw
|
||||
26
man/eth-raw.head.groff
Normal file
26
man/eth-raw.head.groff
Normal file
@@ -0,0 +1,26 @@
|
||||
.TH eth-raw 1
|
||||
|
||||
.SH NAME
|
||||
eth-raw \- Create and send a jsonrpc transaction from signed rlp transaction
|
||||
|
||||
.SH SYNOPSIS
|
||||
.P
|
||||
\fBeth-raw\fP [ --deploy ] \fItransaction_data\fP
|
||||
.P
|
||||
\fBeth-raw\fP [ -p \fIrpc_provider\fP ] [ --deploy ] -s \fItransaction_data\fP
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
.P
|
||||
Creates a jsonrpc object from serialized data.
|
||||
.P
|
||||
If \fB-y\fP is defined, and \fB--mode\fP is not set, or set to "tx", a \fIeth_sendRawTransaction\fP object will be created.
|
||||
.P
|
||||
Otherwise, an \fIeth_call\fP object will be created. The recipient of the call will be the contract specified with \fB-e\fP. If \fB-y\fP has been set, the sender of the query will be the address corresponding to the key file.
|
||||
.P
|
||||
If the \fB-s\fP option is added, the jsonrpc object will be sent to the rpc provider. \fBNote\fP If the jsonrpc object is a transaction, this may incur real costs.
|
||||
.P
|
||||
See the \fBEXAMPLES\fP section for details on how to use \fBeth-raw\fP with the outputs from \fBeth-gas\fP and \fBeth-encode\fP
|
||||
|
||||
|
||||
.SS OPTIONS
|
||||
4
man/eth-raw.seealso.groff
Normal file
4
man/eth-raw.seealso.groff
Normal file
@@ -0,0 +1,4 @@
|
||||
.SH SEE ALSO
|
||||
|
||||
.BP
|
||||
confini-dump(1), eth-keyfile(1), eth-encode(1), eth-gas(1)
|
||||
17
man/eth-wait.head.groff
Normal file
17
man/eth-wait.head.groff
Normal file
@@ -0,0 +1,17 @@
|
||||
.TH eth-wait 1
|
||||
|
||||
.SH NAE
|
||||
eth-wait \- Wait for a transaction to be confirmed on network
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fBeth-wait\fP [ -p \fIrpc_provider\fP ] \fItransaction_hash\fP ...
|
||||
|
||||
.SH DESCRIPTION
|
||||
.P
|
||||
Blocks until network confirmation for the transactions are returned from \fIrpc_provider\fP.
|
||||
.P
|
||||
By default, if execution of the transaction failed on the network, the command will cause an error. This behavior can be adjusted using the \fB--ignore\fP or \fB--ignore-all\fP option.
|
||||
.P
|
||||
A transaction hash unknown to the \fIrpc_provider\fP will also cause an error.
|
||||
|
||||
.SS OPTIONS
|
||||
2
man/eth-wait.overrides
Normal file
2
man/eth-wait.overrides
Normal file
@@ -0,0 +1,2 @@
|
||||
ignore Ignore error from the specified transaction. May be defined more than once. --ignore tx_hash
|
||||
ignoreall Ignore errors from all transactions. --ignore-all
|
||||
@@ -1,7 +1,7 @@
|
||||
funga-eth~=0.5.3
|
||||
funga-eth~=0.6.1
|
||||
pysha3==1.0.2
|
||||
hexathon~=0.1.1
|
||||
hexathon~=0.1.7
|
||||
websocket-client==0.57.0
|
||||
potaahto~=0.1.0
|
||||
chainlib~=0.0.17
|
||||
confini~=0.5.3
|
||||
potaahto~=0.1.1
|
||||
chainlib~=0.2.1
|
||||
confini~=0.6.0
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[metadata]
|
||||
name = chainlib-eth
|
||||
version = 0.0.22
|
||||
version = 0.2.1
|
||||
description = Ethereum implementation of the chainlib interface
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
url = https://gitlab.com/chaintools/chainlib
|
||||
url = https://gitlab.com/chaintool/chainlib-eth
|
||||
keywords =
|
||||
dlt
|
||||
blockchain
|
||||
@@ -26,7 +26,7 @@ licence_files =
|
||||
|
||||
[options]
|
||||
include_package_data = True
|
||||
python_requires = >= 3.6
|
||||
python_requires = >= 3.7
|
||||
packages =
|
||||
chainlib.eth
|
||||
chainlib.eth.dialect
|
||||
@@ -48,4 +48,3 @@ console_scripts =
|
||||
eth-info = chainlib.eth.runnable.info:main
|
||||
eth-nonce = chainlib.eth.runnable.count:main
|
||||
eth-wait = chainlib.eth.runnable.wait:main
|
||||
eth = chainlib.eth.runnable.info:main
|
||||
|
||||
@@ -1,12 +1,63 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import os
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
# local imports
|
||||
from chainlib.eth.jsonrpc import to_blockheight_param
|
||||
from chainlib.eth.block import Block
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
class TestBlock(unittest.TestCase):
|
||||
|
||||
|
||||
def test_block(self):
|
||||
tx_one_src = {
|
||||
'hash': os.urandom(32).hex(),
|
||||
'from': os.urandom(20).hex(),
|
||||
'to': os.urandom(20).hex(),
|
||||
'value': 13,
|
||||
'data': '0xdeadbeef',
|
||||
'nonce': 666,
|
||||
'gasPrice': 100,
|
||||
'gas': 21000,
|
||||
}
|
||||
|
||||
tx_two_src_hash = os.urandom(32).hex()
|
||||
|
||||
block_hash = os.urandom(32).hex()
|
||||
block_author = os.urandom(20).hex()
|
||||
block_time = datetime.datetime.utcnow().timestamp()
|
||||
block_src = {
|
||||
'number': 42,
|
||||
'hash': block_hash,
|
||||
'author': block_author,
|
||||
'transactions': [
|
||||
tx_one_src,
|
||||
tx_two_src_hash,
|
||||
],
|
||||
'timestamp': block_time,
|
||||
}
|
||||
block = Block(block_src)
|
||||
|
||||
self.assertEqual(block.number, 42)
|
||||
self.assertEqual(block.hash, block_hash)
|
||||
self.assertEqual(block.author, block_author)
|
||||
self.assertEqual(block.timestamp, int(block_time))
|
||||
|
||||
tx_index = block.tx_index_by_hash(tx_one_src['hash'])
|
||||
self.assertEqual(tx_index, 0)
|
||||
|
||||
tx_retrieved = block.tx_by_index(tx_index)
|
||||
self.assertEqual(tx_retrieved.hash, tx_one_src['hash'])
|
||||
|
||||
tx_index = block.tx_index_by_hash(tx_two_src_hash)
|
||||
self.assertEqual(tx_index, 1)
|
||||
|
||||
|
||||
def test_blockheight_param(self):
|
||||
self.assertEqual(to_blockheight_param('latest'), 'latest')
|
||||
self.assertEqual(to_blockheight_param(0), 'latest')
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import datetime
|
||||
import os
|
||||
|
||||
# external imports
|
||||
from chainlib.stat import ChainStat
|
||||
@@ -19,6 +20,7 @@ class TestStat(unittest.TestCase):
|
||||
'hash': None,
|
||||
'transactions': [],
|
||||
'number': 41,
|
||||
'author': os.urandom(20).hex(),
|
||||
})
|
||||
|
||||
d = datetime.datetime.utcnow()
|
||||
@@ -27,6 +29,7 @@ class TestStat(unittest.TestCase):
|
||||
'hash': None,
|
||||
'transactions': [],
|
||||
'number': 42,
|
||||
'author': os.urandom(20).hex(),
|
||||
})
|
||||
|
||||
s.block_apply(block_a)
|
||||
@@ -39,6 +42,7 @@ class TestStat(unittest.TestCase):
|
||||
'hash': None,
|
||||
'transactions': [],
|
||||
'number': 43,
|
||||
'author': os.urandom(20).hex(),
|
||||
})
|
||||
|
||||
s.block_apply(block_c)
|
||||
|
||||
@@ -30,6 +30,7 @@ from chainlib.eth.address import (
|
||||
from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
same as hex_same,
|
||||
)
|
||||
from chainlib.eth.block import Block
|
||||
|
||||
@@ -39,6 +40,27 @@ logg = logging.getLogger()
|
||||
|
||||
class TxTestCase(EthTesterCase):
|
||||
|
||||
def test_tx_basic(self):
|
||||
tx_src = {
|
||||
'hash': os.urandom(32).hex(),
|
||||
'from': os.urandom(20).hex(),
|
||||
'to': os.urandom(20).hex(),
|
||||
'value': 13,
|
||||
'data': '0xdeadbeef',
|
||||
'nonce': 666,
|
||||
'gasPrice': 100,
|
||||
'gas': 21000,
|
||||
}
|
||||
|
||||
tx = Tx(tx_src)
|
||||
|
||||
self.assertEqual(tx.hash, tx_src['hash'])
|
||||
self.assertTrue(is_same_address(tx.outputs[0], tx_src['from']))
|
||||
self.assertTrue(is_same_address(tx.inputs[0], tx_src['to']))
|
||||
self.assertEqual(tx.value, tx_src['value'])
|
||||
self.assertEqual(tx.nonce, tx_src['nonce'])
|
||||
self.assertTrue(hex_same(tx.payload, tx_src['data']))
|
||||
|
||||
|
||||
def test_tx_reciprocal(self):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
@@ -50,6 +72,19 @@ class TxTestCase(EthTesterCase):
|
||||
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):
|
||||
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
|
||||
gas_oracle = RPCGasOracle(self.rpc)
|
||||
@@ -94,6 +129,7 @@ class TxTestCase(EthTesterCase):
|
||||
'number': 42,
|
||||
'timestamp': 13241324,
|
||||
'transactions': [],
|
||||
'author': os.urandom(20).hex(),
|
||||
})
|
||||
with self.assertRaises(AttributeError):
|
||||
tx = Tx(tx_data, block=block)
|
||||
@@ -136,7 +172,9 @@ class TxTestCase(EthTesterCase):
|
||||
'number': 42,
|
||||
'timestamp': 13241324,
|
||||
'transactions': [],
|
||||
'author': os.urandom(20).hex(),
|
||||
})
|
||||
|
||||
block.txs = [add_0x(tx_data['hash'])]
|
||||
with self.assertRaises(ValueError):
|
||||
tx = Tx(tx_data, rcpt=rcpt, block=block)
|
||||
|
||||
Reference in New Issue
Block a user