From 61b4f5a07ad4dd5fd72511bfc45e417493a2dd1d Mon Sep 17 00:00:00 2001 From: MMGen Date: Wed, 6 Feb 2019 10:44:27 +0000 Subject: [PATCH] py3port: Parity: support 'eth_chainId' RPC call --- mmgen/altcoins/eth/contract.py | 3 ++- mmgen/altcoins/eth/tx.py | 3 ++- mmgen/bech32.py | 0 mmgen/ed25519ll_djbec.py | 0 mmgen/rpc.py | 7 ++++--- mmgen/util.py | 6 ++++++ 6 files changed, 14 insertions(+), 5 deletions(-) mode change 100644 => 100755 mmgen/bech32.py mode change 100644 => 100755 mmgen/ed25519ll_djbec.py diff --git a/mmgen/altcoins/eth/contract.py b/mmgen/altcoins/eth/contract.py index b802ab2d..50641a59 100755 --- a/mmgen/altcoins/eth/contract.py +++ b/mmgen/altcoins/eth/contract.py @@ -105,7 +105,8 @@ class Token(MMGenObject): # ERC20 def txsign(self,tx_in,key,from_addr,chain_id=None): if chain_id is None: - chain_id = int(g.rpch.parity_chainId(),16) + chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpch.caps] + chain_id = int(g.rpch.request(chain_id_method),16) tx = Transaction(**tx_in).sign(key,chain_id) hex_tx = hexlify(rlp.encode(tx)) coin_txid = CoinTxID(hexlify(tx.hash)) diff --git a/mmgen/altcoins/eth/tx.py b/mmgen/altcoins/eth/tx.py index b010ce83..9b31beb1 100755 --- a/mmgen/altcoins/eth/tx.py +++ b/mmgen/altcoins/eth/tx.py @@ -130,6 +130,7 @@ class EthereumMMGenTX(MMGenTX): return ETHNonce(int(g.rpch.parity_nextNonce('0x'+self.inputs[0].addr),16)) def make_txobj(self): # create_raw + chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpch.caps] self.txobj = { 'from': self.inputs[0].addr, 'to': self.outputs[0].addr if self.outputs else Str(''), @@ -137,7 +138,7 @@ class EthereumMMGenTX(MMGenTX): 'gasPrice': self.usr_rel_fee or self.fee_abs2rel(self.fee,to_unit='eth'), 'startGas': self.start_gas, 'nonce': self.get_nonce(), - 'chainId': Int(g.rpch.parity_chainId(),16), + 'chainId': Int(g.rpch.request(chain_id_method),16), 'data': self.data, } diff --git a/mmgen/bech32.py b/mmgen/bech32.py old mode 100644 new mode 100755 diff --git a/mmgen/ed25519ll_djbec.py b/mmgen/ed25519ll_djbec.py old mode 100644 new mode 100755 diff --git a/mmgen/rpc.py b/mmgen/rpc.py index 65777112..9d61f440 100755 --- a/mmgen/rpc.py +++ b/mmgen/rpc.py @@ -218,6 +218,9 @@ class EthereumRPCConnection(CoinDaemonRPCConnection): '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. + 'eth_chainId', 'eth_gasPrice', 'eth_getBalance', 'eth_getBlockByHash', @@ -233,9 +236,7 @@ class EthereumRPCConnection(CoinDaemonRPCConnection): 'net_peerCount', 'net_version', 'parity_chain', - # Returns the EIP155 chain ID used for transaction signing at the current best block. - # Null is returned if not available. - 'parity_chainId', + 'parity_chainId', # superseded by eth_chainId 'parity_chainStatus', 'parity_composeTransaction', 'parity_gasCeilTarget', diff --git a/mmgen/util.py b/mmgen/util.py index 9e153c99..c598127f 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -857,6 +857,12 @@ def rpc_init_parity(): (g.token,g.dcoin) = resolve_token_arg(g.token) g.rpch.caps = () + try: + g.rpch.request('eth_chainId') + g.rpch.caps += ('eth_chainId',) + except RPCFailure: + pass + return g.rpch def rpc_init_bitcoind():