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
- 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
- Implement chainlib 0.3.0
* 0.3.1

View File

@ -51,7 +51,13 @@ from eth_erc20 import ERC20
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
@ -69,7 +75,7 @@ args = argparser.parse_args()
logg = process_log(args, logg)
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))

View File

@ -30,6 +30,7 @@ from chainlib.eth.cli.arg import (
Arg,
ArgFlag,
process_args,
stdin_arg,
)
from chainlib.eth.cli.config import (
Config,
@ -52,24 +53,38 @@ from eth_erc20 import ERC20
logg = logging.getLogger()
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
arg_flags = ArgFlag()
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 = 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()
logg = process_log(args, logg)
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)
logg.debug('config loaded:\n{}'.format(config))
@ -79,62 +94,54 @@ logg.debug('settings loaded:\n{}'.format(settings))
def main():
token_address = settings.get('EXEC')
item = config.get('_ITEM')
token_address = config.get('_CONTRACT')
conn = settings.get('CONN')
g = ERC20(
chain_spec=settings.get('CHAIN_SPEC'),
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)
r = conn.do(name_o)
token_name = g.parse_name(r)
s = ''
if not item or not args.raw:
if not config.true('_RAW'):
s = 'Name: '
s += token_name
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)
r = conn.do(symbol_o)
token_symbol = g.parse_symbol(r)
s = ''
if not item or not args.raw:
if not config.true('_RAW'):
s = 'Symbol: '
s += token_symbol
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)
r = conn.do(decimals_o)
decimals = int(strip_0x(r), 16)
s = ''
if not item or not args.raw:
if not config.true('_RAW'):
s = 'Decimals: '
s += str(decimals)
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)
r = conn.do(supply_o)
supply = int(strip_0x(r), 16)
s = ''
if not item or not args.raw:
if not config.true('_RAW'):
s = 'Supply: '
s += str(supply)
print(s)
if item == 'supply':
sys.exit(0)
if __name__ == '__main__':

View File

@ -21,7 +21,6 @@ from hexathon import (
add_0x,
strip_0x,
)
from chainlib.eth.runnable.util import decode_for_puny_humans
import chainlib.eth.cli
from chainlib.eth.cli.log import process_log
from chainlib.eth.settings import process_settings
@ -43,7 +42,7 @@ logg = logging.getLogger()
def process_config_local(config, arg, args, flags):
config.add(args.amount, '_VALUE', False)
config.add(config.get('_POSARG'), '_VALUE', False)
return config
@ -53,13 +52,13 @@ flags = arg_flags.STD_WRITE | arg_flags.EXEC | arg_flags.WALLET
argparser = chainlib.eth.cli.ArgumentParser()
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()
logg = process_log(args, logg)
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)
logg.debug('config loaded:\n{}'.format(config))

View File

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

View File

@ -1,6 +1,6 @@
[metadata]
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.
author = Louis Holbrook
author_email = dev@holbrook.no