Browse Source

New tool commands: gen_addr, gen_key

- generate a single coin address or key from the specified MMGen ID
MMGen 6 years ago
parent
commit
430292d1da
2 changed files with 21 additions and 0 deletions
  1. 2 0
      mmgen/main_tool.py
  2. 19 0
      mmgen/tool.py

+ 2 - 0
mmgen/main_tool.py

@@ -46,6 +46,8 @@ Cryptocoin address/key operations (compressed public keys supported):
   wif2hex        - convert a private key from WIF to hex format
   wif2hex        - convert a private key from WIF to hex format
 
 
 Wallet/TX operations (coin daemon must be running):
 Wallet/TX operations (coin daemon must be running):
+  gen_addr      - generate a single MMGen address from default or specified wallet
+  gen_key       - generate a single MMGen WIF key from default or specified wallet
   getbalance    - like '{pn}-cli getbalance' but shows confirmed/unconfirmed,
   getbalance    - like '{pn}-cli getbalance' but shows confirmed/unconfirmed,
                   spendable/unspendable balances for individual {pnm} wallets
                   spendable/unspendable balances for individual {pnm} wallets
   listaddress   - list the specified {pnm} address and its balance
   listaddress   - list the specified {pnm} address and its balance

+ 19 - 0
mmgen/tool.py

@@ -77,6 +77,9 @@ cmd_data = OrderedDict([
 	('Mn_stats',     ["wordlist [str='electrum']"]),
 	('Mn_stats',     ["wordlist [str='electrum']"]),
 	('Mn_printlist', ["wordlist [str='electrum']"]),
 	('Mn_printlist', ["wordlist [str='electrum']"]),
 
 
+	('Gen_addr',     ['<{} ID> [str]'.format(pnm),"wallet [str='']"]),
+	('Gen_key',      ['<{} ID> [str]'.format(pnm),"wallet [str='']"]),
+
 	('Listaddress',['<{} address> [str]'.format(pnm),'minconf [int=1]','pager [bool=False]','showempty [bool=True]','showbtcaddr [bool=True]','show_age [bool=False]','show_days [bool=True]']),
 	('Listaddress',['<{} address> [str]'.format(pnm),'minconf [int=1]','pager [bool=False]','showempty [bool=True]','showbtcaddr [bool=True]','show_age [bool=False]','show_days [bool=True]']),
 	('Listaddresses',["addrs [str='']",'minconf [int=1]','showempty [bool=False]','pager [bool=False]','showbtcaddrs [bool=True]','all_labels [bool=False]',"sort [str=''] (options: reverse, age)",'show_age [bool=False]','show_days [bool=True]']),
 	('Listaddresses',["addrs [str='']",'minconf [int=1]','showempty [bool=False]','pager [bool=False]','showbtcaddrs [bool=True]','all_labels [bool=False]',"sort [str=''] (options: reverse, age)",'show_age [bool=False]','show_days [bool=True]']),
 	('Getbalance',   ['minconf [int=1]','quiet [bool=False]','pager [bool=False]']),
 	('Getbalance',   ['minconf [int=1]','quiet [bool=False]','pager [bool=False]']),
@@ -633,6 +636,22 @@ def monero_wallet_ops(infile,op,blockheight=None,addrs=None):
 
 
 # ================ RPC commands ================== #
 # ================ RPC commands ================== #
 
 
+def Gen_addr(addr,wallet='',target='addr'):
+	addr = MMGenID(addr)
+	sf = get_seed_file([wallet] if wallet else [],1)
+	opt.quiet = True
+	from mmgen.seed import SeedSource
+	ss = SeedSource(sf)
+	if ss.seed.sid != addr.sid:
+		m = 'Seed ID of requested address ({}) does not match wallet ({})'
+		die(1,m.format(addr.sid,ss.seed.sid))
+	al = AddrList(seed=ss.seed,addr_idxs=AddrIdxList(str(addr.idx)),mmtype=addr.mmtype,do_chksum=False)
+	d = al.data[0]
+	Msg(d.sec.wif if target=='wif' else d.addr)
+
+def Gen_key(addr,wallet=''):
+	return Gen_addr(addr,wallet,target='wif')
+
 def Listaddress(addr,minconf=1,pager=False,showempty=True,showbtcaddr=True,show_age=False,show_days=None):
 def Listaddress(addr,minconf=1,pager=False,showempty=True,showbtcaddr=True,show_age=False,show_days=None):
 	return Listaddresses(addrs=addr,minconf=minconf,pager=pager,
 	return Listaddresses(addrs=addr,minconf=minconf,pager=pager,
 			showempty=showempty,showbtcaddrs=showbtcaddr,show_age=show_age,show_days=show_days)
 			showempty=showempty,showbtcaddrs=showbtcaddr,show_age=show_age,show_days=show_days)