commit 3f7344614dee985bd469505ac2be15802f342924
parent e704445ff7ca84838b240c940c1d90ac09d521c1
Author: lash <dev@holbrook.no>
Date: Fri, 4 Nov 2022 07:27:58 +0000
Add output selection for eth-get cmd
Diffstat:
10 files changed, 84 insertions(+), 65 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,4 +1,4 @@
-- 0.3.4
+- 0.4.0
* option for net amount in eth-gas (deduct fee from desired spend)
* implement height for eth-balance
* data input from file in gas command
diff --git a/chainlib/eth/runnable/balance.py b/chainlib/eth/runnable/balance.py
@@ -48,8 +48,9 @@ script_dir = os.path.dirname(os.path.realpath(__file__))
def process_config_local(config, arg, args, flags):
recipient = None
- if args.address:
- recipient = add_0x(args.address)
+ address = config.get('_POSARG')
+ if address:
+ recipient = add_0x(address)
else:
recipient = stdin_arg()
config.add(recipient, '_RECIPIENT', False)
@@ -70,7 +71,7 @@ logg = process_log(args, logg)
logg.debug('flags {} {} {}'.format(flags, arg_flags.SEQ, flags & arg_flags.SEQ))
config = Config()
-config = process_config(config, arg, args, flags)
+config = process_config(config, arg, args, flags, positional_name='address')
config = process_config_local(config, arg, args, flags)
logg.debug('config loaded:\n{}'.format(config))
diff --git a/chainlib/eth/runnable/checksum.py b/chainlib/eth/runnable/checksum.py
@@ -7,15 +7,17 @@ from hexathon import strip_0x
# local imports
from chainlib.eth.address import to_checksum_address
+from chainlib.eth.cli.arg import stdin_arg
v = None
if len(sys.argv) > 1:
v = sys.argv[1]
else:
- h = select.select([sys.stdin], [], [], 0)
- if len(h[0]) > 0:
- v = h[0][0].read()
- v = v.rstrip()
+ #h = select.select([sys.stdin], [], [], 0)
+ #if len(h[0]) > 0:
+ # v = h[0][0].read()
+ # v = v.rstrip()
+ v = stdin_arg()
if v == None:
sys.stderr.write('input missing\n')
diff --git a/chainlib/eth/runnable/encode.py b/chainlib/eth/runnable/encode.py
@@ -112,6 +112,7 @@ def main():
# signer_address = rpc.get_signer_address()
#except SignerMissingException:
# pass
+ conn = settings.get('CONN')
signer_address = settings.get('SENDER_ADDRESS')
code = '0x'
@@ -190,7 +191,7 @@ def main():
o['params'].append(height)
o = j.finalize(o)
- if config.get('_RPC_SEND'):
+ if settings.get('RPC_SEND'):
r = conn.do(o)
try:
print(strip_0x(r))
diff --git a/chainlib/eth/runnable/gas.py b/chainlib/eth/runnable/gas.py
@@ -71,8 +71,9 @@ def from_data_arg(data):
def process_config_local(config, arg, args, flags):
data = ''
- for data_arg in args.data:
- data += from_data_arg(data_arg)
+ if args.data != None:
+ for data_arg in args.data:
+ data += from_data_arg(data_arg)
if data == '':
data = None
config.add(data, '_DATA', False)
diff --git a/chainlib/eth/runnable/get.py b/chainlib/eth/runnable/get.py
@@ -41,7 +41,6 @@ from chainlib.eth.block import (
Block,
block_by_hash,
)
-from chainlib.eth.runnable.util import decode_for_puny_humans
from chainlib.eth.jsonrpc import to_blockheight_param
import chainlib.eth.cli
from chainlib.eth.cli.arg import (
@@ -89,7 +88,7 @@ def process_settings_local(settings, config):
arg_flags = ArgFlag()
arg = Arg(arg_flags)
-flags = arg_flags.STD_BASE_READ | arg_flags.TARGET
+flags = arg_flags.STD_BASE_READ | arg_flags.TARGET | arg_flags.TAB
flags = arg_flags.less(flags, arg_flags.CHAIN_SPEC)
argparser = chainlib.eth.cli.ArgumentParser()
@@ -116,7 +115,7 @@ def get_transaction(conn, chain_spec, tx_hash, id_generator):
logg.error('Transaction {} not found'.format(tx_hash))
sys.exit(1)
- if config.true('_RAW'):
+ if config.true('_RAW') and config.get('_OUTARG') == None:
tx_src = Tx.src_normalize(tx_src)
return pack(tx_src, chain_spec).hex()
@@ -162,8 +161,8 @@ def main():
hsh,
settings.get('RPC_ID_GENERATOR'),
)
- if not config.true('_RAW'):
- r = r.to_human()
+ if not config.true('_RAW') or config.get('_OUTARG') != None:
+ r = r.to_human(fields=config.get('_OUTARG'), skip_keys=config.true('_RAW'))
else:
r = get_address(
settings.get('CONN'),
@@ -172,7 +171,9 @@ def main():
settings.get('HEIGHT'),
)
if r != None:
- print(r)
+ sys.stdout.write(r)
+ if not config.true('_NOLINE'):
+ sys.stdout.write('\n')
if __name__ == '__main__':
diff --git a/chainlib/eth/runnable/raw.py b/chainlib/eth/runnable/raw.py
@@ -160,7 +160,8 @@ def main():
if settings.get('RPC_SEND'):
r = settings.get('CONN').do(o)
if config.true('_WAIT'):
- r = settings.get('CONN').wait(tx_hash_hex)
+ #r = settings.get('CONN').wait(tx_hash_hex)
+ r = settings.get('CONN').wait(r)
if r['status'] == 0:
logg.critical('VM revert for {}. Wish I could tell you more'.format(tx_hash_hex))
sys.exit(1)
diff --git a/chainlib/eth/src.py b/chainlib/eth/src.py
@@ -23,7 +23,6 @@ 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'])
diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py
@@ -724,68 +724,81 @@ class Tx(BaseTx, Src):
return self.__str__()
- def to_human(self):
+ def to_human(self, fields=None, skip_keys=False):
"""Human-readable string dump of transaction contents.
:rtype: str
:returns: Contents
"""
- s = """hash {}
-from {}
-to {}
-value {}
-nonce {}
-gas_price {}
-gas_limit {}
-input {}
-""".format(
- self.hash,
- self.outputs[0],
- self.inputs[0],
- self.value,
- self.nonce,
- self.gas_price,
- self.gas_limit,
- self.payload,
- )
+
+ outkeys = [
+ 'hash',
+ 'from',
+ 'to',
+ 'value',
+ 'nonce',
+ 'gas_price',
+ 'gas_limit',
+ 'input',
+ 'status',
+ ]
+
+ outvals = [
+ self.hash,
+ self.outputs[0],
+ self.inputs[0],
+ self.value,
+ self.nonce,
+ self.gas_price,
+ self.gas_limit,
+ self.payload,
+ ]
status = Status.UNKNOWN.name
logg.debug('selfstatus {}'.format(self.status))
- if self.result != None and self.result.status != Status.PENDING:
- s += """gas_used {}
-""".format(
- self.result.fee_cost,
- )
+
try:
status = self.result.status.name
except AttributeError:
logg.debug('tx {} does not have a result yet', self.hash)
- s += 'status ' + status + '\n'
+ #s += 'status ' + status + '\n'
+ outvals.append(status)
+ if self.result != None and self.result.status != Status.PENDING:
+ outkeys.append('gas_used')
+ outvals.append(self.result.fee_cost)
if self.block != None:
- s += """block_number {}
-block_hash {}
-tx_index {}
-""".format(
- self.block.number,
- self.block.hash,
- self.result.tx_index,
- )
+ outkeys += [
+ 'block_hash',
+ 'tx_index',
+ 'src',
+ ]
+ outvals += [
+ self.block.number,
+ self.block.hash,
+ self.result.tx_index,
+ ]
- if self.contract != None:
- s += """contract {}
-""".format(
- self.contract,
- )
-
if self.wire != None:
- s += """src {}
-""".format(
- str(self.wire),
- )
+ outkeys.append('src')
+ outvals.append(self.wire)
+
+ if self.result != None and self.result.contract != None:
+ outkeys.append('contract')
+ outvals.append(self.result.contract)
+
+ s = ''
+ for i, k in enumerate(outkeys):
+ if fields != None:
+ if k not in fields:
+ continue
+ if len(s) > 0:
+ s += '\n'
+ if skip_keys:
+ s += outvals[i]
+ else:
+ s += '{} {}'.format(k, outvals[i])
return s
-
-
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chainlib-eth
-version = 0.3.4
+version = 0.4.0
description = Ethereum implementation of the chainlib interface
author = Louis Holbrook
author_email = dev@holbrook.no