Esempio n. 1
0
    def add_label(self,
                  arg1,
                  label='',
                  addr=None,
                  silent=False,
                  on_fail='return'):
        from mmgen.tx import is_mmgen_id, is_coin_addr
        mmaddr, coinaddr = None, None
        if is_coin_addr(addr or arg1):
            coinaddr = CoinAddr(addr or arg1, on_fail='return')
        if is_mmgen_id(arg1):
            mmaddr = TwMMGenID(arg1)

        if mmaddr and not coinaddr:
            from mmgen.addr import AddrData
            coinaddr = AddrData(source='tw').mmaddr2coinaddr(mmaddr)

        try:
            if not is_mmgen_id(arg1):
                assert coinaddr, u"Invalid coin address for this chain: {}".format(
                    arg1)
            assert coinaddr, u"{pn} address '{ma}' not found in tracking wallet"
            assert self.is_in_wallet(
                coinaddr), u"Address '{ca}' not found in tracking wallet"
        except Exception as e:
            msg(e.message.format(pn=g.proj_name, ma=mmaddr, ca=coinaddr))
            return False

        # Allow for the possibility that BTC addr of MMGen addr was entered.
        # Do reverse lookup, so that MMGen addr will not be marked as non-MMGen.
        if not mmaddr:
            from mmgen.addr import AddrData
            mmaddr = AddrData(source='tw').coinaddr2mmaddr(coinaddr)

        if not mmaddr:
            mmaddr = '{}:{}'.format(g.proto.base_coin.lower(), coinaddr)

        mmaddr = TwMMGenID(mmaddr)

        cmt = TwComment(label, on_fail=on_fail)
        if cmt in (False, None): return False

        lbl = TwLabel(mmaddr + ('', ' ' + cmt)[bool(cmt)], on_fail=on_fail)

        ret = self.set_label(coinaddr, lbl)

        from mmgen.rpc import rpc_error, rpc_errmsg
        if rpc_error(ret):
            msg('From {}: {}'.format(g.proto.daemon_name, rpc_errmsg(ret)))
            if not silent:
                msg('Label could not be {}'.format(
                    ('removed', 'added')[bool(label)]))
            return False
        else:
            m = mmaddr.type.replace('mmg', 'MMG')
            a = mmaddr.replace(g.proto.base_coin.lower() + ':', '')
            s = '{} address {} in tracking wallet'.format(m, a)
            if label: msg(u"Added label '{}' to {}".format(label, s))
            else: msg(u'Removed label from {}'.format(s))
            return True
Esempio n. 2
0
def get_outputs_from_cmdline(cmd_args, tx):
    from mmgen.addr import AddrList, AddrData
    addrfiles = [a for a in cmd_args if get_extension(a) == AddrList.ext]
    cmd_args = set(cmd_args) - set(addrfiles)

    ad_f = AddrData()
    for a in addrfiles:
        check_infile(a)
        ad_f.add(AddrList(a))

    ad_w = AddrData(source='tw')

    for a in cmd_args:
        if ',' in a:
            a1, a2 = a.split(',', 1)
            if is_mmgen_id(a1) or is_btc_addr(a1):
                btc_addr = mmaddr2baddr(
                    c, a1, ad_w, ad_f) if is_mmgen_id(a1) else BTCAddr(a1)
                tx.add_output(btc_addr, BTCAmt(a2))
            else:
                die(2,
                    "%s: unrecognized subargument in argument '%s'" % (a1, a))
        elif is_mmgen_id(a) or is_btc_addr(a):
            if tx.get_chg_output_idx() != None:
                die(
                    2,
                    'ERROR: More than one change address listed on command line'
                )
            btc_addr = mmaddr2baddr(c, a, ad_w,
                                    ad_f) if is_mmgen_id(a) else BTCAddr(a)
            tx.add_output(btc_addr, BTCAmt('0'), is_chg=True)
        else:
            die(2, '%s: unrecognized argument' % a)

    if not tx.outputs:
        die(2, 'At least one output must be specified on the command line')

    if tx.get_chg_output_idx() == None:
        die(2, ('ERROR: No change output specified',
                wmsg['no_change_output'])[len(tx.outputs) == 1])

    tx.add_mmaddrs_to_outputs(ad_w, ad_f)

    if not segwit_is_active() and tx.has_segwit_outputs():
        fs = '{} Segwit address requested on the command line, but Segwit is not active on this chain'
        rdie(2, fs.format(g.proj_name))
Esempio n. 3
0
File: tx.py Progetto: voidp34r/mmgen
	def get_outputs_from_cmdline(self,cmd_args):
		from mmgen.addr import AddrList,AddrData
		addrfiles = [a for a in cmd_args if get_extension(a) == AddrList.ext]
		cmd_args = set(cmd_args) - set(addrfiles)

		ad_f = AddrData()
		for a in addrfiles:
			check_infile(a)
			ad_f.add(AddrList(a))

		ad_w = AddrData(source='tw')

		for a in cmd_args:
			if ',' in a:
				a1,a2 = a.split(',',1)
				if is_mmgen_id(a1) or is_coin_addr(a1):
					coin_addr = mmaddr2coinaddr(a1,ad_w,ad_f) if is_mmgen_id(a1) else CoinAddr(a1)
					self.add_output(coin_addr,g.proto.coin_amt(a2))
				else:
					die(2,"{}: invalid subargument in command-line argument '{}'".format(a1,a))
			elif is_mmgen_id(a) or is_coin_addr(a):
				if self.get_chg_output_idx() != None:
					die(2,'ERROR: More than one change address listed on command line')
				coin_addr = mmaddr2coinaddr(a,ad_w,ad_f) if is_mmgen_id(a) else CoinAddr(a)
				self.add_output(coin_addr,g.proto.coin_amt('0'),is_chg=True)
			else:
				die(2,'{}: invalid command-line argument'.format(a))

		if not self.outputs:
			die(2,'At least one output must be specified on the command line')

		if self.get_chg_output_idx() == None:
			die(2,('ERROR: No change output specified',wmsg['no_change_output'])[len(self.outputs) == 1])

		self.add_mmaddrs_to_outputs(ad_w,ad_f)
		self.check_dup_addrs('outputs')

		if not segwit_is_active() and self.has_segwit_outputs():
			fs = '{} Segwit address requested on the command line, but Segwit is not active on this chain'
			rdie(2,fs.format(g.proj_name))
Esempio n. 4
0
File: tx.py Progetto: voidp34r/mmgen
	def get_outputs_from_cmdline(self,mmid): # TODO: check that addr is empty

		from mmgen.addr import AddrData
		ad_w = AddrData(source='tw')

		if is_mmgen_id(mmid):
			coin_addr = mmaddr2coinaddr(mmid,ad_w,None) if is_mmgen_id(mmid) else CoinAddr(mmid)
			self.add_output(coin_addr,g.proto.coin_amt('0'),is_chg=True)
		else:
			die(2,'{}: invalid command-line argument'.format(mmid))

		self.add_mmaddrs_to_outputs(ad_w,None)

		if not segwit_is_active() and self.has_segwit_outputs():
			fs = '{} Segwit address requested on the command line, but Segwit is not active on this chain'
			rdie(2,fs.format(g.proj_name))
Esempio n. 5
0
 def _create_tx_data(self, sources, addrs_per_wallet=addrs_per_wallet):
     from mmgen.addr import AddrData, AddrList
     from mmgen.obj import AddrIdxList
     tx_data, ad = {}, AddrData()
     for s in sources:
         afile = get_file_with_ext(self.cfgs[s]['tmpdir'], 'addrs')
         al = AddrList(afile)
         ad.add(al)
         aix = AddrIdxList(fmt_str=self.cfgs[s]['addr_idx_list'])
         if len(aix) != addrs_per_wallet:
             raise TestSuiteFatalException(
                 'Address index list length != {}: {}'.format(
                     addrs_per_wallet, repr(aix)))
         tx_data[s] = {
             'addrfile': afile,
             'chk': al.chksum,
             'al_id': al.al_id,
             'addr_idxs': aix[-2:],
             'segwit': self.cfgs[s]['segwit']
         }
     return ad, tx_data
Esempio n. 6
0
    def add_label(cls, arg1, label='', addr=None, silent=False):
        from mmgen.tx import is_mmgen_id, is_btc_addr
        mmaddr, btcaddr = None, None
        if is_btc_addr(addr or arg1):
            btcaddr = BTCAddr(addr or arg1, on_fail='return')
        if is_mmgen_id(arg1):
            mmaddr = TwMMGenID(arg1)

        if not btcaddr and not mmaddr:
            msg("Address '{}' invalid or not found in tracking wallet".format(
                addr or arg1))
            return False

        if not btcaddr:
            from mmgen.addr import AddrData
            btcaddr = AddrData(source='tw').mmaddr2btcaddr(mmaddr)

        if not btcaddr:
            msg("{} address '{}' not found in tracking wallet".format(
                g.proj_name, mmaddr))
            return False

        # Checked that the user isn't importing a random address
        if not btcaddr.is_in_tracking_wallet():
            msg("Address '{}' not in tracking wallet".format(btcaddr))
            return False

        c = rpc_connection()
        if not btcaddr.is_for_current_chain():
            msg("Address '{}' not valid for chain {}".format(
                btcaddr, g.chain.upper()))
            return False

        # Allow for the possibility that BTC addr of MMGen addr was entered.
        # Do reverse lookup, so that MMGen addr will not be marked as non-MMGen.
        if not mmaddr:
            from mmgen.addr import AddrData
            ad = AddrData(source='tw')
            mmaddr = ad.btcaddr2mmaddr(btcaddr)

        if not mmaddr: mmaddr = 'btc:' + btcaddr

        mmaddr = TwMMGenID(mmaddr)

        cmt = TwComment(label, on_fail='return')
        if cmt in (False, None): return False

        lbl = TwLabel(mmaddr +
                      ('', ' ' + cmt)[bool(cmt)])  # label is ASCII for now

        # NOTE: this works because importaddress() removes the old account before
        # associating the new account with the address.
        # Will be replaced by setlabel() with new RPC label API
        # RPC args: addr,label,rescan[=true],p2sh[=none]
        ret = c.importaddress(btcaddr, lbl, False, on_fail='return')

        from mmgen.rpc import rpc_error, rpc_errmsg
        if rpc_error(ret):
            msg('From bitcoind: ' + rpc_errmsg(ret))
            if not silent:
                msg('Label could not be {}'.format(
                    ('removed', 'added')[bool(label)]))
            return False
        else:
            m = mmaddr.type.replace('mmg', 'MMG')
            a = mmaddr.replace('btc:', '')
            s = '{} address {} in tracking wallet'.format(m, a)
            if label: msg("Added label '{}' to {}".format(label, s))
            else: msg('Removed label from {}'.format(s))
            return True
Esempio n. 7
0
    def add_label(cls,
                  arg1,
                  label='',
                  addr=None,
                  silent=False,
                  on_fail='return'):
        from mmgen.tx import is_mmgen_id, is_coin_addr
        mmaddr, coinaddr = None, None
        if is_coin_addr(addr or arg1):
            coinaddr = CoinAddr(addr or arg1, on_fail='return')
        if is_mmgen_id(arg1):
            mmaddr = TwMMGenID(arg1)

        if mmaddr and not coinaddr:
            from mmgen.addr import AddrData
            coinaddr = AddrData(source='tw').mmaddr2coinaddr(mmaddr)

        try:
            if not is_mmgen_id(arg1):
                assert coinaddr, "Invalid coin address for this chain: {}".format(
                    arg1)
            assert coinaddr, "{pn} address '{ma}' not found in tracking wallet"
            assert coinaddr.is_in_tracking_wallet(
            ), "Address '{ca}' not found in tracking wallet"
        except Exception as e:
            msg(e[0].format(pn=g.proj_name, ma=mmaddr, ca=coinaddr))
            return False

        # Allow for the possibility that BTC addr of MMGen addr was entered.
        # Do reverse lookup, so that MMGen addr will not be marked as non-MMGen.
        if not mmaddr:
            from mmgen.addr import AddrData
            mmaddr = AddrData(source='tw').coinaddr2mmaddr(coinaddr)

        if not mmaddr:
            mmaddr = '{}:{}'.format(g.proto.base_coin.lower(), coinaddr)

        mmaddr = TwMMGenID(mmaddr)

        cmt = TwComment(label, on_fail=on_fail)
        if cmt in (False, None): return False

        lbl = TwLabel(mmaddr + ('', ' ' + cmt)[bool(cmt)], on_fail=on_fail)

        # NOTE: this works because importaddress() removes the old account before
        # associating the new account with the address.
        # Will be replaced by setlabel() with new RPC label API
        # RPC args: addr,label,rescan[=true],p2sh[=none]
        ret = g.rpch.importaddress(coinaddr, lbl, False, on_fail='return')

        from mmgen.rpc import rpc_error, rpc_errmsg
        if rpc_error(ret):
            msg('From {}: {}'.format(g.proto.daemon_name, rpc_errmsg(ret)))
            if not silent:
                msg('Label could not be {}'.format(
                    ('removed', 'added')[bool(label)]))
            return False
        else:
            m = mmaddr.type.replace('mmg', 'MMG')
            a = mmaddr.replace(g.proto.base_coin.lower() + ':', '')
            s = '{} address {} in tracking wallet'.format(m, a)
            if label: msg(u"Added label '{}' to {}".format(label, s))
            else: msg(u'Removed label from {}'.format(s))
            return True
Esempio n. 8
0
	def add_label(cls,arg1,label='',addr=None,silent=False):
		from mmgen.tx import is_mmgen_id,is_coin_addr
		mmaddr,coinaddr = None,None
		if is_coin_addr(addr or arg1):
			coinaddr = CoinAddr(addr or arg1,on_fail='return')
		if is_mmgen_id(arg1):
			mmaddr = TwMMGenID(arg1)

		if not coinaddr and not mmaddr:
			msg("Address '{}' invalid or not found in tracking wallet".format(addr or arg1))
			return False

		if not coinaddr:
			from mmgen.addr import AddrData
			coinaddr = AddrData(source='tw').mmaddr2coinaddr(mmaddr)

		if not coinaddr:
			msg("{} address '{}' not found in tracking wallet".format(g.proj_name,mmaddr))
			return False

		# Checked that the user isn't importing a random address
		if not coinaddr.is_in_tracking_wallet():
			msg("Address '{}' not in tracking wallet".format(coinaddr))
			return False

		if not coinaddr.is_for_chain(g.chain):
			msg("Address '{}' not valid for chain {}".format(coinaddr,g.chain.upper()))
			return False

		# Allow for the possibility that BTC addr of MMGen addr was entered.
		# Do reverse lookup, so that MMGen addr will not be marked as non-MMGen.
		if not mmaddr:
			from mmgen.addr import AddrData
			ad = AddrData(source='tw')
			mmaddr = ad.coinaddr2mmaddr(coinaddr)

		if not mmaddr: mmaddr = '{}:{}'.format(g.proto.base_coin.lower(),coinaddr)

		mmaddr = TwMMGenID(mmaddr)

		cmt = TwComment(label,on_fail='return')
		if cmt in (False,None): return False

		lbl = TwLabel(mmaddr + ('',' '+cmt)[bool(cmt)]) # label is ASCII for now

		# NOTE: this works because importaddress() removes the old account before
		# associating the new account with the address.
		# Will be replaced by setlabel() with new RPC label API
		# RPC args: addr,label,rescan[=true],p2sh[=none]
		ret = g.rpch.importaddress(coinaddr,lbl,False,on_fail='return')

		from mmgen.rpc import rpc_error,rpc_errmsg
		if rpc_error(ret):
			msg('From {}: {}'.format(g.proto.daemon_name,rpc_errmsg(ret)))
			if not silent:
				msg('Label could not be {}'.format(('removed','added')[bool(label)]))
			return False
		else:
			m = mmaddr.type.replace('mmg','MMG')
			a = mmaddr.replace(g.proto.base_coin.lower()+':','')
			s = '{} address {} in tracking wallet'.format(m,a)
			if label: msg("Added label '{}' to {}".format(label,s))
			else:     msg('Removed label from {}'.format(s))
			return True