2021-06-28 07:48:36 +02:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import enum
|
|
|
|
import select
|
|
|
|
|
|
|
|
# external imports
|
2021-08-21 09:27:40 +02:00
|
|
|
from potaahto.symbols import snake_and_camel
|
2021-06-28 07:48:36 +02:00
|
|
|
from hexathon import (
|
|
|
|
add_0x,
|
|
|
|
strip_0x,
|
|
|
|
)
|
|
|
|
import sha3
|
|
|
|
from chainlib.jsonrpc import (
|
|
|
|
JSONRPCRequest,
|
|
|
|
jsonrpc_result,
|
|
|
|
IntSequenceGenerator,
|
|
|
|
)
|
2021-08-21 09:27:40 +02:00
|
|
|
from chainlib.chain import ChainSpec
|
|
|
|
from chainlib.status import Status
|
2022-05-12 17:46:29 +02:00
|
|
|
from chainlib.settings import ChainSettings
|
2021-08-21 09:27:40 +02:00
|
|
|
|
|
|
|
# local imports
|
2021-06-28 07:48:36 +02:00
|
|
|
from chainlib.eth.connection import EthHTTPConnection
|
|
|
|
from chainlib.eth.tx import (
|
|
|
|
Tx,
|
|
|
|
pack,
|
2022-05-12 20:05:13 +02:00
|
|
|
transaction,
|
|
|
|
receipt,
|
2021-06-28 07:48:36 +02:00
|
|
|
)
|
2021-08-21 09:27:40 +02:00
|
|
|
from chainlib.eth.address import (
|
|
|
|
to_checksum_address,
|
|
|
|
is_checksum_address,
|
|
|
|
)
|
|
|
|
from chainlib.eth.block import (
|
|
|
|
Block,
|
|
|
|
block_by_hash,
|
|
|
|
)
|
2021-06-28 07:48:36 +02:00
|
|
|
from chainlib.eth.runnable.util import decode_for_puny_humans
|
2021-08-21 09:27:40 +02:00
|
|
|
from chainlib.eth.jsonrpc import to_blockheight_param
|
|
|
|
import chainlib.eth.cli
|
2022-05-12 10:20:06 +02:00
|
|
|
from chainlib.eth.cli.arg import (
|
|
|
|
Arg,
|
|
|
|
ArgFlag,
|
|
|
|
process_args,
|
|
|
|
)
|
|
|
|
from chainlib.eth.cli.config import (
|
|
|
|
Config,
|
|
|
|
process_config,
|
|
|
|
)
|
2022-05-12 20:05:13 +02:00
|
|
|
from chainlib.eth.contract import code
|
2022-05-12 10:20:06 +02:00
|
|
|
from chainlib.eth.cli.log import process_log
|
2022-05-12 17:46:29 +02:00
|
|
|
from chainlib.eth.settings import process_settings
|
|
|
|
|
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__))
|
|
|
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2022-05-12 17:46:29 +02:00
|
|
|
|
|
|
|
def process_config_local(config, arg, args, flags):
|
|
|
|
config.add(args.item, '_ITEM', False)
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
2022-05-12 20:05:13 +02:00
|
|
|
def process_settings_local(settings, config):
|
|
|
|
item = config.get('_ITEM')
|
|
|
|
item = strip_0x(item)
|
|
|
|
|
|
|
|
if len(item) == 40:
|
|
|
|
config.add(item, '_RECIPIENT', False)
|
|
|
|
elif len(item) == 64:
|
|
|
|
config.add(item, '_HASH', False)
|
|
|
|
|
|
|
|
return process_settings(settings, config)
|
|
|
|
|
|
|
|
|
2022-05-12 10:20:06 +02:00
|
|
|
arg_flags = ArgFlag()
|
|
|
|
arg = Arg(arg_flags)
|
2022-05-12 17:46:29 +02:00
|
|
|
flags = arg_flags.STD_BASE_READ | arg_flags.TARGET
|
2022-05-12 10:20:06 +02:00
|
|
|
flags = arg_flags.less(flags, arg_flags.CHAIN_SPEC)
|
2022-05-12 13:10:47 +02:00
|
|
|
|
|
|
|
argparser = chainlib.eth.cli.ArgumentParser()
|
2022-05-12 10:20:06 +02:00
|
|
|
argparser = process_args(argparser, arg, flags)
|
|
|
|
argparser.add_argument('item', type=str, help='Address or transaction to retrieve data for')
|
2021-08-21 09:27:40 +02:00
|
|
|
args = argparser.parse_args()
|
2022-05-12 10:20:06 +02:00
|
|
|
|
|
|
|
logg = process_log(args, logg)
|
|
|
|
|
|
|
|
config = Config()
|
|
|
|
config = process_config(config, arg, args, flags)
|
2022-05-12 17:46:29 +02:00
|
|
|
config = process_config_local(config, arg, args, flags)
|
2022-05-12 10:20:06 +02:00
|
|
|
logg.debug('config loaded:\n{}'.format(config))
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2022-05-12 17:46:29 +02:00
|
|
|
settings = ChainSettings()
|
2022-05-12 20:05:13 +02:00
|
|
|
settings = process_settings_local(settings, config)
|
2022-05-12 17:46:29 +02:00
|
|
|
logg.debug('settings loaded:\n{}'.format(settings))
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
|
2022-05-12 17:46:29 +02:00
|
|
|
def get_transaction(conn, chain_spec, tx_hash, id_generator):
|
2022-05-12 20:05:13 +02:00
|
|
|
o = transaction(tx_hash, id_generator=id_generator)
|
2021-06-28 07:48:36 +02:00
|
|
|
tx_src = conn.do(o)
|
|
|
|
if tx_src == None:
|
|
|
|
logg.error('Transaction {} not found'.format(tx_hash))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
if config.true('_RAW'):
|
2021-06-28 07:48:36 +02:00
|
|
|
tx_src = Tx.src_normalize(tx_src)
|
|
|
|
return pack(tx_src, chain_spec).hex()
|
|
|
|
|
|
|
|
tx = None
|
|
|
|
status = -1
|
|
|
|
rcpt = None
|
|
|
|
|
2022-05-12 20:05:13 +02:00
|
|
|
o = receipt(tx_hash, id_generator=id_generator)
|
2021-06-28 07:48:36 +02:00
|
|
|
rcpt = conn.do(o)
|
|
|
|
|
|
|
|
if tx == None:
|
|
|
|
tx = Tx(tx_src)
|
|
|
|
if rcpt != None:
|
|
|
|
tx.apply_receipt(rcpt)
|
2021-08-21 09:27:40 +02:00
|
|
|
rcpt = snake_and_camel(rcpt)
|
|
|
|
o = block_by_hash(rcpt['block_hash'])
|
|
|
|
r = conn.do(o)
|
|
|
|
block = Block(r)
|
|
|
|
tx.apply_block(block)
|
2021-06-28 07:48:36 +02:00
|
|
|
tx.generate_wire(chain_spec)
|
|
|
|
return tx
|
2021-08-21 09:27:40 +02:00
|
|
|
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
def get_address(conn, address, id_generator, height):
|
2022-05-12 20:05:13 +02:00
|
|
|
o = code(address, height, id_generator=id_generator)
|
|
|
|
r = conn.do(o)
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2022-05-12 20:05:13 +02:00
|
|
|
content = strip_0x(r, allow_empty=True)
|
2021-06-28 07:48:36 +02:00
|
|
|
if len(content) == 0:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
r = None
|
2022-05-12 20:05:13 +02:00
|
|
|
if settings.get('HASH') != None:
|
2022-05-12 20:20:52 +02:00
|
|
|
hsh = settings.get('HASH')[0]
|
2022-05-12 17:46:29 +02:00
|
|
|
r = get_transaction(
|
|
|
|
settings.get('CONN'),
|
|
|
|
settings.get('CHAIN_SPEC'),
|
2022-05-12 20:20:52 +02:00
|
|
|
hsh,
|
2022-05-12 17:46:29 +02:00
|
|
|
settings.get('RPC_ID_GENERATOR'),
|
|
|
|
)
|
2021-08-21 09:27:40 +02:00
|
|
|
if not config.true('_RAW'):
|
|
|
|
r = r.to_human()
|
|
|
|
else:
|
2022-05-12 17:46:29 +02:00
|
|
|
r = get_address(
|
|
|
|
settings.get('CONN'),
|
2022-05-12 20:05:13 +02:00
|
|
|
settings.get('RECIPIENT'),
|
2022-05-12 17:46:29 +02:00
|
|
|
settings.get('RPC_ID_GENERATOR'),
|
2022-05-12 20:05:13 +02:00
|
|
|
settings.get('HEIGHT'),
|
2022-05-12 17:46:29 +02:00
|
|
|
)
|
2021-09-01 09:38:09 +02:00
|
|
|
if r != None:
|
|
|
|
print(r)
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|