WIP add erc20 transfer executable
This commit is contained in:
@@ -26,14 +26,14 @@ from eth_abi import encode_single
|
||||
|
||||
# local imports
|
||||
from cic_tools.eth.address import to_checksum
|
||||
from cic_tools.eth.method import (
|
||||
from cic_tools.eth.rpc import (
|
||||
jsonrpc_template,
|
||||
erc20_balance,
|
||||
erc20_decimals,
|
||||
jsonrpc_result,
|
||||
)
|
||||
from cic_tools.eth.erc20 import ERC20TxFactory
|
||||
from cic_tools.eth.connection import HTTPConnection
|
||||
|
||||
from cic_tools.eth.nonce import DefaultNonceOracle
|
||||
from cic_tools.eth.gas import DefaultGasOracle
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -55,22 +55,25 @@ if args.v:
|
||||
logg.setLevel(logging.DEBUG)
|
||||
|
||||
conn = HTTPConnection(args.p)
|
||||
gas_oracle = DefaultGasOracle(conn)
|
||||
|
||||
|
||||
def main():
|
||||
account = to_checksum(args.account)
|
||||
if not args.u and account != add_0x(args.account):
|
||||
raise ValueError('invalid checksum address')
|
||||
|
||||
|
||||
r = None
|
||||
decimals = 18
|
||||
if args.t != None:
|
||||
g = ERC20TxFactory()
|
||||
# determine decimals
|
||||
decimals_o = erc20_decimals(args.t)
|
||||
decimals_o = g.erc20_decimals(args.t)
|
||||
r = conn.do(decimals_o)
|
||||
decimals = int(strip_0x(r), 16)
|
||||
|
||||
# get balance
|
||||
balance_o = erc20_balance(args.t, account)
|
||||
balance_o = g.erc20_balance(args.t, account)
|
||||
r = conn.do(balance_o)
|
||||
|
||||
else:
|
||||
|
||||
@@ -19,7 +19,6 @@ import logging
|
||||
# third-party imports
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore import DictKeystore
|
||||
from crypto_dev_signer.eth.helper import EthTxExecutor
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
@@ -28,9 +27,7 @@ from hexathon import (
|
||||
# local imports
|
||||
from cic_tools.eth.address import to_checksum
|
||||
from cic_tools.eth.connection import HTTPConnection
|
||||
from cic_tools.eth.method import (
|
||||
jsonrpc_template,
|
||||
)
|
||||
from cic_tools.eth.rpc import jsonrpc_template
|
||||
from cic_tools.eth.nonce import DefaultNonceOracle
|
||||
from cic_tools.eth.gas import (
|
||||
DefaultGasOracle,
|
||||
@@ -52,8 +49,8 @@ argparser.add_argument('-ww', action='store_true', help='Wait for every transact
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
||||
argparser.add_argument('-a', '--signer-address', dest='a', type=str, help='Signing address')
|
||||
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
|
||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-u', '--unsafe', dest='u', action='store_true', help='Auto-convert address to checksum adddress')
|
||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||
argparser.add_argument('recipient', type=str, help='Ethereum address of recipient')
|
||||
argparser.add_argument('amount', type=int, help='Amount of tokens to mint and gift')
|
||||
@@ -101,10 +98,14 @@ def main():
|
||||
logg.debug('sender {} balance before: {}'.format(signer_address, balance(signer_address)))
|
||||
logg.debug('recipient {} balance before: {}'.format(recipient, balance(recipient)))
|
||||
|
||||
g = GasTxFactory(signer, gas_oracle, nonce_oracle, chain_id=chain_id)
|
||||
g = GasTxFactory(signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
(tx_hash_hex, o) = g.create(signer_address, recipient, value)
|
||||
conn.do(o)
|
||||
|
||||
logg.debug('sender {} balance after: {}'.format(signer_address, balance(signer_address)))
|
||||
logg.debug('recipient {} balance after: {}'.format(recipient, balance(recipient)))
|
||||
|
||||
|
||||
print(tx_hash_hex)
|
||||
|
||||
|
||||
|
||||
113
cic_tools/eth/runnable/transfer.py
Normal file
113
cic_tools/eth/runnable/transfer.py
Normal file
@@ -0,0 +1,113 @@
|
||||
#!python3
|
||||
|
||||
"""Token transfer script
|
||||
|
||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
|
||||
"""
|
||||
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# standard imports
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
# third-party imports
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore import DictKeystore
|
||||
from crypto_dev_signer.eth.helper import EthTxExecutor
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from cic_tools.eth.address import to_checksum
|
||||
from cic_tools.eth.connection import HTTPConnection
|
||||
from cic_tools.eth.rpc import jsonrpc_template
|
||||
from cic_tools.eth.nonce import DefaultNonceOracle
|
||||
from cic_tools.eth.gas import DefaultGasOracle
|
||||
from cic_tools.eth.erc20 import ERC20TxFactory
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
||||
|
||||
default_abi_dir = '/usr/local/share/cic/solidity/abi'
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
||||
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
|
||||
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
|
||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
||||
argparser.add_argument('--token-address', required='True', dest='t', type=str, help='Token address')
|
||||
argparser.add_argument('-a', '--sender-address', dest='s', type=str, help='Sender account address')
|
||||
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
|
||||
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=default_abi_dir, help='Directory containing bytecode and abi (default {})'.format(default_abi_dir))
|
||||
argparser.add_argument('-u', '--unsafe', dest='u', action='store_true', help='Auto-convert address to checksum adddress')
|
||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||
argparser.add_argument('recipient', type=str, help='Recipient account address')
|
||||
argparser.add_argument('amount', type=int, help='Amount of tokens to mint and gift')
|
||||
args = argparser.parse_args()
|
||||
|
||||
|
||||
if args.vv:
|
||||
logg.setLevel(logging.DEBUG)
|
||||
elif args.v:
|
||||
logg.setLevel(logging.INFO)
|
||||
|
||||
block_last = args.w
|
||||
block_all = args.ww
|
||||
|
||||
signer_address = None
|
||||
keystore = DictKeystore()
|
||||
if args.y != None:
|
||||
logg.debug('loading keystore file {}'.format(args.y))
|
||||
signer_address = keystore.import_keystore_file(args.y)
|
||||
logg.debug('now have key for signer address {}'.format(signer_address))
|
||||
signer = EIP155Signer(keystore)
|
||||
|
||||
conn = HTTPConnection(args.p)
|
||||
nonce_oracle = DefaultNonceOracle(signer_address, conn)
|
||||
gas_oracle = DefaultGasOracle(conn)
|
||||
|
||||
chain_pair = args.i.split(':')
|
||||
chain_id = int(chain_pair[1])
|
||||
#g = ERC20TxFactory(signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle, chain_id=chain_id)
|
||||
g = ERC20TxFactory()
|
||||
|
||||
def balance(token_address, address):
|
||||
o = g.erc20_balance(token_address, address)
|
||||
r = conn.do(o)
|
||||
hx = strip_0x(r)
|
||||
return int(hx, 16)
|
||||
|
||||
|
||||
def main():
|
||||
recipient = args.recipient
|
||||
if not args.u and recipient != add_0x(args.recipient):
|
||||
raise ValueError('invalid checksum address')
|
||||
|
||||
value = args.amount
|
||||
|
||||
logg.debug('sender {} balance before: {}'.format(signer_address, balance(args.t, signer_address)))
|
||||
logg.debug('recipient {} balance before: {}'.format(recipient, balance(args.t, recipient)))
|
||||
|
||||
logg.debug('sender {} balance after: {}'.format(signer_address, balance(args.t, signer_address)))
|
||||
logg.debug('recipient {} balance after: {}'.format(recipient, balance(args.t, recipient)))
|
||||
|
||||
|
||||
if block_last:
|
||||
helper.wait_for()
|
||||
|
||||
print(tx_hash)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user