From 6da5fca5de2777452509b9ca17ad57fdbb616286 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 1 Aug 2021 20:54:50 +0000 Subject: [PATCH] rpc.py: remove parity methods where possible, related cleanups --- mmgen/altcoins/eth/contract.py | 6 ++++-- mmgen/altcoins/eth/tw.py | 2 +- mmgen/altcoins/eth/tx.py | 11 ++++++----- mmgen/rpc.py | 21 +++++++-------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/mmgen/altcoins/eth/contract.py b/mmgen/altcoins/eth/contract.py index 6e24d79d..3c484996 100755 --- a/mmgen/altcoins/eth/contract.py +++ b/mmgen/altcoins/eth/contract.py @@ -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) diff --git a/mmgen/altcoins/eth/tw.py b/mmgen/altcoins/eth/tw.py index 6646d3cf..c535b97d 100755 --- a/mmgen/altcoins/eth/tw.py +++ b/mmgen/altcoins/eth/tw.py @@ -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): diff --git a/mmgen/altcoins/eth/tx.py b/mmgen/altcoins/eth/tx.py index 234d5527..c19e9007 100755 --- a/mmgen/altcoins/eth/tx.py +++ b/mmgen/altcoins/eth/tx.py @@ -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) diff --git a/mmgen/rpc.py b/mmgen/rpc.py index 0281856c..741f2587 100755 --- a/mmgen/rpc.py +++ b/mmgen/rpc.py @@ -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', )