From edfa94e3bbd2d17bfb2715e3b89ee661dd2d1429 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 13 Mar 2024 12:16:10 +0000 Subject: [PATCH] new `TrackingWalletName` class --- mmgen/obj.py | 6 ++++++ mmgen/proto/btc/rpc.py | 3 ++- test/objtest_py_d/ot_btc_mainnet.py | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mmgen/obj.py b/mmgen/obj.py index 9bc3c6e2..2bd131e8 100755 --- a/mmgen/obj.py +++ b/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' diff --git a/mmgen/proto/btc/rpc.py b/mmgen/proto/btc/rpc.py index 9b87841a..f5de469a 100755 --- a/mmgen/proto/btc/rpc.py +++ b/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, diff --git a/test/objtest_py_d/ot_btc_mainnet.py b/test/objtest_py_d/ot_btc_mainnet.py index 803ca5b7..a94b3b2d 100755 --- a/test/objtest_py_d/ot_btc_mainnet.py +++ b/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',