Exemplo 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
Exemplo n.º 2
0
Arquivo: tw.py Projeto: mmgen/mmgen
	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,"Invalid coin address for this chain: {}".format(arg1)
			assert coinaddr,"{pn} address '{ma}' not found in tracking wallet"
			assert self.is_in_wallet(coinaddr),"Address '{ca}' not found in tracking wallet"
		except Exception as e:
			msg(e.args[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)

		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("Added label '{}' to {}".format(label,s))
			else:     msg('Removed label from {}'.format(s))
			return True
Exemplo n.º 3
0
def parse_tw_acct_label(s):
	ret = s.split(None,1)
	a1,a2 = None,None
	if ret:
		a1 = ret[0] if is_mmgen_id(ret[0]) else '' if ret[0][:4] == 'btc:' else None
		a2 = ret[1] if len(ret) == 2 else None
	return a1,a2
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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