Implement for chainlib 0.4.x

This commit is contained in:
lash 2022-11-06 10:29:58 +00:00
parent 067cc1bb30
commit dbce42888c
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 44 additions and 31 deletions

View File

@ -1,5 +1,6 @@
* 0.4.1 * 0.4.1
- Implement chainlib 0.3.x for giftable token - Implement chainlib 0.4.x for giftable token
- Fix broken inputs in erc20 cli tools
* 0.4.0 * 0.4.0
- Implement chainlib 0.3.0 - Implement chainlib 0.3.0
* 0.3.1 * 0.3.1

View File

@ -51,7 +51,13 @@ from eth_erc20 import ERC20
def process_config_local(config, arg, args, flags): def process_config_local(config, arg, args, flags):
config.add(args.address, '_RECIPIENT', False) recipient = None
address = config.get('_POSARG')
if address:
recipient = add_0x(address)
else:
recipient = stdin_arg()
config.add(recipient, '_RECIPIENT', False)
return config return config
@ -69,7 +75,7 @@ args = argparser.parse_args()
logg = process_log(args, logg) logg = process_log(args, logg)
config = Config() 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) config = process_config_local(config, arg, args, flags)
logg.debug('config loaded:\n{}'.format(config)) logg.debug('config loaded:\n{}'.format(config))

View File

@ -30,6 +30,7 @@ from chainlib.eth.cli.arg import (
Arg, Arg,
ArgFlag, ArgFlag,
process_args, process_args,
stdin_arg,
) )
from chainlib.eth.cli.config import ( from chainlib.eth.cli.config import (
Config, Config,
@ -52,24 +53,38 @@ from eth_erc20 import ERC20
logg = logging.getLogger() logg = logging.getLogger()
def process_config_local(config, arg, args, flags): def process_config_local(config, arg, args, flags):
config.add(args.item, '_ITEM', False) contract = None
try:
contract = config.get('_EXEC_ADDRESS')
except KeyError:
pass
if contract == None:
address = config.get('_POSARG')
if address:
contract = add_0x(address)
else:
contract = stdin_arg()
config.add(contract, '_CONTRACT', False)
return config return config
arg_flags = ArgFlag() arg_flags = ArgFlag()
arg = Arg(arg_flags) arg = Arg(arg_flags)
flags = arg_flags.STD_READ | arg_flags.EXEC flags = arg_flags.STD_READ | arg_flags.EXEC | arg_flags.TAB
argparser = chainlib.eth.cli.ArgumentParser() argparser = chainlib.eth.cli.ArgumentParser()
argparser = process_args(argparser, arg, flags) argparser = process_args(argparser, arg, flags)
argparser.add_argument('item', type=str, nargs='?', help='display only given data item') argparser.add_argument('contract_address', type=str, help='Token contract address (may also be specified by -e)')
args = argparser.parse_args() args = argparser.parse_args()
logg = process_log(args, logg) logg = process_log(args, logg)
config = Config() config = Config()
config = process_config(config, arg, args, flags) config = process_config(config, arg, args, flags, positional_name='contract_address')
config = process_config_local(config, arg, args, flags) config = process_config_local(config, arg, args, flags)
logg.debug('config loaded:\n{}'.format(config)) logg.debug('config loaded:\n{}'.format(config))
@ -79,62 +94,54 @@ logg.debug('settings loaded:\n{}'.format(settings))
def main(): def main():
token_address = settings.get('EXEC') token_address = config.get('_CONTRACT')
item = config.get('_ITEM')
conn = settings.get('CONN') conn = settings.get('CONN')
g = ERC20( g = ERC20(
chain_spec=settings.get('CHAIN_SPEC'), chain_spec=settings.get('CHAIN_SPEC'),
gas_oracle=settings.get('GAS_ORACLE'), gas_oracle=settings.get('GAS_ORACLE'),
) )
outkeys = config.get('_OUTARG')
if not item or item == 'name': if not outkeys or 'address' in outkeys:
name_o = g.name(token_address) name_o = g.name(token_address)
r = conn.do(name_o) r = conn.do(name_o)
token_name = g.parse_name(r) token_name = g.parse_name(r)
s = '' s = ''
if not item or not args.raw: if not config.true('_RAW'):
s = 'Name: ' s = 'Name: '
s += token_name s += token_name
print(s) print(s)
if item == 'name':
sys.exit(0)
if not item or item == 'symbol': if not outkeys or 'symbol' in outkeys:
symbol_o = g.symbol(token_address) symbol_o = g.symbol(token_address)
r = conn.do(symbol_o) r = conn.do(symbol_o)
token_symbol = g.parse_symbol(r) token_symbol = g.parse_symbol(r)
s = '' s = ''
if not item or not args.raw: if not config.true('_RAW'):
s = 'Symbol: ' s = 'Symbol: '
s += token_symbol s += token_symbol
print(s) print(s)
if item == 'symbol':
sys.exit(0)
if not item or item == 'decimals': if not outkeys or 'decimals' in outkeys:
decimals_o = g.decimals(token_address) decimals_o = g.decimals(token_address)
r = conn.do(decimals_o) r = conn.do(decimals_o)
decimals = int(strip_0x(r), 16) decimals = int(strip_0x(r), 16)
s = '' s = ''
if not item or not args.raw: if not config.true('_RAW'):
s = 'Decimals: ' s = 'Decimals: '
s += str(decimals) s += str(decimals)
print(s) print(s)
if item == 'decimals':
sys.exit(0)
if not item or item == 'supply': if not outkeys or 'supply' in outkeys:
supply_o = g.total_supply(token_address) supply_o = g.total_supply(token_address)
r = conn.do(supply_o) r = conn.do(supply_o)
supply = int(strip_0x(r), 16) supply = int(strip_0x(r), 16)
s = '' s = ''
if not item or not args.raw: if not config.true('_RAW'):
s = 'Supply: ' s = 'Supply: '
s += str(supply) s += str(supply)
print(s) print(s)
if item == 'supply':
sys.exit(0)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -21,7 +21,6 @@ from hexathon import (
add_0x, add_0x,
strip_0x, strip_0x,
) )
from chainlib.eth.runnable.util import decode_for_puny_humans
import chainlib.eth.cli import chainlib.eth.cli
from chainlib.eth.cli.log import process_log from chainlib.eth.cli.log import process_log
from chainlib.eth.settings import process_settings from chainlib.eth.settings import process_settings
@ -43,7 +42,7 @@ logg = logging.getLogger()
def process_config_local(config, arg, args, flags): def process_config_local(config, arg, args, flags):
config.add(args.amount, '_VALUE', False) config.add(config.get('_POSARG'), '_VALUE', False)
return config return config
@ -53,13 +52,13 @@ flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET
argparser = chainlib.eth.cli.ArgumentParser() argparser = chainlib.eth.cli.ArgumentParser()
argparser = process_args(argparser, arg, flags) argparser = process_args(argparser, arg, flags)
argparser.add_argument('amount', type=str, help='Token amount to send') argparser.add_argument('value', type=str, help='Token value to send')
args = argparser.parse_args() args = argparser.parse_args()
logg = process_log(args, logg) logg = process_log(args, logg)
config = Config() config = Config()
config = process_config(config, arg, args, flags) config = process_config(config, arg, args, flags, positional_name='value')
config = process_config_local(config, arg, args, flags) config = process_config_local(config, arg, args, flags)
logg.debug('config loaded:\n{}'.format(config)) logg.debug('config loaded:\n{}'.format(config))

View File

@ -1,3 +1,3 @@
confini~=0.6.1 confini~=0.6.1
chainlib-eth~=0.3.0 chainlib-eth~=0.4.2
potaahto~=0.1.1 potaahto~=0.1.1

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = eth-erc20 name = eth-erc20
version = 0.4.0 version = 0.5.0
description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens. description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens.
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no