2020-12-07 11:41:06 +01:00
|
|
|
"""Mints and gifts tokens to a given address
|
2021-01-09 01:24:03 +01:00
|
|
|
|
2020-12-07 11:41:06 +01:00
|
|
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
|
|
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
# standard imports
|
2021-01-09 01:24:03 +01:00
|
|
|
import sys
|
2020-12-07 11:41:06 +01:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
import logging
|
2021-01-09 01:24:03 +01:00
|
|
|
import time
|
2020-12-07 11:41:06 +01:00
|
|
|
|
2021-07-29 20:25:10 +02:00
|
|
|
# external imports
|
|
|
|
import chainlib.eth.cli
|
2021-04-04 14:47:32 +02:00
|
|
|
from chainlib.eth.tx import receipt
|
|
|
|
from chainlib.chain import ChainSpec
|
|
|
|
from chainlib.eth.connection import EthHTTPConnection
|
2021-07-29 20:25:10 +02:00
|
|
|
from chainlib.eth.address import to_checksum_address
|
|
|
|
from hexathon import (
|
|
|
|
strip_0x,
|
|
|
|
add_0x,
|
|
|
|
)
|
2021-04-04 14:47:32 +02:00
|
|
|
|
|
|
|
# local imports
|
|
|
|
from giftable_erc20_token import GiftableToken
|
2020-12-07 11:41:06 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
2021-07-29 20:25:10 +02:00
|
|
|
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)
|
|
|
|
argparser.add_positional('amount', type=int, help='Token amount to gift')
|
2020-12-07 11:41:06 +01:00
|
|
|
args = argparser.parse_args()
|
2021-07-29 20:25:10 +02:00
|
|
|
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()
|
|
|
|
wallet.from_config(config)
|
2020-12-07 11:41:06 +01:00
|
|
|
|
2021-07-29 20:25:10 +02:00
|
|
|
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
|
|
|
conn = rpc.connect_by_config(config)
|
|
|
|
|
|
|
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
2021-01-09 23:12:08 +01:00
|
|
|
|
|
|
|
|
2021-04-04 14:47:32 +02:00
|
|
|
def main():
|
2021-07-29 20:25:10 +02:00
|
|
|
signer = rpc.get_signer()
|
|
|
|
signer_address = rpc.get_sender_address()
|
|
|
|
|
|
|
|
gas_oracle = rpc.get_gas_oracle()
|
|
|
|
nonce_oracle = rpc.get_nonce_oracle()
|
|
|
|
|
|
|
|
recipient_address_input = config.get('_RECIPIENT')
|
|
|
|
if recipient_address_input == None:
|
|
|
|
recipient_address_input = signer_address
|
|
|
|
|
|
|
|
recipient_address = add_0x(to_checksum_address(recipient_address_input))
|
|
|
|
if not config.true('_UNSAFE') and recipient_address != add_0x(recipient_address_input):
|
|
|
|
raise ValueError('invalid checksum address for recipient')
|
|
|
|
|
|
|
|
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')
|
2021-04-04 14:47:32 +02:00
|
|
|
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)
|
2021-07-29 20:25:10 +02:00
|
|
|
if config.get('_RPC_SEND'):
|
|
|
|
conn.do(o)
|
|
|
|
if config.get('_WAIT'):
|
|
|
|
r = conn.wait(tx_hash_hex)
|
2021-04-13 08:16:32 +02:00
|
|
|
if r['status'] == 0:
|
|
|
|
sys.stderr.write('EVM revert. Wish I had more to tell you')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
logg.info('mint to {} tx {}'.format(recipient_address, tx_hash_hex))
|
|
|
|
|
|
|
|
print(tx_hash_hex)
|
2021-07-29 20:25:10 +02:00
|
|
|
else:
|
|
|
|
print(o)
|
2020-12-07 11:41:06 +01:00
|
|
|
|
|
|
|
|
2021-01-09 01:24:03 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|