protocol.py: chain_name -> chain_names
This commit is contained in:
parent
44ace41c79
commit
0ff49400b6
4 changed files with 34 additions and 33 deletions
|
|
@ -109,11 +109,11 @@
|
|||
# Set the maximum transaction fee for ETH:
|
||||
# eth_max_tx_fee 0.005
|
||||
|
||||
# Set the Ethereum mainnet name:
|
||||
# eth_mainnet_chain_name foundation
|
||||
# Set the Ethereum mainnet chain names (space-separated list, first is default):
|
||||
# eth_mainnet_chain_names ethereum foundation
|
||||
|
||||
# Set the Ethereum testnet name:
|
||||
# eth_testnet_chain_name kovan
|
||||
# Set the Ethereum testnet chain names (space-separated list, first is default):
|
||||
# eth_testnet_chain_names kovan
|
||||
|
||||
# Set the Monero wallet RPC host:
|
||||
# monero_wallet_rpc_host localhost
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ class GlobalContext(Lockable):
|
|||
'btc_max_tx_fee','ltc_max_tx_fee','bch_max_tx_fee','eth_max_tx_fee',
|
||||
'btc_ignore_daemon_version','bch_ignore_daemon_version','ltc_ignore_daemon_version',
|
||||
'eth_ignore_daemon_version','etc_ignore_daemon_version',
|
||||
'eth_mainnet_chain_name','eth_testnet_chain_name',
|
||||
'eth_mainnet_chain_names','eth_testnet_chain_names',
|
||||
'max_tx_file_size','max_input_size'
|
||||
)
|
||||
# Supported environmental vars
|
||||
|
|
|
|||
|
|
@ -102,8 +102,8 @@ class CoinProtocol(MMGenObject):
|
|||
'regtest': '_rt',
|
||||
}[network]
|
||||
|
||||
if not hasattr(self,'chain_name'):
|
||||
self.chain_name = self.network
|
||||
# first chain name is default
|
||||
self.chain_name = self.chain_names[0] if hasattr(self,'chain_names') else self.network
|
||||
|
||||
if self.tokensym:
|
||||
assert isinstance(self,CoinProtocol.Ethereum), 'CoinProtocol.Base_chk1'
|
||||
|
|
@ -122,16 +122,11 @@ class CoinProtocol(MMGenObject):
|
|||
the attribute 'chain_name' is used, while 'network' retains the generic name.
|
||||
For Bitcoin and Bitcoin forks, 'network' and 'chain_name' are equivalent.
|
||||
"""
|
||||
for network,suf in (
|
||||
('mainnet',''),
|
||||
('testnet','Testnet'),
|
||||
('regtest','Regtest' ),
|
||||
):
|
||||
name = CoinProtocol.coins[coin.lower()].name + suf
|
||||
proto = getattr(CoinProtocol,name)
|
||||
proto_chain_name = getattr(proto,'chain_name',None) or network
|
||||
if chain_name == proto_chain_name:
|
||||
return network
|
||||
for network in ('mainnet','testnet','regtest'):
|
||||
proto = init_proto(coin,network=network)
|
||||
for proto_chain_name in ( getattr(proto,'chain_names',None) or [network] ):
|
||||
if chain_name == proto_chain_name:
|
||||
return network
|
||||
raise ValueError(f'{chain_name}: unrecognized chain name for coin {coin}')
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -144,6 +139,10 @@ class CoinProtocol(MMGenObject):
|
|||
else:
|
||||
return nid(network_id,'mainnet')
|
||||
|
||||
@staticmethod
|
||||
def create_network_id(coin,network):
|
||||
return coin.lower() + { 'mainnet':'', 'testnet':'_tn', 'regtest':'_rt' }[network]
|
||||
|
||||
def cap(self,s):
|
||||
return s in self.caps
|
||||
|
||||
|
|
@ -384,7 +383,7 @@ class CoinProtocol(MMGenObject):
|
|||
|
||||
coin_amt = ETHAmt
|
||||
max_tx_fee = ETHAmt('0.005')
|
||||
chain_name = 'foundation'
|
||||
chain_names = ['ethereum','foundation']
|
||||
sign_mode = 'standalone'
|
||||
caps = ('token',)
|
||||
mmcaps = ('key','addr','rpc','tx')
|
||||
|
|
@ -410,21 +409,21 @@ class CoinProtocol(MMGenObject):
|
|||
return pubkey_hash
|
||||
|
||||
class EthereumTestnet(Ethereum):
|
||||
chain_name = 'kovan'
|
||||
chain_names = ['kovan']
|
||||
|
||||
class EthereumRegtest(EthereumTestnet):
|
||||
chain_name = 'developmentchain'
|
||||
chain_names = ['developmentchain']
|
||||
|
||||
class EthereumClassic(Ethereum):
|
||||
chain_name = 'ethereum_classic' # chain_id 0x3d (61)
|
||||
max_tx_fee = ETHAmt('0.005')
|
||||
chain_names = ['ethereum_classic'] # chain_id 0x3d (61)
|
||||
max_tx_fee = ETHAmt('0.005')
|
||||
ignore_daemon_version = False
|
||||
|
||||
class EthereumClassicTestnet(EthereumClassic):
|
||||
chain_name = 'classic-testnet' # aka Morden, chain_id 0x3e (62) (UNTESTED)
|
||||
chain_names = ['classic-testnet'] # aka Morden, chain_id 0x3e (62) (UNTESTED)
|
||||
|
||||
class EthereumClassicRegtest(EthereumClassicTestnet):
|
||||
chain_name = 'developmentchain'
|
||||
chain_names = ['developmentchain']
|
||||
|
||||
class Zcash(Bitcoin):
|
||||
base_coin = 'ZEC'
|
||||
|
|
|
|||
|
|
@ -216,9 +216,9 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
def run(chk,testnet):
|
||||
for coin,chain_chk in (('ETH',chk),('ETC',None)):
|
||||
t = self.spawn_test(
|
||||
args = [f'--coin={coin}',f'--testnet={(0,1)[testnet]}','coin_specific_vars','chain_name'],
|
||||
extra_desc = f'({coin} testnet={testnet} chain={chain_chk})' )
|
||||
chain = t.expect_getend('chain_name: ')
|
||||
args = [f'--coin={coin}',f'--testnet={(0,1)[testnet]}','coin_specific_vars','chain_names'],
|
||||
extra_desc = f'({coin} testnet={testnet} chain_names={chain_chk})' )
|
||||
chain = t.expect_getend('chain_names: ')
|
||||
if chain_chk:
|
||||
assert chain == chain_chk, f'{chain} != {chain_chk}'
|
||||
else:
|
||||
|
|
@ -227,15 +227,17 @@ class TestSuiteCfg(TestSuiteBase):
|
|||
t.ok()
|
||||
return t
|
||||
|
||||
write_to_file(self.path('usr'),'eth_mainnet_chain_name foobar\n')
|
||||
imsg(yellow('Wrote cfg file: "eth_mainnet_chain_name foobar"'))
|
||||
t = run('foobar',False)
|
||||
txt = 'eth_mainnet_chain_names istanbul constantinople'
|
||||
write_to_file(self.path('usr'),txt+'\n')
|
||||
imsg(yellow(f'Wrote cfg file: "{txt}"'))
|
||||
t = run("['istanbul', 'constantinople']",False)
|
||||
t = run(None,True)
|
||||
|
||||
write_to_file(self.path('usr'),'eth_testnet_chain_name foobar\n')
|
||||
imsg(yellow('Wrote cfg file: "eth_testnet_chain_name foobar"'))
|
||||
txt = 'eth_testnet_chain_names rinkeby'
|
||||
write_to_file(self.path('usr'),txt+'\n')
|
||||
imsg(yellow(f'Wrote cfg file: "{txt}"'))
|
||||
t = run(None,False)
|
||||
t = run('foobar',True)
|
||||
t = run("['rinkeby']",True)
|
||||
|
||||
t.skip_ok = True
|
||||
return t
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue