Add missing jsonrpc module, add address code retrieve to get cli util
This commit is contained in:
parent
a0dd37e944
commit
9356ef53b2
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
__pycache__
|
||||
gmon.out
|
||||
*.pyc
|
||||
dist/
|
||||
build/
|
||||
*.egg-info
|
11
Makefile
Normal file
11
Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
PACKAGE=chainlib
|
||||
|
||||
build:
|
||||
python setup.py bdist_wheel
|
||||
|
||||
.PHONY clean:
|
||||
rm -rf build
|
||||
rm -rf dist
|
||||
rm -rf $(PACKAGE).egg-info
|
||||
|
||||
.PHONY dist: clean build
|
16
chainlib/eth/jsonrpc.py
Normal file
16
chainlib/eth/jsonrpc.py
Normal file
@ -0,0 +1,16 @@
|
||||
# proposed custom errors
|
||||
# source: https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal
|
||||
|
||||
#1 Unauthorized Should be used when some action is not authorized, e.g. sending from a locked account.
|
||||
#2 Action not allowed Should be used when some action is not allowed, e.g. preventing an action, while another depending action is processing on, like sending again when a confirmation popup is shown to the user (?).
|
||||
#3 Execution error Will contain a subset of custom errors in the data field. See below.
|
||||
|
||||
#100 X doesn’t exist Should be used when something which should be there is not found. (Doesn’t apply to eth_getTransactionBy_ and eth_getBlock_. They return a success with value null)
|
||||
#101 Requires ether Should be used for actions which require somethin else, e.g. gas or a value.
|
||||
#102 Gas too low Should be used when a to low value of gas was given.
|
||||
#103 Gas limit exceeded Should be used when a limit is exceeded, e.g. for the gas limit in a block.
|
||||
#104 Rejected Should be used when an action was rejected, e.g. because of its content (too long contract code, containing wrong characters ?, should differ from -32602 - Invalid params).
|
||||
#105 Ether too low Should be used when a to low value of Ether was given.
|
||||
|
||||
#106 Timeout Should be used when an action timedout.
|
||||
#107 Conflict Should be used when an action conflicts with another (ongoing?) action.
|
@ -17,11 +17,10 @@ import argparse
|
||||
import logging
|
||||
import enum
|
||||
|
||||
# third-party imports
|
||||
# external imports
|
||||
from hexathon import (
|
||||
add_0x,
|
||||
strip_0x,
|
||||
even,
|
||||
)
|
||||
import sha3
|
||||
|
||||
@ -33,8 +32,10 @@ from chainlib.jsonrpc import (
|
||||
)
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
from chainlib.eth.tx import Tx
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.block import Block
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.status import Status
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@ -50,7 +51,7 @@ argparser.add_argument('-u', '--unsafe', dest='u', action='store_true', help='Au
|
||||
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('-v', action='store_true', help='Be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
||||
argparser.add_argument('tx_hash', type=str, help='Transaction hash')
|
||||
argparser.add_argument('item', type=str, help='Item to get information for (address og transaction)')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.vv:
|
||||
@ -60,16 +61,11 @@ elif args.v:
|
||||
|
||||
conn = EthHTTPConnection(args.p)
|
||||
|
||||
tx_hash = add_0x(args.tx_hash)
|
||||
#tx_hash = add_0x(args.tx_hash)
|
||||
item = add_0x(args.item)
|
||||
|
||||
|
||||
class Status(enum.Enum):
|
||||
UNCONFIRMED = -1
|
||||
REVERTED = 0
|
||||
SUCCESS = 1
|
||||
|
||||
|
||||
def main():
|
||||
def get_transaction(conn, tx_hash):
|
||||
o = jsonrpc_template()
|
||||
o['method'] = 'eth_getTransactionByHash'
|
||||
o['params'].append(tx_hash)
|
||||
@ -92,7 +88,30 @@ def main():
|
||||
tx = Tx(tx_src)
|
||||
if rcpt != None:
|
||||
tx.apply_receipt(rcpt)
|
||||
print(tx)
|
||||
return tx
|
||||
|
||||
|
||||
def get_address(conn, address):
|
||||
o = jsonrpc_template()
|
||||
o['method'] = 'eth_getCode'
|
||||
o['params'].append(address)
|
||||
o['params'].append('latest')
|
||||
code = conn.do(o)
|
||||
|
||||
content = strip_0x(code, allow_empty=True)
|
||||
if len(content) == 0:
|
||||
return None
|
||||
|
||||
return content
|
||||
|
||||
|
||||
def main():
|
||||
r = None
|
||||
if len(item) > 42:
|
||||
r = get_transaction(conn, item)
|
||||
elif args.u or to_checksum_address(item):
|
||||
r = get_address(conn, item)
|
||||
print(r)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user