def print_summary(signed_txs): if opt.full_summary: bmsg('\nAutosign summary:\n') for tx in signed_txs: init_coin(tx.coin,tx.chain == 'testnet') msg_r(tx.format_view(terse=True)) return body = [] for tx in signed_txs: non_mmgen = [o for o in tx.outputs if not o.mmid] if non_mmgen: body.append((tx,non_mmgen)) if body: bmsg('\nAutosign summary:') fs = '{} {} {}' t_wid,a_wid = 6,44 msg(fs.format('TX ID ','Non-MMGen outputs'+' '*(a_wid-17),'Amount')) msg(fs.format('-'*t_wid, '-'*a_wid, '-'*7)) for tx,non_mmgen in body: for nm in non_mmgen: msg(fs.format( tx.txid.fmt(width=t_wid,color=True) if nm is non_mmgen[0] else ' '*t_wid, nm.addr.fmt(width=a_wid,color=True), nm._amt.hl() + ' ' + yellow(tx.coin))) else: msg('No non-MMGen outputs')
def ref_altcoin_tx_chk(self): self.write_to_tmpfile(pwfile,dfl_wpasswd) pf = joinpath(self.tmpdir,pwfile) from mmgen.protocol import init_coin for k in ('bch','eth','mm1','etc'): coin,token = ('eth','mm1') if k == 'mm1' else (k,None) ref_subdir = self._get_ref_subdir_by_coin(coin) for tn in (False,True): if tn and coin == 'etc': continue g.testnet = tn init_coin(coin) fn = TestSuiteRef.sources['ref_tx_file'][token or coin][bool(tn)] tf = joinpath(ref_dir,ref_subdir,fn) wf = dfl_words_file e = ['--coin='+coin,'--testnet='+('0','1')[tn]] if token: e += ['--token='+token] t = self.txsign(tf, wf, pf, save = False, has_label = True, do_passwd = False, extra_desc = '({}{})'.format(token or coin,' testnet' if tn else ''), extra_opts = e ) ok_msg() g.testnet = False init_coin('btc') t.skip_ok = True return t
def process_wallets(): m = { 'create': ('Creat', 'Generat', create, False), 'sync': ('Sync', 'Sync', sync, True) } opt.accept_defaults = opt.accept_defaults or m[op][3] from mmgen.protocol import init_coin init_coin('xmr') from mmgen.addr import AddrList al = KeyAddrList(infile) data = [ d for d in al.data if addrs == None or d.idx in AddrIdxList(addrs) ] dl = len(data) assert dl, "No addresses in addrfile within range '{}'".format(addrs) gmsg('\n{}ing {} wallet{}'.format(m[op][0], dl, suf(dl))) for n, d in enumerate( data): # [d.sec,d.wallet_passwd,d.viewkey,d.addr] fn = os.path.join( opt.outdir or u'', u'{}-{}-MoneroWallet{}'.format(al.al_id.sid, d.idx, u'-α' if g.debug_utf8 else '')) gmsg(u'\n{}ing wallet {}/{} ({})'.format(m[op][1], n + 1, dl, fn)) m[op][2](n, d, fn) gmsg('\n{} wallet{} {}ed'.format(dl, suf(dl), m[op][0].lower())) if op == 'sync': msg('Balance: {:.12f}, Unlocked balance: {:.12f}'.format(*bals))
def process_wallets(): m = { 'create': ('Creat','Generat',create,False), 'sync': ('Sync', 'Sync', sync, True) } opt.accept_defaults = opt.accept_defaults or m[op][3] from mmgen.protocol import init_coin init_coin('xmr') from mmgen.addr import AddrList al = KeyAddrList(infile) data = [d for d in al.data if addrs == '' or d.idx in AddrIdxList(addrs)] dl = len(data) assert dl,"No addresses in addrfile within range '{}'".format(addrs) gmsg('\n{}ing {} wallet{}'.format(m[op][0],dl,suf(dl))) for n,d in enumerate(data): # [d.sec,d.wallet_passwd,d.viewkey,d.addr] fn = os.path.join( opt.outdir or '','{}-{}-MoneroWallet{}'.format( al.al_id.sid, d.idx, '-α' if g.debug_utf8 else '')) gmsg('\n{}ing wallet {}/{} ({})'.format(m[op][1],n+1,dl,fn)) m[op][2](n,d,fn) gmsg('\n{} wallet{} {}ed'.format(dl,suf(dl),m[op][0].lower())) if op == 'sync': col1_w = max(map(len,bals)) + 1 fs = '{:%s} {} {}' % col1_w msg('\n'+fs.format('Wallet','Balance ','Unlocked Balance ')) from mmgen.obj import XMRAmt tbals = [XMRAmt('0'),XMRAmt('0')] for bal in bals: for i in (0,1): tbals[i] += bals[bal][i] msg(fs.format(bal+':',*[XMRAmt(b).fmt(fs='5.12',color=True) for b in bals[bal]])) msg(fs.format('-'*col1_w,'-'*18,'-'*18)) msg(fs.format('TOTAL:',*[XMRAmt(b).fmt(fs='5.12',color=True) for b in tbals]))
def print_summary(signed_txs): if opt.full_summary: bmsg('\nAutosign summary:\n') for tx in signed_txs: init_coin(tx.coin, tx.chain == 'testnet') msg_r(tx.format_view(terse=True)) return body = [] for tx in signed_txs: non_mmgen = [o for o in tx.outputs if not o.mmid] if non_mmgen: body.append((tx, non_mmgen)) if body: bmsg('\nAutosign summary:') fs = '{} {} {}' t_wid, a_wid = 6, 44 msg( fs.format('TX ID ', 'Non-MMGen outputs' + ' ' * (a_wid - 17), 'Amount')) msg(fs.format('-' * t_wid, '-' * a_wid, '-' * 7)) for tx, non_mmgen in body: for nm in non_mmgen: msg( fs.format( tx.txid.fmt(width=t_wid, color=True) if nm is non_mmgen[0] else ' ' * t_wid, nm.addr.fmt(width=a_wid, color=True), nm._amt.hl() + ' ' + yellow(tx.coin))) else: msg('No non-MMGen outputs')
def ref_altcoin_tx_chk(self): self.write_to_tmpfile(pwfile, dfl_wpasswd) pf = joinpath(self.tmpdir, pwfile) from mmgen.protocol import init_coin for k in ('bch', 'eth', 'mm1', 'etc'): coin, token = ('eth', 'mm1') if k == 'mm1' else (k, None) ref_subdir = self._get_ref_subdir_by_coin(coin) for tn in (False, True): if tn and coin == 'etc': continue g.testnet = tn init_coin(coin) fn = TestSuiteRef.sources['ref_tx_file'][token or coin][bool(tn)] tf = joinpath(ref_dir, ref_subdir, fn) wf = dfl_words_file e = ['--coin=' + coin, '--testnet=' + ('0', '1')[tn]] if token: e += ['--token=' + token] t = self.txsign(tf, wf, pf, save=False, has_label=True, do_passwd=False, extra_desc='({}{})'.format( token or coin, ' testnet' if tn else ''), extra_opts=e) ok_msg() g.testnet = False init_coin('btc') t.skip_ok = True return t
def process_wallets(): m = { 'create': ('Creat','Generat',create,False), 'sync': ('Sync', 'Sync', sync, True) } opt.accept_defaults = opt.accept_defaults or m[op][3] from mmgen.protocol import init_coin init_coin('xmr') from mmgen.addr import AddrList al = KeyAddrList(infile) data = [d for d in al.data if addrs == None or d.idx in AddrIdxList(addrs)] dl = len(data) assert dl,"No addresses in addrfile within range '{}'".format(addrs) gmsg('\n{}ing {} wallet{}'.format(m[op][0],dl,suf(dl))) for n,d in enumerate(data): # [d.sec,d.wallet_passwd,d.viewkey,d.addr] fn = os.path.join( opt.outdir or u'',u'{}-{}-MoneroWallet{}'.format( al.al_id.sid, d.idx, u'-α' if g.debug_utf8 else '')) gmsg(u'\n{}ing wallet {}/{} ({})'.format(m[op][1],n+1,dl,fn)) m[op][2](n,d,fn) gmsg('\n{} wallet{} {}ed'.format(dl,suf(dl),m[op][0].lower())) if op == 'sync': col1_w = max(map(len,bals)) + 1 fs = u'{:%s} {:18} {:18}' % col1_w msg('\n'+fs.format('Wallet',' Balance',' Unlocked Balance')) tbals = [Decimal('0'),Decimal('0')] for bal in bals: for i in (0,1): tbals[i] += bals[bal][i] msg(fs.format(bal+':',*bals[bal])) msg(fs.format('-'*col1_w,'-'*18,'-'*18)) msg(fs.format('TOTAL:',*tbals))
def sign_tx_file(txfile): try: init_coin(mmgen.tx.MMGenTX(txfile, coin_sym_only=True).coin) reload(sys.modules['mmgen.tx']) tx = mmgen.tx.MMGenTX(txfile) if tx.coin not in no_daemon_coins: rpc_init(reinit=True) txsign(tx, wfs, None, None) tx.write_to_file(ask_write=False) return True except: return False
def test_mmgen_txs(): fns = ( ('btc',False,'test/ref/0B8D5A[15.31789,14,tl=1320969600].rawtx'), ('btc',True,'test/ref/0C7115[15.86255,14,tl=1320969600].testnet.rawtx'), ('bch',False,'test/ref/460D4D-BCH[10.19764,tl=1320969600].rawtx') ) from mmgen.protocol import init_coin from mmgen.tx import MMGenTX print_info('test/ref/*rawtx','MMGen reference transactions') for n,(coin,tn,fn) in enumerate(fns): init_coin(coin,tn) rpc_init(reinit=True) test_tx(MMGenTX(fn).hex,fn,n+1) init_coin('btc',False) rpc_init(reinit=True) Msg('OK')
def init_external_prog(): global b, b_desc, ext_lib, ext_sec2addr, sp, eth, addr_type def test_support(k): if b == k: return True if b != 'ext' and b != k: return False if g.coin in ci.external_tests['mainnet'][k] and not g.testnet: return True if g.coin in ci.external_tests['testnet'][k]: return True return False if b == 'zcash_mini' or addr_type.name == 'zcash_z': import subprocess as sp from mmgen.protocol import init_coin ext_sec2addr = zcash_mini_sec2addr ext_lib = 'zcash_mini' init_coin('zec') addr_type = MMGenAddrType('Z') elif test_support('pyethereum'): try: import mmgen.altcoins.eth.pyethereum.utils as eth except: raise ImportError( "Unable to import 'ethereum' module. Is pyethereum installed?") ext_sec2addr = pyethereum_sec2addr ext_lib = 'pyethereum' elif test_support('pycoin'): try: global pcku, secp256k1_generator, network_for_netcode import pycoin.cmds.ku as pcku from pycoin.ecdsa.secp256k1 import secp256k1_generator from pycoin.networks.registry import network_for_netcode except: raise ImportError( "Unable to import pycoin modules. Is pycoin installed and up-to-date?" ) ext_sec2addr = pycoin_sec2addr ext_lib = 'pycoin' elif test_support('keyconv'): import subprocess as sp ext_sec2addr = keyconv_sec2addr ext_lib = 'keyconv' else: m = '{}: coin supported by MMGen but unsupported by gentest.py for {}' raise ValueError(m.format(g.coin, ('mainnet', 'testnet')[g.testnet])) b_desc = ext_lib b = 'ext'
def test_mmgen_txs(): fns = ( ('btc', False, 'test/ref/0B8D5A[15.31789,14,tl=1320969600].rawtx'), ('btc', True, 'test/ref/0C7115[15.86255,14,tl=1320969600].testnet.rawtx'), ('bch', False, 'test/ref/460D4D-BCH[10.19764,tl=1320969600].rawtx')) from mmgen.protocol import init_coin from mmgen.tx import MMGenTX print_info('test/ref/*rawtx', 'MMGen reference transactions') for n, (coin, tn, fn) in enumerate(fns): init_coin(coin, tn) rpc_init(reinit=True) test_tx(MMGenTX(fn).hex, fn, n + 1) init_coin('btc', False) rpc_init(reinit=True) Msg('OK')
def init_external_prog(): global b,b_desc,ext_lib,ext_sec2addr,sp,eth,addr_type def test_support(k): if b == k: return True if b != 'ext' and b != k: return False if g.coin in ci.external_tests['mainnet'][k] and not g.testnet: return True if g.coin in ci.external_tests['testnet'][k]: return True return False if b == 'zcash_mini' or addr_type.name == 'zcash_z': import subprocess as sp from mmgen.protocol import init_coin ext_sec2addr = zcash_mini_sec2addr ext_lib = 'zcash_mini' init_coin('zec') addr_type = MMGenAddrType('Z') elif test_support('pyethereum'): try: import mmgen.altcoins.eth.pyethereum.utils as eth except: raise ImportError("Unable to import 'ethereum' module. Is pyethereum installed?") ext_sec2addr = pyethereum_sec2addr ext_lib = 'pyethereum' elif test_support('pycoin'): try: global pcku,secp256k1_generator,network_for_netcode import pycoin.cmds.ku as pcku from pycoin.ecdsa.secp256k1 import secp256k1_generator from pycoin.networks.registry import network_for_netcode except: raise ImportError("Unable to import pycoin modules. Is pycoin installed and up-to-date?") ext_sec2addr = pycoin_sec2addr ext_lib = 'pycoin' elif test_support('keyconv'): import subprocess as sp ext_sec2addr = keyconv_sec2addr ext_lib = 'keyconv' else: m = '{}: coin supported by MMGen but unsupported by gentest.py for {}' raise ValueError(m.format(g.coin,('mainnet','testnet')[g.testnet])) b_desc = ext_lib b = 'ext'
def sign_tx_file(txfile): try: g.testnet = False g.coin = 'BTC' tmp_tx = mmgen.tx.MMGenTX(txfile, metadata_only=True) init_coin(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): g.testnet = True init_coin(tmp_tx.coin) if hasattr(g.proto, 'chain_name'): m = 'Chains do not match! tx file: {}, proto: {}' assert tmp_tx.chain == g.proto.chain_name, m.format( tmp_tx.chain, g.proto.chain_name) g.chain = tmp_tx.chain g.token = tmp_tx.dcoin g.dcoin = tmp_tx.dcoin or g.coin reload(sys.modules['mmgen.tx']) if g.proto.base_coin == 'ETH': reload(sys.modules['mmgen.altcoins.eth.tx']) tx = mmgen.tx.MMGenTX(txfile) if g.proto.sign_mode == 'daemon': rpc_init(reinit=True) if txsign(tx, wfs, None, None): tx.write_to_file(ask_write=False) return True else: return False except Exception as e: msg(u'An error occurred: {}'.format(e.message)) return False except: return False
def init_external_prog(): global b, b_desc, ext_lib, ext_sec2addr, sp, eth, pcku, PREFIX_TRANSFORMS, addr_type def test_support(k): if b == k: return True if b != 'ext' and b != k: return False if g.coin in ci.external_tests['mainnet'][k] and not g.testnet: return True if g.coin in ci.external_tests['testnet'][k]: return True return False if b == 'zcash_mini' or addr_type.name == 'zcash_z': import subprocess as sp from mmgen.protocol import init_coin ext_sec2addr = zcash_mini_sec2addr ext_lib = 'zcash_mini' init_coin('zec') addr_type = MMGenAddrType('Z') elif test_support('pyethereum'): try: import ethereum.utils as eth except: raise ImportError, "Unable to import 'pyethereum' module. Is pyethereum installed?" ext_sec2addr = pyethereum_sec2addr ext_lib = 'pyethereum' elif test_support('pycoin'): try: import pycoin.cmds.ku as pcku except: raise ImportError, "Unable to import module 'ku'. Is pycoin installed?" PREFIX_TRANSFORMS = pcku.prefix_transforms_for_network(g.coin) ext_sec2addr = pycoin_sec2addr ext_lib = 'pycoin' elif test_support('keyconv'): import subprocess as sp ext_sec2addr = keyconv_sec2addr ext_lib = 'keyconv' else: m = '{}: coin supported by MMGen but unsupported by gentest.py for {}' raise ValueError, m.format(g.coin, ('mainnet', 'testnet')[g.testnet]) b_desc = ext_lib b = 'ext'
def sign_tx_file(txfile, signed_txs): try: g.testnet = False g.coin = 'BTC' tmp_tx = mmgen.tx.MMGenTX(txfile, metadata_only=True) init_coin(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): g.testnet = True init_coin(tmp_tx.coin) if hasattr(g.proto, 'chain_name'): m = 'Chains do not match! tx file: {}, proto: {}' assert tmp_tx.chain == g.proto.chain_name, m.format( tmp_tx.chain, g.proto.chain_name) g.chain = tmp_tx.chain g.token = tmp_tx.dcoin g.dcoin = tmp_tx.dcoin or g.coin tx = mmgen.tx.MMGenTX(txfile) if g.proto.sign_mode == 'daemon': rpc_init(reinit=True) if txsign(tx, wfs, None, None): tx.write_to_file(ask_write=False) signed_txs.append(tx) return True else: return False except Exception as e: msg('An error occurred: {}'.format(e.args[0])) return False except: return False
def init_external_prog(): global b,b_desc,ext_lib,ext_sec2addr,sp,eth,pcku,PREFIX_TRANSFORMS,addr_type def test_support(k): if b == k: return True if b != 'ext' and b != k: return False if g.coin in ci.external_tests['mainnet'][k] and not g.testnet: return True if g.coin in ci.external_tests['testnet'][k]: return True return False if b == 'zcash_mini' or addr_type.name == 'zcash_z': import subprocess as sp from mmgen.protocol import init_coin ext_sec2addr = zcash_mini_sec2addr ext_lib = 'zcash_mini' init_coin('zec') addr_type = MMGenAddrType('Z') elif test_support('pyethereum'): try: import ethereum.utils as eth except: raise ImportError,"Unable to import 'pyethereum' module. Is pyethereum installed?" ext_sec2addr = pyethereum_sec2addr ext_lib = 'pyethereum' elif test_support('pycoin'): try: import pycoin.cmds.ku as pcku except: raise ImportError,"Unable to import module 'ku'. Is pycoin installed?" PREFIX_TRANSFORMS = pcku.prefix_transforms_for_network(g.coin) ext_sec2addr = pycoin_sec2addr ext_lib = 'pycoin' elif test_support('keyconv'): import subprocess as sp ext_sec2addr = keyconv_sec2addr ext_lib = 'keyconv' else: m = '{}: coin supported by MMGen but unsupported by gentest.py for {}' raise ValueError,m.format(g.coin,('mainnet','testnet')[g.testnet]) b_desc = ext_lib b = 'ext'
def sign_tx_file(txfile,signed_txs): try: g.testnet = False g.coin = 'BTC' tmp_tx = mmgen.tx.MMGenTX(txfile,metadata_only=True) init_coin(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): g.testnet = True init_coin(tmp_tx.coin) if hasattr(g.proto,'chain_name'): m = 'Chains do not match! tx file: {}, proto: {}' assert tmp_tx.chain == g.proto.chain_name,m.format(tmp_tx.chain,g.proto.chain_name) g.chain = tmp_tx.chain g.token = tmp_tx.dcoin g.dcoin = tmp_tx.dcoin or g.coin tx = mmgen.tx.MMGenTX(txfile) if g.proto.sign_mode == 'daemon': rpc_init(reinit=True) if txsign(tx,wfs,None,None): tx.write_to_file(ask_write=False) signed_txs.append(tx) return True else: return False except Exception as e: msg('An error occurred: {}'.format(e.args[0])) return False except: return False
from mmgen.obj import MMGenID try: mmids = [MMGenID(a,on_fail='die') for a in cmd_args] except: die(1,'Command line arguments must be valid MMGen IDs') if mmids[0] == mmids[1]: die(2,'Both transactions have the same output! ({})'.format(mmids[0])) from mmgen.tx import MMGenSplitTX from mmgen.protocol import init_coin if opt.tx_fees: for idx,g_coin in ((1,opt.other_coin),(0,g.coin)): init_coin(g_coin) opt.tx_fee = opt.tx_fees.split(',')[idx] opts.opt_is_tx_fee(opt.tx_fee,'transaction fee') or sys.exit(1) rpc_init(reinit=True) tx1 = MMGenSplitTX() opt.no_blank = True gmsg("Creating timelocked transaction for long chain ({})".format(g.coin)) locktime = int(opt.locktime or 0) or g.rpch.getblockcount() tx1.create(mmids[0],locktime) tx1.format() tx1.create_fn()
die(1,'{}\n{}: invalid generator argument'.format(e[0],cmd_args[0])) from mmgen.addr import KeyGenerator,AddrGenerator from mmgen.obj import PrivKey kg_a = KeyGenerator(addr_type,a) ag = AddrGenerator(addr_type) if a and b: if opt.all: from mmgen.protocol import init_coin,init_genonly_altcoins,CoinProtocol init_genonly_altcoins('btc',trust_level=0) mmgen_supported = CoinProtocol.get_valid_coins(upcase=True) for coin in ci.external_tests[('mainnet','testnet')[g.testnet]][ext_lib]: if coin not in mmgen_supported: continue init_coin(coin) tmp_addr_type = addr_type if addr_type in g.proto.mmtypes else MMGenAddrType(g.proto.dfl_mmtype) kg_a = KeyGenerator(tmp_addr_type,a) ag = AddrGenerator(tmp_addr_type) compare_test() else: if b != 'ext': kg_b = KeyGenerator(addr_type,b) b_desc = kg_b.desc compare_test() elif a and not fh: speed_test() elif a and dump: b_desc = 'dump' dump_test() else:
-v, --verbose Produce more verbose output """ } cmd_args = opts.init(opts_data) if g.coin != 'BTC': die(1, "This program must be run with --coin set to 'BTC'") if len(cmd_args) != 1: opts.usage() import mmgen.tx 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') reload(sys.modules['mmgen.tx']) if opt.verbose: gmsg('Converting transaction to {} format'.format(g.coin)) tx.inputs.convert_coin(verbose=opt.verbose) tx.outputs.convert_coin(verbose=opt.verbose) tx.desc = 'converted transaction' tx.write_to_file(ask_write=False, ask_overwrite=False)
from mmgen.obj import MMGenID try: mmids = [MMGenID(a, on_fail='die') for a in cmd_args] except: die(1, 'Command line arguments must be valid MMGen IDs') if mmids[0] == mmids[1]: die(2, 'Both transactions have the same output! ({})'.format(mmids[0])) from mmgen.tx import MMGenSplitTX from mmgen.protocol import init_coin if opt.tx_fees: for idx, g_coin in ((1, opt.other_coin), (0, g.coin)): init_coin(g_coin) opt.tx_fee = opt.tx_fees.split(',')[idx] opts.opt_is_tx_fee(opt.tx_fee, 'transaction fee') or sys.exit(1) rpc_init(reinit=True) tx1 = MMGenSplitTX() opt.no_blank = True gmsg("Creating timelocked transaction for long chain ({})".format(g.coin)) locktime = int(opt.locktime or 0) or g.rpch.getblockcount() tx1.create(mmids[0], locktime) tx1.format() tx1.create_fn()
def Keyaddrlist2monerowallet(infile,blockheight=None): import pexpect if blockheight != None and int(blockheight) < 0: blockheight = 0 def run_cmd(cmd): import subprocess as sp p = sp.Popen(cmd,stdin=sp.PIPE,stdout=sp.PIPE,stderr=sp.PIPE) return p def test_rpc(): p = run_cmd(['monero-wallet-cli','--version']) if p.stdout.read()[:6] != 'Monero': die(1,"Unable to run 'monero-wallet-cli'!") p = run_cmd(['monerod','status']) ret = p.stdout.read() if ret[:7] != 'Height:': die(1,'Unable to connect to monerod!') return int(ret[8:].split('/')[0]) cur_height = test_rpc() from mmgen.protocol import init_coin init_coin('xmr') from mmgen.addr import AddrList al = KeyAddrList(infile) sid = al.al_id.sid os.environ['LANG'] = 'C' def my_expect(p,m,s,regex=False): if m: msg_r(' {}...'.format(m)) ret = (p.expect_exact,p.expect)[regex](s) if not (ret == 0 or (type(s) == list and ret in (0,1))): die(2,"Expect failed: '{}' (return value: {})".format(s,ret)) if m: msg('OK') return ret def my_sendline(p,m,s,usr_ret): if m: msg_r(' {}...'.format(m)) ret = p.sendline(s) if ret != usr_ret: die(2,"Unable to send line '{}' (return value {})".format(s,ret)) if m: msg('OK') vmsg("sendline: '{}' => {}".format(s,ret)) def create(): gmsg('\nCreating {} wallet{}'.format(dl,suf(dl))) for n,d in enumerate(al.data): fn = '{}{}-{}-MoneroWallet'.format( (opt.outdir+'/' if opt.outdir else ''), sid,d.idx) gmsg("\nGenerating wallet {}/{} ({})".format(n+1,dl,fn)) try: os.stat(fn) except: pass else: die(1,"Wallet '{}' already exists!".format(fn)) # pmsg([d.sec,d.wallet_passwd,d.viewkey,d.addr,fn]) p = pexpect.spawn('monero-wallet-cli --generate-from-spend-key {}'.format(fn)) my_expect(p,'Awaiting initial prompt','Secret spend key: ') my_sendline(p,'',d.sec,65) my_expect(p,'','Enter new wallet password: '******'Sending password',d.wallet_passwd,33) my_expect(p,'','Confirm password: '******'Sending password again',d.wallet_passwd,33) my_expect(p,'','of your choice: ') my_sendline(p,'','1',2) my_expect(p,'monerod generating wallet','Generated new wallet: ') my_expect(p,'','\n') if d.addr not in p.before: die(3,'Addresses do not match!\n MMGen: {}\n Monero: {}'.format(d.addr,p.before)) my_expect(p,'','View key: ') my_expect(p,'','\n') if d.viewkey not in p.before: die(3,'View keys do not match!\n MMGen: {}\n Monero: {}'.format(d.viewkey,p.before)) my_expect(p,'','(YYYY-MM-DD): ') h = str(blockheight or cur_height-1) my_sendline(p,'',h,len(h)+1) ret = my_expect(p,'',['Starting refresh','Still apply restore height? (Y/Yes/N/No): ']) if ret == 1: my_sendline(p,'','Y',2) m = ' Warning: {}: blockheight argument is higher than current blockheight' ymsg(m.format(blockheight)) elif blockheight != None: p.logfile = sys.stderr my_expect(p,'Syncing wallet','\[wallet.*$',regex=True) p.logfile = None my_sendline(p,'Exiting','exit',5) p.read() dl = len(al.data) try: create() gmsg('\n{} wallet{} created'.format(dl,suf(dl))) except KeyboardInterrupt: rdie(1,'\nUser interrupt\n') except EOFError: rdie(2,'\nEnd of file\n') except Exception as e: rdie(1,'Program died: {!r}'.format(e))
--, --longhelp Print help message for long options (common options) -v, --verbose Produce more verbose output """ } } cmd_args = opts.init(opts_data) if g.coin != 'BTC': die(1,"This program must be run with --coin set to 'BTC'") if len(cmd_args) != 1: opts.usage() import mmgen.tx 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') if opt.verbose: gmsg('Converting transaction to {} format'.format(g.coin)) tx.inputs.convert_coin(verbose=opt.verbose) tx.outputs.convert_coin(verbose=opt.verbose) tx.desc = 'converted transaction' tx.write_to_file(ask_write=False,ask_overwrite=False)
from mmgen.addr import KeyGenerator, AddrGenerator from mmgen.obj import PrivKey kg_a = KeyGenerator(addr_type, a) ag = AddrGenerator(addr_type) if a and b: if opt.all: from mmgen.protocol import init_coin, init_genonly_altcoins, CoinProtocol init_genonly_altcoins('btc', trust_level=0) mmgen_supported = CoinProtocol.get_valid_coins(upcase=True) for coin in ci.external_tests[('mainnet', 'testnet')[g.testnet]][ext_lib]: if coin not in mmgen_supported: continue init_coin(coin) tmp_addr_type = addr_type if addr_type in g.proto.mmtypes else MMGenAddrType( g.proto.dfl_mmtype) kg_a = KeyGenerator(tmp_addr_type, a) ag = AddrGenerator(tmp_addr_type) compare_test() else: if b != 'ext': kg_b = KeyGenerator(addr_type, b) b_desc = kg_b.desc compare_test() elif a and not fh: speed_test() elif a and dump: b_desc = 'dump' dump_test()