rpc.py: remove parity methods where possible, related cleanups

This commit is contained in:
The MMGen Project 2021-08-01 20:54:50 +00:00
commit 6da5fca5de
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 18 additions and 22 deletions

View file

@ -114,7 +114,9 @@ class TokenBase(MMGenObject): # ERC20
from .pyethereum.transactions import Transaction
if chain_id is None:
chain_id = int(await self.rpc.call('eth_chainId'),16)
res = await self.rpc.call('eth_chainId')
chain_id = None if res == None else int(res,16)
tx = Transaction(**tx_in).sign(key,chain_id)
hex_tx = rlp.encode(tx).hex()
coin_txid = CoinTxID(tx.hash.hex())
@ -138,7 +140,7 @@ class TokenBase(MMGenObject): # ERC20
tx_in = self.make_tx_in(
from_addr,to_addr,amt,
start_gas,gasPrice,
nonce = int(await self.rpc.call('parity_nextNonce','0x'+from_addr),16),
nonce = int(await self.rpc.call('eth_getTransactionCount','0x'+from_addr,'pending'),16),
method_sig = method_sig,
from_addr2 = from_addr2 )
(hex_tx,coin_txid) = await self.txsign(tx_in,key,from_addr)

View file

@ -75,7 +75,7 @@ class EthereumTrackingWallet(TrackingWallet):
msg('{} upgraded successfully!'.format(self.desc))
async def rpc_get_balance(self,addr):
return ETHAmt(int(await self.rpc.call('eth_getBalance','0x'+addr),16),'wei')
return ETHAmt(int(await self.rpc.call('eth_getBalance','0x'+addr,'latest'),16),'wei')
@write_mode
async def batch_import_address(self,args_list):

View file

@ -85,7 +85,7 @@ class EthereumMMGenTX:
self.disable_fee_check = True
async def get_nonce(self):
return ETHNonce(int(await self.rpc.call('parity_nextNonce','0x'+self.inputs[0].addr),16))
return ETHNonce(int(await self.rpc.call('eth_getTransactionCount','0x'+self.inputs[0].addr,'pending'),16))
async def make_txobj(self): # called by create_raw()
self.txobj = {
@ -95,7 +95,7 @@ class EthereumMMGenTX:
'gasPrice': self.fee_abs2rel(self.usr_fee,to_unit='eth'),
'startGas': self.start_gas,
'nonce': await self.get_nonce(),
'chainId': Int(await self.rpc.call('eth_chainId'),16),
'chainId': self.rpc.chainID,
'data': self.usr_contract_data,
}
@ -302,7 +302,7 @@ class EthereumMMGenTX:
'gasPrice': ETHAmt(d['gasPrice']),
'startGas': ETHAmt(d['startGas']),
'nonce': ETHNonce(d['nonce']),
'chainId': Int(d['chainId']),
'chainId': None if d['chainId'] == 'None' else Int(d['chainId']),
'data': HexStr(d['data']) }
self.tx_gas = o['startGas'] # approximate, but better than nothing
self.txobj = o
@ -394,8 +394,9 @@ class EthereumMMGenTX:
async def is_in_mempool():
if not 'full_node' in self.rpc.caps:
return False
return '0x'+self.coin_txid in [
x['hash'] for x in await self.rpc.call('parity_pendingTransactions') ]
if self.rpc.daemon.id in ('parity','openethereum'):
pool = [x['hash'] for x in await self.rpc.call('parity_pendingTransactions')]
return '0x'+self.coin_txid in pool
async def is_in_wallet():
d = await self.rpc.call('eth_getTransactionReceipt','0x'+self.coin_txid)

View file

@ -613,42 +613,35 @@ class EthereumRPCClient(RPCClient,metaclass=aInitMeta):
Requested daemon: {self.daemon.id}
Running daemon: {vi}
""",strip_char='\t').rstrip())
self.daemon_version = int('{:d}{:03d}{:03d}'.format(*[int(e) for e in vip.groups()]))
self.daemon_version_str = '{}.{}.{}'.format(*vip.groups())
self.daemon_version_info = vi
self.blockcount = int(bh['number'],16)
self.cur_date = int(bh['timestamp'],16)
self.caps = ()
from .obj import Int
if self.daemon.id in ('parity','openethereum'):
if (await self.call('parity_nodeKind'))['capability'] == 'full':
self.caps += ('full_node',)
self.chainID = None
self.chain = (await self.call('parity_chain')).replace(' ','_')
self.chainID = None if ci == None else Int(ci,16) # parity/oe return chainID only for dev chain
self.chain = (await self.call('parity_chain')).replace(' ','_').replace('_testnet','')
rpcmethods = (
'eth_accounts',
'eth_blockNumber',
'eth_call',
# Returns the EIP155 chain ID used for transaction signing at the current best block.
# Null is returned if not available.
# Parity: Null is returned if not available, ID not required in transactions
'eth_chainId',
'eth_gasPrice',
'eth_getBalance',
'eth_getBlockByHash',
'eth_getCode',
'eth_getTransactionByHash',
'eth_getTransactionCount',
'eth_getTransactionReceipt',
'eth_protocolVersion',
'eth_sendRawTransaction',
'eth_signTransaction',
'eth_syncing',
'net_listening',
'net_peerCount',
'net_version',
'parity_chain',
'parity_getBlockHeaderByNumber',
'parity_nextNonce',
'parity_nodeKind',
'parity_pendingTransactions',
)