Merge branch 'lash/funga'
This commit is contained in:
commit
7832071512
@ -1,3 +1,5 @@
|
|||||||
- 0.0.5-pending
|
- 0.0.15:
|
||||||
|
* Correct inverted addess checksum check for gas cli
|
||||||
|
- 0.0.5-unreleased:
|
||||||
* Receive all ethereum components from chainlib package
|
* Receive all ethereum components from chainlib package
|
||||||
* Make settings configurable
|
* Make settings configurable
|
||||||
|
@ -4,7 +4,7 @@ from hexathon import (
|
|||||||
strip_0x,
|
strip_0x,
|
||||||
uniform,
|
uniform,
|
||||||
)
|
)
|
||||||
from crypto_dev_signer.encoding import (
|
from funga.eth.encoding import (
|
||||||
is_address,
|
is_address,
|
||||||
is_checksum_address,
|
is_checksum_address,
|
||||||
to_checksum_address,
|
to_checksum_address,
|
||||||
|
@ -60,6 +60,20 @@ def transaction_count(block_hash, id_generator=None):
|
|||||||
return j.finalize(o)
|
return j.finalize(o)
|
||||||
|
|
||||||
|
|
||||||
|
def syncing(id_generator=None):
|
||||||
|
"""Request the syncing state of the node
|
||||||
|
|
||||||
|
:param id_generator: JSONRPC id generator
|
||||||
|
:type id_generator: JSONRPCIdGenerator
|
||||||
|
:rtype: dict
|
||||||
|
:returns: rpc query object
|
||||||
|
"""
|
||||||
|
j = JSONRPCRequest(id_generator)
|
||||||
|
o = j.template()
|
||||||
|
o['method'] = 'eth_syncing'
|
||||||
|
return j.finalize(o)
|
||||||
|
|
||||||
|
|
||||||
class Block(BaseBlock):
|
class Block(BaseBlock):
|
||||||
"""Encapsulates an Ethereum block
|
"""Encapsulates an Ethereum block
|
||||||
|
|
||||||
|
@ -16,10 +16,12 @@ class CLIEncoder(ABIContractEncoder):
|
|||||||
__re_uint = r'^([uU])[int]*([0-9]+)?$'
|
__re_uint = r'^([uU])[int]*([0-9]+)?$'
|
||||||
__re_bytes = r'^([bB])[ytes]*([0-9]+)?$'
|
__re_bytes = r'^([bB])[ytes]*([0-9]+)?$'
|
||||||
__re_string = r'^([sS])[tring]*$'
|
__re_string = r'^([sS])[tring]*$'
|
||||||
|
__re_address = r'^([aA])[ddress]*?$'
|
||||||
__translations = [
|
__translations = [
|
||||||
'to_uint',
|
'to_uint',
|
||||||
'to_bytes',
|
'to_bytes',
|
||||||
'to_string',
|
'to_string',
|
||||||
|
'to_address',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, signature=None):
|
def __init__(self, signature=None):
|
||||||
@ -58,6 +60,18 @@ class CLIEncoder(ABIContractEncoder):
|
|||||||
return (s, a)
|
return (s, a)
|
||||||
|
|
||||||
|
|
||||||
|
def to_address(self, typ):
|
||||||
|
s = None
|
||||||
|
a = None
|
||||||
|
m = re.match(self.__re_address, typ)
|
||||||
|
if m == None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
s = 'ADDRESS'
|
||||||
|
a = getattr(ABIContractType, s)
|
||||||
|
return (s, a)
|
||||||
|
|
||||||
|
|
||||||
def to_string(self, typ):
|
def to_string(self, typ):
|
||||||
m = re.match(self.__re_string, typ)
|
m = re.match(self.__re_string, typ)
|
||||||
if m == None:
|
if m == None:
|
||||||
|
@ -13,6 +13,7 @@ from chainlib.eth.nonce import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: how is the keystore implemented in rpc here?
|
||||||
class Rpc(BaseRpc):
|
class Rpc(BaseRpc):
|
||||||
"""Convenience constructor to set Ethereum defaults for chainlib cli Rpc object
|
"""Convenience constructor to set Ethereum defaults for chainlib cli Rpc object
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# external imports
|
# external imports
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
from chainlib.cli import Wallet as BaseWallet
|
from chainlib.cli import Wallet as BaseWallet
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
@ -13,7 +14,7 @@ class Wallet(BaseWallet):
|
|||||||
:type checksummer: Implementation of chainlib.eth.address.AddressChecksum
|
:type checksummer: Implementation of chainlib.eth.address.AddressChecksum
|
||||||
"""
|
"""
|
||||||
def __init__(self, checksummer=AddressChecksum):
|
def __init__(self, checksummer=AddressChecksum):
|
||||||
super(Wallet, self).__init__(EIP155Signer, checksummer=checksummer)
|
super(Wallet, self).__init__(EIP155Signer, checksummer=checksummer, keystore=DictKeystore())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ from chainlib.jsonrpc import (
|
|||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
unpack,
|
unpack,
|
||||||
)
|
)
|
||||||
|
from potaahto.symbols import snake_and_camel
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -88,11 +89,16 @@ class EthHTTPConnection(JSONRPCHTTPConnection):
|
|||||||
|
|
||||||
e = jsonrpc_result(r, error_parser)
|
e = jsonrpc_result(r, error_parser)
|
||||||
if e != None:
|
if e != None:
|
||||||
logg.debug('({}) poll receipt completed {}'.format(str(self), r))
|
e = snake_and_camel(e)
|
||||||
logg.debug('e {}'.format(strip_0x(e['status'])))
|
# In openethereum we encounter receipts that have NONE block hashes and numbers. WTF...
|
||||||
if strip_0x(e['status']) == '00':
|
logg.debug('({}) poll receipt received {}'.format(str(self), r))
|
||||||
raise RevertEthException(tx_hash_hex)
|
if e['block_hash'] == None:
|
||||||
return e
|
logg.warning('poll receipt attempt {} returned receipt but with a null block hash value!'.format(i))
|
||||||
|
else:
|
||||||
|
logg.debug('e {}'.format(strip_0x(e['status'])))
|
||||||
|
if strip_0x(e['status']) == '00':
|
||||||
|
raise RevertEthException(tx_hash_hex)
|
||||||
|
return e
|
||||||
|
|
||||||
if timeout > 0.0:
|
if timeout > 0.0:
|
||||||
delta = (datetime.datetime.utcnow() - t) + datetime.timedelta(seconds=delay)
|
delta = (datetime.datetime.utcnow() - t) + datetime.timedelta(seconds=delay)
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
[rpc]
|
[rpc]
|
||||||
http_provider = http://localhost:8545
|
|
||||||
provider = http://localhost:8545
|
provider = http://localhost:8545
|
||||||
auth =
|
auth =
|
||||||
credentials =
|
credentials =
|
||||||
dialect = default
|
dialect = default
|
||||||
scheme = http
|
scheme = http
|
||||||
|
verify = 1
|
||||||
|
|
||||||
[chain]
|
[chain]
|
||||||
spec = evm:ethereum:1
|
spec = evm:berlin:1:ethereum
|
||||||
|
|
||||||
[wallet]
|
[wallet]
|
||||||
key_file =
|
key_file =
|
||||||
|
@ -6,7 +6,7 @@ from hexathon import (
|
|||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
)
|
)
|
||||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
from funga.eth.transaction import EIP155Transaction
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainlib.fee import FeeOracle
|
from chainlib.fee import FeeOracle
|
||||||
@ -55,7 +55,7 @@ def balance(address, id_generator=None, height=BlockSpec.LATEST):
|
|||||||
j = JSONRPCRequest(id_generator)
|
j = JSONRPCRequest(id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_getBalance'
|
o['method'] = 'eth_getBalance'
|
||||||
o['params'].append(address)
|
o['params'].append(add_0x(address))
|
||||||
height = to_blockheight_param(height)
|
height = to_blockheight_param(height)
|
||||||
o['params'].append(height)
|
o['params'].append(height)
|
||||||
return j.finalize(o)
|
return j.finalize(o)
|
||||||
|
@ -44,7 +44,7 @@ class NonceOracle(BaseNonceOracle):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, address, id_generator=None):
|
def __init__(self, address, id_generator=None):
|
||||||
self.id_generator = id_generator
|
self.id_generator = id_generator
|
||||||
super(NonceOracle, self).__init__(address)
|
super(NonceOracle, self).__init__(add_0x(address))
|
||||||
|
|
||||||
|
|
||||||
def get_nonce(self):
|
def get_nonce(self):
|
||||||
|
@ -5,8 +5,8 @@ import logging
|
|||||||
# external imports
|
# external imports
|
||||||
import eth_tester
|
import eth_tester
|
||||||
import pytest
|
import pytest
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainlib.eth.unittest.base import *
|
from chainlib.eth.unittest.base import *
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import pytest
|
import pytest
|
||||||
#from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
|
@ -24,7 +24,7 @@ from chainlib.eth.gas import (
|
|||||||
balance,
|
balance,
|
||||||
)
|
)
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
@ -15,8 +15,8 @@ from chainlib.eth.connection import EthHTTPConnection
|
|||||||
from chainlib.eth.tx import count
|
from chainlib.eth.tx import count
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.jsonrpc import IntSequenceGenerator
|
from chainlib.jsonrpc import IntSequenceGenerator
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
from hexathon import add_0x
|
from hexathon import add_0x
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
@ -43,7 +43,7 @@ conn = rpc.connect_by_config(config)
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
# TODO: should tolerate if address not prefixed with 0x
|
# TODO: should tolerate if address not prefixed with 0x
|
||||||
o = count(holder_address, id_generator=rpc.id_generator)
|
o = count(add_0x(holder_address), id_generator=rpc.id_generator)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
count_result = None
|
count_result = None
|
||||||
try:
|
try:
|
||||||
|
@ -13,8 +13,8 @@ import sha3
|
|||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
from chainlib.eth.cli.encode import CLIEncoder
|
from chainlib.eth.cli.encode import CLIEncoder
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
@ -45,10 +45,7 @@ from chainlib.error import SignerMissingException
|
|||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.eth.runnable.util import decode_for_puny_humans
|
from chainlib.eth.runnable.util import decode_for_puny_humans
|
||||||
from chainlib.eth.jsonrpc import to_blockheight_param
|
from chainlib.eth.jsonrpc import to_blockheight_param
|
||||||
<<<<<<< HEAD
|
|
||||||
from chainlib.eth.address import to_checksum_address
|
from chainlib.eth.address import to_checksum_address
|
||||||
=======
|
|
||||||
>>>>>>> d6b258f2140f5ce555f765a90c14a65a5f3fc6de
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
@ -58,12 +55,14 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
|
arg_flags = chainlib.eth.cli.argflag_std_write | chainlib.eth.cli.Flag.EXEC
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
|
argparser.add_argument('--notx', action='store_true', help='Network send is not a transaction')
|
||||||
argparser.add_argument('--signature', type=str, help='Method signature to encode')
|
argparser.add_argument('--signature', type=str, help='Method signature to encode')
|
||||||
argparser.add_argument('contract_args', type=str, nargs='*', help='arguments to encode')
|
argparser.add_argument('contract_args', type=str, nargs='*', help='arguments to encode')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
extra_args = {
|
extra_args = {
|
||||||
'signature': None,
|
'signature': None,
|
||||||
'contract_args': None,
|
'contract_args': None,
|
||||||
|
'notx': None,
|
||||||
}
|
}
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_config_dir=config_dir)
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_config_dir=config_dir)
|
||||||
|
|
||||||
@ -112,7 +111,7 @@ def main():
|
|||||||
|
|
||||||
exec_address = add_0x(to_checksum_address(config.get('_EXEC_ADDRESS')))
|
exec_address = add_0x(to_checksum_address(config.get('_EXEC_ADDRESS')))
|
||||||
|
|
||||||
if signer == None:
|
if signer == None or config.true('_NOTX'):
|
||||||
c = TxFactory(chain_spec)
|
c = TxFactory(chain_spec)
|
||||||
j = JSONRPCRequest(id_generator=rpc.id_generator)
|
j = JSONRPCRequest(id_generator=rpc.id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
@ -147,7 +146,7 @@ def main():
|
|||||||
tx_format = TxFormat.RLP_SIGNED
|
tx_format = TxFormat.RLP_SIGNED
|
||||||
(tx_hash_hex, o) = c.finalize(tx, tx_format=tx_format)
|
(tx_hash_hex, o) = c.finalize(tx, tx_format=tx_format)
|
||||||
if send:
|
if send:
|
||||||
r = conn.do(r)
|
r = conn.do(o)
|
||||||
print(r)
|
print(r)
|
||||||
else:
|
else:
|
||||||
if config.get('_RAW'):
|
if config.get('_RAW'):
|
||||||
|
@ -26,7 +26,10 @@ from chainlib.eth.gas import Gas
|
|||||||
from chainlib.eth.gas import balance as gas_balance
|
from chainlib.eth.gas import balance as gas_balance
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.eth.runnable.util import decode_for_puny_humans
|
from chainlib.eth.runnable.util import decode_for_puny_humans
|
||||||
from chainlib.eth.address import is_same_address
|
from chainlib.eth.address import (
|
||||||
|
is_same_address,
|
||||||
|
is_checksum_address,
|
||||||
|
)
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
@ -63,8 +66,12 @@ send = config.true('_RPC_SEND')
|
|||||||
def balance(address, id_generator):
|
def balance(address, id_generator):
|
||||||
o = gas_balance(address, id_generator=id_generator)
|
o = gas_balance(address, id_generator=id_generator)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
hx = strip_0x(r)
|
try:
|
||||||
return int(hx, 16)
|
balance = int(r)
|
||||||
|
except ValueError:
|
||||||
|
balance = strip_0x(r)
|
||||||
|
balance = int(balance, 16)
|
||||||
|
return balance
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -74,7 +81,7 @@ def main():
|
|||||||
g = Gas(chain_spec, signer=signer, gas_oracle=rpc.get_gas_oracle(), nonce_oracle=rpc.get_nonce_oracle())
|
g = Gas(chain_spec, signer=signer, gas_oracle=rpc.get_gas_oracle(), nonce_oracle=rpc.get_nonce_oracle())
|
||||||
|
|
||||||
recipient = to_checksum_address(config.get('_RECIPIENT'))
|
recipient = to_checksum_address(config.get('_RECIPIENT'))
|
||||||
if not config.true('_UNSAFE') and is_checksum_address(recipient):
|
if not config.true('_UNSAFE') and not is_checksum_address(recipient):
|
||||||
raise ValueError('invalid checksum address')
|
raise ValueError('invalid checksum address')
|
||||||
|
|
||||||
logg.info('gas transfer from {} to {} value {}'.format(signer_address, recipient, value))
|
logg.info('gas transfer from {} to {} value {}'.format(signer_address, recipient, value))
|
||||||
|
@ -63,6 +63,7 @@ item = add_0x(args.item)
|
|||||||
|
|
||||||
|
|
||||||
def get_transaction(conn, tx_hash, id_generator):
|
def get_transaction(conn, tx_hash, id_generator):
|
||||||
|
tx_hash = add_0x(tx_hash)
|
||||||
j = JSONRPCRequest(id_generator=id_generator)
|
j = JSONRPCRequest(id_generator=id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_getTransactionByHash'
|
o['method'] = 'eth_getTransactionByHash'
|
||||||
@ -97,13 +98,13 @@ def get_transaction(conn, tx_hash, id_generator):
|
|||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
block = Block(r)
|
block = Block(r)
|
||||||
tx.apply_block(block)
|
tx.apply_block(block)
|
||||||
logg.debug('foo {}'.format(tx_src))
|
|
||||||
tx.generate_wire(chain_spec)
|
tx.generate_wire(chain_spec)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_address(conn, address, id_generator, height):
|
def get_address(conn, address, id_generator, height):
|
||||||
|
address = add_0x(address)
|
||||||
j = JSONRPCRequest(id_generator=id_generator)
|
j = JSONRPCRequest(id_generator=id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
o['method'] = 'eth_getCode'
|
o['method'] = 'eth_getCode'
|
||||||
|
@ -16,7 +16,7 @@ from hexathon import (
|
|||||||
even,
|
even,
|
||||||
)
|
)
|
||||||
import sha3
|
import sha3
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainlib.eth.address import AddressChecksum
|
from chainlib.eth.address import AddressChecksum
|
||||||
@ -24,6 +24,7 @@ from chainlib.eth.chain import network_id
|
|||||||
from chainlib.eth.block import (
|
from chainlib.eth.block import (
|
||||||
block_latest,
|
block_latest,
|
||||||
block_by_number,
|
block_by_number,
|
||||||
|
syncing,
|
||||||
Block,
|
Block,
|
||||||
)
|
)
|
||||||
from chainlib.eth.tx import count
|
from chainlib.eth.tx import count
|
||||||
@ -43,21 +44,35 @@ logg = logging.getLogger()
|
|||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||||
|
|
||||||
|
results_translation = {
|
||||||
|
'network_id': 'Network Id',
|
||||||
|
'block': 'Block',
|
||||||
|
'syncing': 'Syncing',
|
||||||
|
'gas_limit': 'Gas Limit',
|
||||||
|
'gas_price': 'Gas Price',
|
||||||
|
'block_time': 'Block time',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
arg_flags = chainlib.eth.cli.argflag_std_read
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
argparser.add_positional('address', type=str, help='Address to retrieve info for', required=False)
|
|
||||||
argparser.add_argument('--long', action='store_true', help='Calculate averages through sampling of blocks and txs')
|
argparser.add_argument('--long', action='store_true', help='Calculate averages through sampling of blocks and txs')
|
||||||
|
argparser.add_argument('--local', action='store_true', help='Include local info')
|
||||||
|
argparser.add_positional('entry', required=False, help='Output single item')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args={'long': None}, default_config_dir=config_dir)
|
extra_args = {
|
||||||
|
'local': None,
|
||||||
|
'long': None,
|
||||||
|
'entry': None,
|
||||||
|
}
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_config_dir=config_dir)
|
||||||
|
|
||||||
holder_address = args.address
|
if config.get('_ENTRY') != None:
|
||||||
wallet = chainlib.eth.cli.Wallet()
|
if config.get('_ENTRY') not in results_translation.keys():
|
||||||
wallet.from_config(config)
|
raise ValueError('Unknown entry {}'.format(config.get('_ENTRY')))
|
||||||
if wallet.get_signer_address() == None and holder_address != None:
|
|
||||||
wallet.from_address(holder_address)
|
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
rpc = chainlib.eth.cli.Rpc()
|
||||||
conn = rpc.connect_by_config(config)
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
token_symbol = 'eth'
|
token_symbol = 'eth'
|
||||||
@ -68,12 +83,25 @@ human = not config.true('_RAW')
|
|||||||
|
|
||||||
longmode = config.true('_LONG')
|
longmode = config.true('_LONG')
|
||||||
|
|
||||||
|
def set_result(results, k, v, w=sys.stdout):
|
||||||
|
kt = results_translation[k]
|
||||||
|
if str(config.get('_ENTRY')) == k:
|
||||||
|
w.write('{}'.format(v))
|
||||||
|
return True
|
||||||
|
logg.info('{}: {}\n'.format(kt, v))
|
||||||
|
results[k] = v
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
results = {}
|
||||||
|
|
||||||
o = network_id(id_generator=rpc.id_generator)
|
o = network_id(id_generator=rpc.id_generator)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
#if human:
|
#if human:
|
||||||
# n = format(n, ',')
|
# n = format(n, ',')
|
||||||
sys.stdout.write('Network id: {}\n'.format(r))
|
if set_result(results, 'network_id', r):
|
||||||
|
return
|
||||||
|
|
||||||
o = block_latest(id_generator=rpc.id_generator)
|
o = block_latest(id_generator=rpc.id_generator)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
@ -81,7 +109,8 @@ def main():
|
|||||||
first_block_number = n
|
first_block_number = n
|
||||||
if human:
|
if human:
|
||||||
n = format(n, ',')
|
n = format(n, ',')
|
||||||
sys.stdout.write('Block: {}\n'.format(n))
|
if set_result(results, 'block', n):
|
||||||
|
return
|
||||||
|
|
||||||
o = block_by_number(first_block_number, False, id_generator=rpc.id_generator)
|
o = block_by_number(first_block_number, False, id_generator=rpc.id_generator)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
@ -107,22 +136,31 @@ def main():
|
|||||||
if human:
|
if human:
|
||||||
n = format(n, ',')
|
n = format(n, ',')
|
||||||
|
|
||||||
sys.stdout.write('Gaslimit: {}\n'.format(n))
|
if set_result(results, 'gas_limit', n):
|
||||||
sys.stdout.write('Blocktime: {}\n'.format(aggr_time / BLOCK_SAMPLES))
|
return
|
||||||
|
if set_result(results, 'block_time', aggr_time / BLOCK_SAMPLES):
|
||||||
|
return
|
||||||
|
|
||||||
o = price(id_generator=rpc.id_generator)
|
o = price(id_generator=rpc.id_generator)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
n = int(r, 16)
|
n = int(r, 16)
|
||||||
if human:
|
if human:
|
||||||
n = format(n, ',')
|
n = format(n, ',')
|
||||||
sys.stdout.write('Gasprice: {}\n'.format(n))
|
if set_result(results, 'gas_price', n):
|
||||||
|
return
|
||||||
|
|
||||||
if holder_address != None:
|
if config.get('_LOCAL'):
|
||||||
o = count(holder_address)
|
o = syncing()
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
n = int(r, 16)
|
if set_result(results, 'syncing', r):
|
||||||
sys.stdout.write('Address: {}\n'.format(holder_address))
|
return
|
||||||
sys.stdout.write('Nonce: {}\n'.format(n))
|
|
||||||
|
if config.get('_ENTRY') != None:
|
||||||
|
raise RuntimeError('entry {} ({}) not processed, please review the flag settings'.format(config.get('_ENTRY'), results_translation[config.get('_ENTRY')]))
|
||||||
|
|
||||||
|
for k in results.keys():
|
||||||
|
kt = results_translation[k]
|
||||||
|
sys.stdout.write('{}: {}\n'.format(kt, results[k]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -11,8 +11,8 @@ import urllib
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
|
114
chainlib/eth/runnable/wait.py
Normal file
114
chainlib/eth/runnable/wait.py
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
# 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
|
||||||
|
import chainlib.eth.cli
|
||||||
|
from funga.eth.signer import EIP155Signer
|
||||||
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
|
from hexathon import (
|
||||||
|
add_0x,
|
||||||
|
strip_0x,
|
||||||
|
uniform as hex_uniform,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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.error import RevertEthException
|
||||||
|
from chainlib.chain import ChainSpec
|
||||||
|
from chainlib.eth.runnable.util import decode_for_puny_humans
|
||||||
|
from chainlib.eth.jsonrpc import to_blockheight_param
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||||
|
|
||||||
|
arg_flags = chainlib.eth.cli.argflag_std_read
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
||||||
|
argparser.add_argument('--ignore', type=str, action='append', default=[], help='Ignore error from the given transaction')
|
||||||
|
argparser.add_argument('--ignore-all', action='store_true', dest='ignore_all', help='Ignore errors from all transactions')
|
||||||
|
argparser.add_positional('hashes', append=True, type=str, help='Transaction hashes to wait for')
|
||||||
|
args = argparser.parse_args()
|
||||||
|
extra_args = {
|
||||||
|
'ignore': None,
|
||||||
|
'ignore_all': None,
|
||||||
|
'hashes': None,
|
||||||
|
}
|
||||||
|
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_config_dir=config_dir)
|
||||||
|
|
||||||
|
rpc = chainlib.eth.cli.Rpc()
|
||||||
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
|
chain_spec = None
|
||||||
|
try:
|
||||||
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
hashes_ready = []
|
||||||
|
hashes_ignore = []
|
||||||
|
|
||||||
|
for hsh in config.get('_IGNORE'):
|
||||||
|
hashes_ignore.append(add_0x(hex_uniform(strip_0x(hsh))))
|
||||||
|
|
||||||
|
if len(config.get('_HASHES')) == 1:
|
||||||
|
try:
|
||||||
|
hsh = add_0x(hex_uniform(strip_0x(config.get('_HASHES')[0])))
|
||||||
|
hashes_ready = [hsh]
|
||||||
|
except ValueError:
|
||||||
|
logg.debug('hash argument not a hash, will try it as a file name')
|
||||||
|
f = open(config.get('_HASHES')[0])
|
||||||
|
for hsh in f:
|
||||||
|
logg.debug('hshs {}'.format(hsh))
|
||||||
|
hashes_ready.append(add_0x(hex_uniform(strip_0x(hsh.rstrip()))))
|
||||||
|
f.close()
|
||||||
|
else:
|
||||||
|
for hsh in config.get('_HASHES'):
|
||||||
|
logg.debug('hsh {}'.format(hsh))
|
||||||
|
hashes_ready.append(add_0x(hex_uniform(strip_0x(hsh))))
|
||||||
|
|
||||||
|
for hsh in hashes_ready:
|
||||||
|
logg.debug('processing transaction hash {}'.format(hsh))
|
||||||
|
try:
|
||||||
|
r = conn.wait(hsh)
|
||||||
|
except RevertEthException:
|
||||||
|
if config.get('_IGNORE_ALL') or hsh in hashes_ignore:
|
||||||
|
logg.info('ignoring revert in transaction hash {}'.format(hsh))
|
||||||
|
continue
|
||||||
|
sys.stderr.write('revert in transaction hash {}\n'.format(hsh))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
@ -13,9 +13,11 @@ from hexathon import (
|
|||||||
)
|
)
|
||||||
from rlp import decode as rlp_decode
|
from rlp import decode as rlp_decode
|
||||||
from rlp import encode as rlp_encode
|
from rlp import encode as rlp_encode
|
||||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
from funga.eth.transaction import EIP155Transaction
|
||||||
from crypto_dev_signer.encoding import public_key_to_address
|
from funga.eth.encoding import (
|
||||||
from crypto_dev_signer.eth.encoding import chain_id_to_v
|
public_key_to_address,
|
||||||
|
chain_id_to_v,
|
||||||
|
)
|
||||||
from potaahto.symbols import snake_and_camel
|
from potaahto.symbols import snake_and_camel
|
||||||
from chainlib.hash import keccak256_hex_to_hex
|
from chainlib.hash import keccak256_hex_to_hex
|
||||||
from chainlib.status import Status
|
from chainlib.status import Status
|
||||||
@ -418,6 +420,8 @@ class TxFactory:
|
|||||||
return self.build(tx, id_generator=id_generator)
|
return self.build(tx, id_generator=id_generator)
|
||||||
elif tx_format == TxFormat.RLP_SIGNED:
|
elif tx_format == TxFormat.RLP_SIGNED:
|
||||||
return self.build_raw(tx)
|
return self.build_raw(tx)
|
||||||
|
elif tx_format == TxFormat.RAW_ARGS:
|
||||||
|
return strip_0x(tx['data'])
|
||||||
raise NotImplementedError('tx formatting {} not implemented'.format(tx_format))
|
raise NotImplementedError('tx formatting {} not implemented'.format(tx_format))
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,9 +23,10 @@ from hexathon import (
|
|||||||
add_0x,
|
add_0x,
|
||||||
strip_0x,
|
strip_0x,
|
||||||
)
|
)
|
||||||
|
from chainlib.eth.tx import receipt
|
||||||
|
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
from crypto_dev_signer.encoding import private_key_to_address
|
from funga.eth.encoding import private_key_to_address
|
||||||
|
|
||||||
|
|
||||||
logg = logging.getLogger().getChild(__name__)
|
logg = logging.getLogger().getChild(__name__)
|
||||||
@ -81,6 +82,11 @@ class TestRPCConnection(RPCConnection):
|
|||||||
return jsonrpc_result(r, error_parser)
|
return jsonrpc_result(r, error_parser)
|
||||||
|
|
||||||
|
|
||||||
|
def wait(self, tx_hash_hex):
|
||||||
|
o = receipt(tx_hash_hex)
|
||||||
|
return self.do(o)
|
||||||
|
|
||||||
|
|
||||||
def eth_blockNumber(self, p):
|
def eth_blockNumber(self, p):
|
||||||
block = self.backend.get_block_by_number('latest')
|
block = self.backend.get_block_by_number('latest')
|
||||||
return block['number']
|
return block['number']
|
||||||
|
@ -5,8 +5,8 @@ import logging
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import eth_tester
|
import eth_tester
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
strip_0x,
|
strip_0x,
|
||||||
add_0x,
|
add_0x,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
crypto-dev-signer>=0.4.15rc2,<=0.4.15
|
funga-eth~=0.5.1
|
||||||
pysha3==1.0.2
|
pysha3==1.0.2
|
||||||
hexathon~=0.0.1a8
|
hexathon~=0.1.0
|
||||||
websocket-client==0.57.0
|
websocket-client==0.57.0
|
||||||
potaahto~=0.0.1a1
|
potaahto~=0.1.0
|
||||||
chainlib==0.0.10a2
|
chainlib~=0.0.14
|
||||||
confini>=0.4.1a1,<0.5.0
|
confini~=0.5.2
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chainlib-eth
|
name = chainlib-eth
|
||||||
version = 0.0.9rc5
|
version = 0.0.15
|
||||||
description = Ethereum implementation of the chainlib interface
|
description = Ethereum implementation of the chainlib interface
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
@ -14,6 +14,7 @@ classifiers =
|
|||||||
Programming Language :: Python :: 3
|
Programming Language :: Python :: 3
|
||||||
Operating System :: OS Independent
|
Operating System :: OS Independent
|
||||||
Development Status :: 3 - Alpha
|
Development Status :: 3 - Alpha
|
||||||
|
Topic :: Software Development :: Libraries
|
||||||
Environment :: Console
|
Environment :: Console
|
||||||
Intended Audience :: Developers
|
Intended Audience :: Developers
|
||||||
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
||||||
@ -36,6 +37,7 @@ packages =
|
|||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
|
eth-count = chainlib.eth.runnable.count:main
|
||||||
eth-balance = chainlib.eth.runnable.balance:main
|
eth-balance = chainlib.eth.runnable.balance:main
|
||||||
eth-checksum = chainlib.eth.runnable.checksum:main
|
eth-checksum = chainlib.eth.runnable.checksum:main
|
||||||
eth-gas = chainlib.eth.runnable.gas:main
|
eth-gas = chainlib.eth.runnable.gas:main
|
||||||
@ -45,4 +47,5 @@ console_scripts =
|
|||||||
eth-encode = chainlib.eth.runnable.encode:main
|
eth-encode = chainlib.eth.runnable.encode:main
|
||||||
eth-info = chainlib.eth.runnable.info:main
|
eth-info = chainlib.eth.runnable.info:main
|
||||||
eth-nonce = chainlib.eth.runnable.count:main
|
eth-nonce = chainlib.eth.runnable.count:main
|
||||||
|
eth-wait = chainlib.eth.runnable.wait:main
|
||||||
eth = chainlib.eth.runnable.info:main
|
eth = chainlib.eth.runnable.info:main
|
||||||
|
@ -2,3 +2,4 @@ eth_tester==0.5.0b3
|
|||||||
py-evm==0.3.0a20
|
py-evm==0.3.0a20
|
||||||
rlp==2.0.1
|
rlp==2.0.1
|
||||||
pytest==6.0.1
|
pytest==6.0.1
|
||||||
|
coverage==5.5
|
||||||
|
@ -7,9 +7,9 @@ import logging
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
from funga.eth.transaction import EIP155Transaction
|
||||||
from crypto_dev_signer.eth.signer.defaultsigner import ReferenceSigner
|
from funga.eth.signer.defaultsigner import EIP155Signer
|
||||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
from funga.eth.keystore.dict import DictKeystore
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
import chainlib
|
import chainlib
|
||||||
@ -97,7 +97,7 @@ class TestSign(TestBase):
|
|||||||
logg.debug('alice {}'.format(alice))
|
logg.debug('alice {}'.format(alice))
|
||||||
logg.debug('bob {}'.format(bob))
|
logg.debug('bob {}'.format(bob))
|
||||||
|
|
||||||
self.signer = ReferenceSigner(keystore)
|
self.signer = EIP155Signer(keystore)
|
||||||
|
|
||||||
Mocket.signer = self.signer
|
Mocket.signer = self.signer
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user