|
@@ -25,10 +25,9 @@ from collections import namedtuple
|
|
|
|
|
|
from ..globalvars import g
|
|
|
from ..objmethods import Hilite,InitErrors,MMGenObject
|
|
|
-from ..obj import TwComment,get_obj,MMGenIdx,MMGenList
|
|
|
+from ..obj import get_obj,MMGenIdx,MMGenList
|
|
|
from ..color import nocolor,yellow,green,red,blue
|
|
|
from ..util import msg,msg_r,fmt,die,capfirst,make_timestr
|
|
|
-from ..addr import MMGenID
|
|
|
|
|
|
# base class for TwUnspentOutputs,TwAddresses,TwTxHistory:
|
|
|
class TwView:
|
|
@@ -506,68 +505,3 @@ class TwView:
|
|
|
return None
|
|
|
|
|
|
return await do_comment_add(res)
|
|
|
-
|
|
|
-class TwMMGenID(str,Hilite,InitErrors,MMGenObject):
|
|
|
- color = 'orange'
|
|
|
- width = 0
|
|
|
- trunc_ok = False
|
|
|
- def __new__(cls,proto,id_str):
|
|
|
- if type(id_str) == cls:
|
|
|
- return id_str
|
|
|
- try:
|
|
|
- ret = addr = disp = MMGenID(proto,id_str)
|
|
|
- sort_key,idtype = (ret.sort_key,'mmgen')
|
|
|
- except Exception as e:
|
|
|
- try:
|
|
|
- coin,addr = id_str.split(':',1)
|
|
|
- assert coin == proto.base_coin.lower(),(
|
|
|
- f'not a string beginning with the prefix {proto.base_coin.lower()!r}:' )
|
|
|
- assert addr.isascii() and addr.isalnum(), 'not an ASCII alphanumeric string'
|
|
|
- ret,sort_key,idtype,disp = (id_str,'z_'+id_str,'non-mmgen','non-MMGen')
|
|
|
- addr = proto.coin_addr(addr)
|
|
|
- except Exception as e2:
|
|
|
- return cls.init_fail(e,id_str,e2=e2)
|
|
|
-
|
|
|
- me = str.__new__(cls,ret)
|
|
|
- me.obj = ret
|
|
|
- me.disp = disp
|
|
|
- me.addr = addr
|
|
|
- me.sort_key = sort_key
|
|
|
- me.type = idtype
|
|
|
- me.proto = proto
|
|
|
- return me
|
|
|
-
|
|
|
- @classmethod
|
|
|
- def fmtc(cls,twmmid,*args,**kwargs):
|
|
|
- return super().fmtc(twmmid.disp,*args,**kwargs)
|
|
|
-
|
|
|
-# non-displaying container for TwMMGenID,TwComment
|
|
|
-class TwLabel(str,InitErrors,MMGenObject):
|
|
|
- exc = 'BadTwLabel'
|
|
|
- passthru_excs = ('BadTwComment',)
|
|
|
- def __new__(cls,proto,text):
|
|
|
- if type(text) == cls:
|
|
|
- return text
|
|
|
- try:
|
|
|
- ts = text.split(None,1)
|
|
|
- mmid = TwMMGenID(proto,ts[0])
|
|
|
- comment = TwComment(ts[1] if len(ts) == 2 else '')
|
|
|
- me = str.__new__( cls, mmid + (' ' + comment if comment else '') )
|
|
|
- me.mmid = mmid
|
|
|
- me.comment = comment
|
|
|
- me.proto = proto
|
|
|
- return me
|
|
|
- except Exception as e:
|
|
|
- return cls.init_fail(e,text)
|
|
|
-
|
|
|
-def get_tw_label(proto,s):
|
|
|
- """
|
|
|
- raise an exception on a malformed comment, return None on an empty or invalid label
|
|
|
- """
|
|
|
- try:
|
|
|
- return TwLabel(proto,s)
|
|
|
- except Exception as e:
|
|
|
- if type(e).__name__ == 'BadTwComment': # do it this way to avoid importing .exception
|
|
|
- raise
|
|
|
- else:
|
|
|
- return None
|