Fix giftable token cli commands

This commit is contained in:
lash 2023-01-24 15:54:00 +00:00
parent 5e7e539bb9
commit 7183e01b72
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 57 additions and 36 deletions

View File

@ -73,6 +73,7 @@ logg.debug('settings loaded:\n{}'.format(settings))
def main(): def main():
signer_address = settings.get('SENDER_ADDRESS') signer_address = settings.get('SENDER_ADDRESS')
conn = settings.get('CONN')
c = GiftableToken( c = GiftableToken(
settings.get('CHAIN_SPEC'), settings.get('CHAIN_SPEC'),

View File

@ -25,62 +25,80 @@ from hexathon import (
strip_0x, strip_0x,
add_0x, add_0x,
) )
from chainlib.settings import ChainSettings
from chainlib.eth.cli.log import process_log
from chainlib.eth.settings import process_settings
from chainlib.eth.cli.arg import (
Arg,
ArgFlag,
process_args,
)
from chainlib.eth.cli.config import (
Config,
process_config,
)
# local imports # local imports
from giftable_erc20_token import GiftableToken from giftable_erc20_token import GiftableToken
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger() logg = logging.getLogger()
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC | chainlib.eth.cli.Flag.WALLET
argparser = chainlib.eth.cli.ArgumentParser(arg_flags) def process_config_local(config, arg, args, flags):
argparser.add_positional('amount', type=int, help='Token amount to gift') config.add(config.get('_POSARG'), '_VALUE', False)
return config
arg_flags = ArgFlag()
arg = Arg(arg_flags)
flags = arg_flags.STD_WRITE | arg_flags.WALLET | arg_flags.EXEC
argparser = chainlib.eth.cli.ArgumentParser()
argparser = process_args(argparser, arg, flags)
argparser.add_argument('value', type=str, help='Token value to send')
args = argparser.parse_args() args = argparser.parse_args()
extra_args = {
'amount': None,
}
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=GiftableToken.gas())
wallet = chainlib.eth.cli.Wallet() logg = process_log(args, logg)
wallet.from_config(config)
rpc = chainlib.eth.cli.Rpc(wallet=wallet) config = Config()
conn = rpc.connect_by_config(config) 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))
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) settings = ChainSettings()
settings = process_settings(settings, config)
logg.debug('settings loaded:\n{}'.format(settings))
def main(): def main():
signer = rpc.get_signer() token_address = settings.get('EXEC')
signer_address = rpc.get_sender_address() signer_address = settings.get('SENDER_ADDRESS')
recipient = settings.get('RECIPIENT')
value = settings.get('VALUE')
conn = settings.get('CONN')
gas_oracle = rpc.get_gas_oracle() c = GiftableToken(
nonce_oracle = rpc.get_nonce_oracle() settings.get('CHAIN_SPEC'),
signer=settings.get('SIGNER'),
gas_oracle=settings.get('GAS_ORACLE'),
nonce_oracle=settings.get('NONCE_ORACLE'),
)
recipient_address_input = config.get('_RECIPIENT') (tx_hash_hex, o) = c.mint_to(
if recipient_address_input == None: token_address,
recipient_address_input = signer_address signer_address,
recipient,
recipient_address = add_0x(to_checksum_address(recipient_address_input)) value,
if not config.true('_UNSAFE') and recipient_address != add_0x(recipient_address_input): )
raise ValueError('invalid checksum address for recipient') if settings.get('RPC_SEND'):
token_address = add_0x(to_checksum_address(config.get('_EXEC_ADDRESS')))
if not config.true('_UNSAFE') and token_address != add_0x(config.get('_EXEC_ADDRESS')):
raise ValueError('invalid checksum address for contract')
token_value = config.get('_AMOUNT')
c = GiftableToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
(tx_hash_hex, o) = c.mint_to(token_address, signer_address, recipient_address, token_value)
if config.get('_RPC_SEND'):
conn.do(o) conn.do(o)
if config.get('_WAIT'): if settings.get('WAIT'):
r = conn.wait(tx_hash_hex) r = conn.wait(tx_hash_hex)
if r['status'] == 0: if r['status'] == 0:
sys.stderr.write('EVM revert. Wish I had more to tell you') sys.stderr.write('EVM revert. Wish I had more to tell you')
sys.exit(1) sys.exit(1)
logg.info('mint to {} tx {}'.format(recipient_address, tx_hash_hex)) logg.info('mint to {} tx {}'.format(recipient, tx_hash_hex))
print(tx_hash_hex) print(tx_hash_hex)
else: else:

View File

@ -72,7 +72,9 @@ logg.debug('settings loaded:\n{}'.format(settings))
def main(): def main():
token_address = settings.get('EXEC')
signer_address = settings.get('SENDER_ADDRESS') signer_address = settings.get('SENDER_ADDRESS')
conn = settings.get('CONN')
recipient_address_input = settings.get('RECIPIENT') recipient_address_input = settings.get('RECIPIENT')
if recipient_address_input == None: if recipient_address_input == None:

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = eth-erc20 name = eth-erc20
version = 0.5.2 version = 0.5.3
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