Browse Source

new `TrackingWalletName` class

The MMGen Project 1 year ago
parent
commit
edfa94e3bb
3 changed files with 14 additions and 2 deletions
  1. 6 0
      mmgen/obj.py
  2. 2 1
      mmgen/proto/btc/rpc.py
  3. 6 1
      test/objtest_py_d/ot_btc_mainnet.py

+ 6 - 0
mmgen/obj.py

@@ -395,6 +395,12 @@ class MMGenWalletLabel(MMGenLabel):
 	max_len = 48
 	desc = 'wallet label'
 
+class TrackingWalletName(MMGenLabel):
+	max_len = 40
+	desc = 'tracking wallet name'
+	allowed = 'abcdefghijklmnopqrstuvwxyz0123456789-_'
+	first_char = 'abcdefghijklmnopqrstuvwxyz0123456789'
+
 class TwComment(MMGenLabel):
 	max_screen_width = 80
 	desc = 'tracking wallet comment'

+ 2 - 1
mmgen/proto/btc/rpc.py

@@ -15,6 +15,7 @@ proto.btc.rpc: Bitcoin base protocol RPC client class
 import os
 
 from ...base_obj import AsyncInit
+from ...obj import TrackingWalletName
 from ...util import ymsg,die,fmt
 from ...fileutil import get_lines_from_file
 from ...rpc import RPCClient,auth_data
@@ -127,7 +128,7 @@ class BitcoinRPCClient(RPCClient,metaclass=AsyncInit):
 		self.proto = proto
 		self.daemon = daemon
 		self.call_sigs = getattr(CallSigs,daemon.id)(cfg)
-		self.twname = cfg.regtest_user or cfg.tw_name or self.dfl_twname
+		self.twname = TrackingWalletName(cfg.regtest_user or cfg.tw_name or self.dfl_twname)
 
 		super().__init__(
 			cfg  = cfg,

+ 6 - 1
test/objtest_py_d/ot_btc_mainnet.py

@@ -9,7 +9,7 @@ test.objtest_py_d.ot_btc_mainnet: BTC mainnet test vectors for MMGen data object
 
 from decimal import Decimal
 
-from mmgen.obj import Int,MMGenTxID,CoinTxID,MMGenWalletLabel,MMGenTxComment,MMGenPWIDString
+from mmgen.obj import Int,MMGenTxID,CoinTxID,MMGenWalletLabel,MMGenTxComment,MMGenPWIDString,TrackingWalletName
 from mmgen.addrlist import AddrIdx,AddrIdxList,AddrListID
 from mmgen.seed import Seed,SeedID
 from mmgen.subseed import SubSeedList,SubSeedIdx,SubSeedIdxRange
@@ -180,6 +180,11 @@ tests = {
 			{'id_str':'F00BAA12:S:9999999', 'proto':proto},
 		),
 	},
+	'TrackingWalletName': {
+		'arg1': 's',
+		'bad':  ('-abcdefg', 'a' * 50, 'abc-α-ω'),
+		'good': ('ab-cd-def_ghi-', '321-abcd')
+	},
 	'TwLabel': {
 		'arg1': 'proto',
 		'exc_name': 'BadTwLabel',