2021-06-28 07:48:36 +02:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
# standard imports
|
|
|
|
import io
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import urllib
|
|
|
|
|
|
|
|
# external imports
|
2022-05-12 18:12:00 +02:00
|
|
|
from chainlib.settings import ChainSettings
|
2021-10-18 14:23:54 +02:00
|
|
|
from funga.eth.signer import EIP155Signer
|
|
|
|
from funga.eth.keystore.dict import DictKeystore
|
2021-06-28 07:48:36 +02:00
|
|
|
from hexathon import (
|
|
|
|
add_0x,
|
|
|
|
strip_0x,
|
|
|
|
)
|
2022-05-12 18:12:00 +02:00
|
|
|
from chainlib.error import SignerMissingException
|
|
|
|
from chainlib.chain import ChainSpec
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
# local imports
|
|
|
|
from chainlib.eth.address import to_checksum
|
|
|
|
from chainlib.eth.connection import EthHTTPConnection
|
|
|
|
from chainlib.jsonrpc import (
|
|
|
|
JSONRPCRequest,
|
|
|
|
IntSequenceGenerator,
|
|
|
|
)
|
|
|
|
from chainlib.eth.nonce import (
|
|
|
|
RPCNonceOracle,
|
|
|
|
OverrideNonceOracle,
|
|
|
|
)
|
|
|
|
from chainlib.eth.gas import (
|
|
|
|
RPCGasOracle,
|
|
|
|
OverrideGasOracle,
|
|
|
|
)
|
|
|
|
from chainlib.eth.tx import (
|
|
|
|
TxFactory,
|
|
|
|
raw,
|
|
|
|
)
|
|
|
|
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
|
2022-05-12 14:58:24 +02:00
|
|
|
import chainlib.eth.cli
|
|
|
|
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
|
2022-05-12 18:12:00 +02:00
|
|
|
from chainlib.eth.settings import process_settings
|
2022-05-12 14:58:24 +02:00
|
|
|
|
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 18:12:00 +02:00
|
|
|
|
|
|
|
def process_config_local(config, arg, args, flags):
|
|
|
|
config.add(args.deploy, '_DEPLOY', False)
|
|
|
|
config.add(args.mode, '_MODE', False)
|
|
|
|
config.add(args.data, '_DATA', False)
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
2022-05-12 14:58:24 +02:00
|
|
|
arg_flags = ArgFlag()
|
|
|
|
arg = Arg(arg_flags)
|
|
|
|
flags = arg_flags.STD_WRITE | arg_flags.EXEC
|
|
|
|
|
|
|
|
argparser = chainlib.eth.cli.ArgumentParser()
|
|
|
|
argparser = process_args(argparser, arg, flags)
|
2021-10-06 06:57:51 +02:00
|
|
|
argparser.add_argument('--deploy', action='store_true', help='Deploy data as contract')
|
2022-02-25 12:07:18 +01:00
|
|
|
argparser.add_argument('--mode', choices=['tx', 'call'], type=str, help='Mode of operation')
|
2022-05-12 14:58:24 +02:00
|
|
|
argparser.add_argument('data', type=str, help='Transaction data')
|
2021-08-21 09:27:40 +02:00
|
|
|
args = argparser.parse_args()
|
2021-06-28 07:48:36 +02:00
|
|
|
|
2022-05-12 14:58:24 +02:00
|
|
|
logg = process_log(args, logg)
|
|
|
|
|
|
|
|
config = Config()
|
|
|
|
config = process_config(config, arg, args, flags)
|
2022-05-12 18:12:00 +02:00
|
|
|
config = process_config_local(config, arg, args, flags)
|
2022-05-12 14:58:24 +02:00
|
|
|
logg.debug('config loaded:\n{}'.format(config))
|
|
|
|
|
2022-05-12 18:12:00 +02:00
|
|
|
settings = ChainSettings()
|
|
|
|
settings = process_settings(settings, config)
|
|
|
|
logg.debug('settings loaded:\n{}'.format(settings))
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
|
2021-08-21 09:27:40 +02:00
|
|
|
def main():
|
2022-05-12 18:12:00 +02:00
|
|
|
if config.get('_EXEC_ADDRESS') != None or config.true('_DEPLOY'):
|
|
|
|
if not args.u and exec_address != exec_address:
|
|
|
|
raise ValueError('invalid checksum address')
|
|
|
|
|
|
|
|
if settings.get('SENDER_ADDRESS'):
|
|
|
|
j = JSONRPCRequest(id_generator=settings.get('RPC_ID_GENERATOR'))
|
2021-10-06 06:57:51 +02:00
|
|
|
o = j.template()
|
|
|
|
o['method'] = 'eth_call'
|
|
|
|
o['params'].append({
|
2022-05-12 18:12:00 +02:00
|
|
|
'to': settings.get('EXEC'),
|
|
|
|
'from': settings.get('SENDER_ADDRESS'),
|
2021-10-06 06:57:51 +02:00
|
|
|
'value': '0x00',
|
|
|
|
'gas': add_0x(int.to_bytes(8000000, 8, byteorder='big').hex()), # TODO: better get of network gas limit
|
|
|
|
'gasPrice': '0x01',
|
2022-05-12 18:12:00 +02:00
|
|
|
'data': add_0x(config.get('_DATA')),
|
2021-10-06 06:57:51 +02:00
|
|
|
})
|
|
|
|
height = to_blockheight_param(config.get('_HEIGHT'))
|
|
|
|
o['params'].append(height)
|
|
|
|
o = j.finalize(o)
|
2022-05-12 18:12:00 +02:00
|
|
|
r = settings.get('CONN').do(o)
|
2021-10-06 06:57:51 +02:00
|
|
|
try:
|
|
|
|
print(strip_0x(r))
|
|
|
|
except ValueError:
|
|
|
|
sys.stderr.write('query returned an empty value ({})\n'.format(r))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
else:
|
2022-05-12 18:12:00 +02:00
|
|
|
if settings.get('CHAIN_SPEC') == None:
|
2021-09-01 09:38:09 +02:00
|
|
|
raise ValueError('chain spec must be specified')
|
2022-05-12 18:12:00 +02:00
|
|
|
g = TxFactory(
|
|
|
|
settings.get('CHAIN_SPEC'),
|
|
|
|
signer=settings.get('SIGNER'),
|
|
|
|
gas_oracle=settings.get('GAS_ORACLE'),
|
|
|
|
nonce_oracle=settings.get('NONCE_ORACLE'),
|
|
|
|
)
|
|
|
|
tx = g.template(
|
|
|
|
settings.get('SENDER_ADDRESS'),
|
|
|
|
settings.get('EXEC'),
|
|
|
|
use_nonce=True,
|
|
|
|
)
|
|
|
|
if config.get('_DATA') != None:
|
|
|
|
tx = g.set_code(tx, add_0x(config.get('_DATA')))
|
2021-09-01 09:38:09 +02:00
|
|
|
|
|
|
|
(tx_hash_hex, o) = g.finalize(tx, id_generator=rpc.id_generator)
|
|
|
|
|
|
|
|
if send:
|
2022-05-12 18:12:00 +02:00
|
|
|
r = settings.get('CONN').do(o)
|
2021-09-01 09:38:09 +02:00
|
|
|
print(r)
|
|
|
|
else:
|
2021-10-06 07:30:07 +02:00
|
|
|
if config.get('_RAW'):
|
|
|
|
o = strip_0x(o)
|
2021-09-01 09:38:09 +02:00
|
|
|
print(o)
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
else:
|
2022-05-12 18:12:00 +02:00
|
|
|
o = raw(config.get('_DATA'), id_generator=settings.get('RPC_ID_GENERATOR'))
|
|
|
|
if settings.get('RPC_SEND'):
|
|
|
|
r = settings.get('CONN').do(o)
|
2022-05-12 14:58:24 +02:00
|
|
|
if config.true('_WAIT'):
|
2022-05-12 18:12:00 +02:00
|
|
|
r = settings.get('CONN').wait(tx_hash_hex)
|
2022-01-09 13:09:23 +01:00
|
|
|
if r['status'] == 0:
|
|
|
|
logg.critical('VM revert for {}. Wish I could tell you more'.format(tx_hash_hex))
|
|
|
|
sys.exit(1)
|
2021-06-28 07:48:36 +02:00
|
|
|
print(r)
|
|
|
|
else:
|
|
|
|
print(o)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|