global change: init_coin() -> g.proto = init_proto()
This commit is contained in:
parent
17ce9e54b5
commit
43432327c7
11 changed files with 33 additions and 42 deletions
|
|
@ -543,17 +543,15 @@ class EthereumDaemon(CoinDaemon):
|
|||
return 'ready' if self.test_socket('localhost',self.rpc_port) else 'stopped'
|
||||
|
||||
# the following code does not work
|
||||
from mmgen.protocol import init_coin
|
||||
init_coin('eth')
|
||||
|
||||
async def do():
|
||||
print(g.rpc)
|
||||
ret = await g.rpc.call('eth_chainId')
|
||||
print(ret)
|
||||
return ('stopped','ready')[ret == '0x11']
|
||||
|
||||
from mmgen.protocol import init_proto
|
||||
try:
|
||||
return run_session(do()) # socket exception is not propagated
|
||||
return run_session(do(),proto=init_proto('eth')) # socket exception is not propagated
|
||||
except:# SocketError:
|
||||
return 'stopped'
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ exit_if_mswin('autosigning')
|
|||
|
||||
import mmgen.tx
|
||||
from .txsign import txsign
|
||||
from .protocol import init_proto,init_coin
|
||||
from .protocol import init_proto
|
||||
from .rpc import rpc_init
|
||||
|
||||
if g.test_suite:
|
||||
|
|
@ -177,14 +177,14 @@ def do_umount():
|
|||
|
||||
async def sign_tx_file(txfile,signed_txs):
|
||||
try:
|
||||
init_coin('BTC',testnet=False)
|
||||
g.proto = init_proto('BTC',testnet=False)
|
||||
tmp_tx = mmgen.tx.MMGenTX(txfile,metadata_only=True)
|
||||
init_coin(tmp_tx.coin)
|
||||
g.proto = init_proto(tmp_tx.coin)
|
||||
|
||||
if tmp_tx.chain != 'mainnet':
|
||||
if tmp_tx.chain == 'testnet' or (
|
||||
hasattr(g.proto,'chain_name') and tmp_tx.chain != g.proto.chain_name):
|
||||
init_coin(tmp_tx.coin,testnet=True)
|
||||
g.proto = init_proto(tmp_tx.coin,testnet=True)
|
||||
|
||||
if hasattr(g.proto,'chain_name'):
|
||||
if tmp_tx.chain != g.proto.chain_name:
|
||||
|
|
@ -265,7 +265,7 @@ def print_summary(signed_txs):
|
|||
bmsg('\nAutosign summary:\n')
|
||||
def gen():
|
||||
for tx in signed_txs:
|
||||
init_coin(tx.coin,tx.chain == 'testnet')
|
||||
g.proto = init_proto(tx.coin,testnet=tx.chain=='testnet')
|
||||
yield tx.format_view(terse=True)
|
||||
msg_r(''.join(gen()))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -108,11 +108,11 @@ if mmids[0] == mmids[1]:
|
|||
die(2,'Both transactions have the same output! ({})'.format(mmids[0]))
|
||||
|
||||
from .tx import MMGenSplitTX
|
||||
from .protocol import init_coin
|
||||
from .protocol import init_proto
|
||||
|
||||
if opt.tx_fees:
|
||||
for idx,g_coin in ((1,opt.other_coin),(0,g.coin)):
|
||||
init_coin(g_coin)
|
||||
g.proto = init_proto(g_coin)
|
||||
opt.tx_fee = opt.tx_fees.split(',')[idx]
|
||||
opts.opt_is_tx_fee('foo',opt.tx_fee,'transaction fee') # raises exception on error
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ async def main():
|
|||
|
||||
gmsg("\nCreating transaction for short chain ({})".format(opt.other_coin))
|
||||
|
||||
init_coin(opt.other_coin)
|
||||
g.proto = init_proto(opt.other_coin)
|
||||
|
||||
tx2 = MMGenSplitTX()
|
||||
tx2.inputs = tx1.inputs
|
||||
|
|
|
|||
|
|
@ -562,9 +562,3 @@ def make_init_genonly_altcoins_str(data):
|
|||
e.trust_level )
|
||||
|
||||
return '\n'.join(gen_text()) + '\n'
|
||||
|
||||
def init_coin(coin,testnet=None):
|
||||
if testnet is None:
|
||||
testnet = g.proto.testnet
|
||||
g.proto = init_proto(coin,testnet=testnet,regtest=g.proto.regtest)
|
||||
return g.proto
|
||||
|
|
|
|||
|
|
@ -1063,8 +1063,8 @@ class MMGenToolCmdMonero(MMGenToolCmds):
|
|||
|
||||
async def process_wallets(op):
|
||||
opt.accept_defaults = opt.accept_defaults or op.accept_defaults
|
||||
from .protocol import init_coin
|
||||
init_coin('xmr')
|
||||
from .protocol import init_proto
|
||||
g.proto = init_proto('xmr')
|
||||
from .addr import AddrList
|
||||
al = KeyAddrList(infile)
|
||||
data = [d for d in al.data if addrs == '' or d.idx in AddrIdxList(addrs)]
|
||||
|
|
@ -1183,10 +1183,10 @@ class tool_api(
|
|||
Valid choices for coins: one of the symbols returned by the 'coins' attribute
|
||||
Valid choices for network: 'mainnet','testnet','regtest'
|
||||
"""
|
||||
from .protocol import init_coin,init_genonly_altcoins
|
||||
from .protocol import init_proto,init_genonly_altcoins
|
||||
altcoin_trust_level = init_genonly_altcoins(coinsym,testnet=network in ('testnet','regtest'))
|
||||
warn_altcoins(coinsym,altcoin_trust_level)
|
||||
return init_coin(coinsym,{'mainnet':False,'testnet':True,'regtest':True}[network])
|
||||
return init_proto(coinsym,network=network)
|
||||
|
||||
@property
|
||||
def coins(self):
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ tx = mmgen.tx.MMGenTX(cmd_args[0])
|
|||
if opt.verbose:
|
||||
gmsg('Original transaction is in {} format'.format(g.coin))
|
||||
|
||||
from mmgen.protocol import init_coin
|
||||
init_coin('BCH')
|
||||
from mmgen.protocol import init_proto
|
||||
g.proto = init_proto('bch')
|
||||
|
||||
if opt.verbose:
|
||||
gmsg('Converting transaction to {} format'.format(g.coin))
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class GenTool(object):
|
|||
class GenToolEthkey(GenTool):
|
||||
desc = 'ethkey'
|
||||
def __init__(self):
|
||||
init_coin('eth')
|
||||
g.proto = init_proto('eth')
|
||||
global addr_type
|
||||
addr_type = MMGenAddrType('E')
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ class GenToolKeyconv(GenTool):
|
|||
class GenToolZcash_mini(GenTool):
|
||||
desc = 'zcash-mini'
|
||||
def __init__(self):
|
||||
init_coin('zec')
|
||||
g.proto = init_proto('zec')
|
||||
global addr_type
|
||||
addr_type = MMGenAddrType('Z')
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ class GenToolMoneropy(GenTool):
|
|||
raise ImportError(m)
|
||||
|
||||
self.mpa = moneropy.account
|
||||
init_coin('xmr')
|
||||
g.proto = init_proto('xmr')
|
||||
|
||||
global addr_type
|
||||
addr_type = MMGenAddrType('M')
|
||||
|
|
@ -390,7 +390,7 @@ def parse_arg2():
|
|||
die(1,m)
|
||||
|
||||
# begin execution
|
||||
from mmgen.protocol import init_coin
|
||||
from mmgen.protocol import init_proto
|
||||
from mmgen.altcoin import CoinInfo as ci
|
||||
from mmgen.obj import MMGenAddrType,PrivKey
|
||||
from mmgen.addr import KeyGenerator,AddrGenerator
|
||||
|
|
@ -427,7 +427,7 @@ elif a and b and type(arg2) == int:
|
|||
if coin.lower() not in CoinProtocol.coins:
|
||||
# ymsg('Coin {} not configured'.format(coin))
|
||||
continue
|
||||
init_coin(coin)
|
||||
g.proto = init_proto(coin)
|
||||
if addr_type not in g.proto.mmtypes:
|
||||
continue
|
||||
# g.proto has changed, so reinit kg and ag just to be on the safe side:
|
||||
|
|
|
|||
|
|
@ -158,5 +158,5 @@ def do_loop():
|
|||
msg(clr('Testing {}'.format(obj)))
|
||||
test_object(test_data,obj)
|
||||
|
||||
init_coin(g.coin)
|
||||
g.proto = init_proto(g.coin)
|
||||
do_loop()
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
|
|||
def ref_altcoin_tx_chk(self):
|
||||
self.write_to_tmpfile(pwfile,dfl_wpasswd)
|
||||
pf = joinpath(self.tmpdir,pwfile)
|
||||
from mmgen.protocol import init_coin
|
||||
from mmgen.protocol import init_proto
|
||||
from mmgen.daemon import CoinDaemon
|
||||
for k in ('bch','eth','mm1','etc'):
|
||||
coin,token = ('eth','mm1') if k == 'mm1' else (k,None)
|
||||
|
|
@ -98,7 +98,7 @@ class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
|
|||
extra_opts += [
|
||||
'--daemon-data-dir=test/daemons/bch',
|
||||
'--rpc-port={}'.format(CoinDaemon(network_id,test_suite=True).rpc_port) ]
|
||||
init_coin(coin,testnet=tn)
|
||||
g.proto = init_proto(coin,testnet=tn)
|
||||
fn = TestSuiteRef.sources['ref_tx_file'][token or coin][bool(tn)]
|
||||
tf = joinpath(ref_dir,ref_subdir,fn)
|
||||
wf = dfl_words_file
|
||||
|
|
@ -112,7 +112,7 @@ class TestSuiteRefAltcoin(TestSuiteRef,TestSuiteBase):
|
|||
if coin == 'bch':
|
||||
stop_test_daemons(network_id)
|
||||
ok_msg()
|
||||
init_coin('btc')
|
||||
g.proto = init_proto('btc')
|
||||
t.skip_ok = True
|
||||
return t
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ test.unit_tests_d.ut_rpc: RPC unit test for the MMGen suite
|
|||
from mmgen.common import *
|
||||
from mmgen.exception import *
|
||||
|
||||
from mmgen.protocol import init_coin
|
||||
from mmgen.protocol import init_proto
|
||||
from mmgen.rpc import MoneroWalletRPCClient
|
||||
from mmgen.daemon import CoinDaemon,MoneroWalletDaemon
|
||||
|
||||
|
|
@ -84,7 +84,6 @@ class unit_tests:
|
|||
def eth(self,name,ut):
|
||||
ed = CoinDaemon('eth',test_suite=True)
|
||||
ed.start()
|
||||
init_coin('eth')
|
||||
g.rpc_port = CoinDaemon('eth',test_suite=True).rpc_port
|
||||
|
||||
async def run_test():
|
||||
|
|
@ -92,7 +91,7 @@ class unit_tests:
|
|||
ret = await g.rpc.call('parity_versionInfo',timeout=300)
|
||||
|
||||
for backend in g.autoset_opts['rpc_backend'].choices:
|
||||
run_session(run_test(),backend=backend)
|
||||
run_session(run_test(),proto=init_proto('eth'),backend=backend)
|
||||
|
||||
ed.stop()
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import os,json
|
|||
|
||||
from mmgen.common import *
|
||||
from ..include.common import *
|
||||
from mmgen.protocol import init_coin
|
||||
from mmgen.protocol import init_proto
|
||||
from mmgen.tx import MMGenTX,DeserializedTX
|
||||
from mmgen.rpc import rpc_init
|
||||
from mmgen.daemon import CoinDaemon
|
||||
|
|
@ -114,11 +114,11 @@ class unit_test(object):
|
|||
)
|
||||
print_info('test/ref/*rawtx','MMGen reference transactions')
|
||||
g.rpc_port = None
|
||||
for n,(coin,tn,fn) in enumerate(fns):
|
||||
proto = init_coin(coin,tn)
|
||||
proto.daemon_data_dir = 'test/daemons/' + coin
|
||||
proto.rpc_port = CoinDaemon(coin + ('','_tn')[tn],test_suite=True).rpc_port
|
||||
await rpc_init(proto=proto)
|
||||
for n,(coin,testnet,fn) in enumerate(fns):
|
||||
g.proto = init_proto(coin,testnet=testnet)
|
||||
g.proto.daemon_data_dir = 'test/daemons/' + coin
|
||||
g.proto.rpc_port = CoinDaemon(coin + ('','_tn')[testnet],test_suite=True).rpc_port
|
||||
await rpc_init()
|
||||
await test_tx(MMGenTX(fn).hex,fn,n+1)
|
||||
Msg('OK')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue