2021-06-28 07:48:36 +02:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
# external imports
|
2021-06-28 07:48:36 +02:00
|
|
|
from hexathon import (
|
|
|
|
add_0x,
|
|
|
|
strip_0x,
|
|
|
|
even,
|
|
|
|
)
|
|
|
|
|
|
|
|
# local imports
|
2021-08-21 09:27:40 +02:00
|
|
|
import chainlib.eth.cli
|
2022-05-12 08:27:11 +02:00
|
|
|
from chainlib.eth.cli.arg import (
|
|
|
|
Arg,
|
|
|
|
ArgFlag,
|
|
|
|
process_args,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.config import (
|
|
|
|
Config,
|
|
|
|
process_config,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.log import process_log
|
2021-08-21 09:27:40 +02:00
|
|
|
from chainlib.eth.address import AddressChecksum
|
2021-06-28 07:48:36 +02:00
|
|
|
from chainlib.jsonrpc import (
|
|
|
|
jsonrpc_result,
|
|
|
|
IntSequenceGenerator,
|
|
|
|
)
|
|
|
|
from chainlib.eth.connection import EthHTTPConnection
|
|
|
|
from chainlib.eth.gas import (
|
|
|
|
OverrideGasOracle,
|
|
|
|
balance,
|
|
|
|
)
|
|
|
|
from chainlib.chain import ChainSpec
|
2021-10-18 14:23:54 +02:00
|
|
|
from funga.eth.signer import EIP155Signer
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2022-05-12 08:27:11 +02:00
|
|
|
arg_flags = ArgFlag()
|
|
|
|
arg = Arg(arg_flags)
|
|
|
|
flags = arg_flags.STD_READ
|
2022-05-12 11:29:10 +02:00
|
|
|
|
|
|
|
argparser = chainlib.eth.cli.ArgumentParser()
|
2022-05-12 08:27:11 +02:00
|
|
|
argparser = process_args(argparser, arg, flags)
|
|
|
|
|
|
|
|
argparser.add_argument('address', type=str, help='Ethereum address of recipient')
|
2021-06-28 07:48:36 +02:00
|
|
|
args = argparser.parse_args()
|
2022-05-12 08:27:11 +02:00
|
|
|
|
|
|
|
logg = process_log(args, logg)
|
|
|
|
logg.debug('flags {} {} {}'.format(flags, arg_flags.SEQ, flags & arg_flags.SEQ))
|
|
|
|
|
|
|
|
config = Config()
|
|
|
|
config = process_config(config, arg, args, flags)
|
|
|
|
logg.debug('config loaded:\n{}'.format(config))
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
wallet = chainlib.eth.cli.Wallet()
|
|
|
|
wallet.from_config(config)
|
|
|
|
holder_address = args.address
|
|
|
|
if wallet.get_signer_address() == None and holder_address != None:
|
|
|
|
holder_address = wallet.from_address(holder_address)
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
rpc = chainlib.eth.cli.Rpc()
|
|
|
|
conn = rpc.connect_by_config(config)
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
r = None
|
|
|
|
decimals = 18
|
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
o = balance(holder_address, id_generator=rpc.id_generator)
|
2021-06-28 07:48:36 +02:00
|
|
|
r = conn.do(o)
|
|
|
|
|
|
|
|
hx = strip_0x(r)
|
|
|
|
balance_value = int(hx, 16)
|
|
|
|
logg.debug('balance {} = {} decimals {}'.format(even(hx), balance_value, decimals))
|
|
|
|
|
|
|
|
balance_str = str(balance_value)
|
|
|
|
balance_len = len(balance_str)
|
|
|
|
if balance_len < decimals + 1:
|
|
|
|
print('0.{}'.format(balance_str.zfill(decimals)))
|
|
|
|
else:
|
|
|
|
offset = balance_len-decimals
|
|
|
|
print('{}.{}'.format(balance_str[:offset],balance_str[offset:]))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|