Browse Source

py3port: Parity: support 'eth_chainId' RPC call

MMGen 6 years ago
parent
commit
61b4f5a07a
4 changed files with 14 additions and 5 deletions
  1. 2 1
      mmgen/altcoins/eth/contract.py
  2. 2 1
      mmgen/altcoins/eth/tx.py
  3. 4 3
      mmgen/bech32.py
  4. 6 0
      mmgen/util.py

+ 2 - 1
mmgen/altcoins/eth/contract.py

@@ -105,7 +105,8 @@ class Token(MMGenObject): # ERC20
 
 
 	def txsign(self,tx_in,key,from_addr,chain_id=None):
 	def txsign(self,tx_in,key,from_addr,chain_id=None):
 		if chain_id is 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)
 		tx = Transaction(**tx_in).sign(key,chain_id)
 		hex_tx = hexlify(rlp.encode(tx))
 		hex_tx = hexlify(rlp.encode(tx))
 		coin_txid = CoinTxID(hexlify(tx.hash))
 		coin_txid = CoinTxID(hexlify(tx.hash))

+ 2 - 1
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))
 		return ETHNonce(int(g.rpch.parity_nextNonce('0x'+self.inputs[0].addr),16))
 
 
 	def make_txobj(self): # create_raw
 	def make_txobj(self): # create_raw
+		chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpch.caps]
 		self.txobj = {
 		self.txobj = {
 			'from': self.inputs[0].addr,
 			'from': self.inputs[0].addr,
 			'to':   self.outputs[0].addr if self.outputs else Str(''),
 			'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'),
 			'gasPrice': self.usr_rel_fee or self.fee_abs2rel(self.fee,to_unit='eth'),
 			'startGas': self.start_gas,
 			'startGas': self.start_gas,
 			'nonce': self.get_nonce(),
 			'nonce': self.get_nonce(),
-			'chainId': Int(g.rpch.parity_chainId(),16),
+			'chainId': Int(g.rpch.request(chain_id_method),16),
 			'data':  self.data,
 			'data':  self.data,
 		}
 		}
 
 

+ 4 - 3
mmgen/bech32.py

@@ -218,6 +218,9 @@ class EthereumRPCConnection(CoinDaemonRPCConnection):
 		'eth_accounts',
 		'eth_accounts',
 		'eth_blockNumber',
 		'eth_blockNumber',
 		'eth_call',
 		'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_gasPrice',
 		'eth_getBalance',
 		'eth_getBalance',
 		'eth_getBlockByHash',
 		'eth_getBlockByHash',
@@ -233,9 +236,7 @@ class EthereumRPCConnection(CoinDaemonRPCConnection):
 		'net_peerCount',
 		'net_peerCount',
 		'net_version',
 		'net_version',
 		'parity_chain',
 		'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_chainStatus',
 		'parity_composeTransaction',
 		'parity_composeTransaction',
 		'parity_gasCeilTarget',
 		'parity_gasCeilTarget',

+ 6 - 0
mmgen/util.py

@@ -857,6 +857,12 @@ def rpc_init_parity():
 		(g.token,g.dcoin) = resolve_token_arg(g.token)
 		(g.token,g.dcoin) = resolve_token_arg(g.token)
 
 
 	g.rpch.caps = ()
 	g.rpch.caps = ()
+	try:
+		g.rpch.request('eth_chainId')
+		g.rpch.caps += ('eth_chainId',)
+	except RPCFailure:
+		pass
+
 	return g.rpch
 	return g.rpch
 
 
 def rpc_init_bitcoind():
 def rpc_init_bitcoind():