globalvars.py: new GlobalConstants (gc), GlobalVars (gv) classes

- The attributes of GlobalConstants are non-configurable.  They’re constant
  for a given machine, user, executable and MMGen release.

- The attributes of GlobalVars, `stderr` and `stdout`, are used by the test
  suite to redirect msg() and friends to /dev/null.

- All the aforementioned attributes formerly belonged to GlobalConfig.
This commit is contained in:
The MMGen Project 2023-03-28 18:14:36 +00:00
commit c3ce1ab8e3
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
70 changed files with 309 additions and 282 deletions

View file

@ -74,7 +74,7 @@ class TwAddrData(AddrData,metaclass=AsyncInit):
async def __init__(self,proto,twctl=None):
from .rpc import rpc_init
from .tw.shared import TwLabel
from .globalvars import g
from .globalvars import gc
from .seed import SeedID
self.proto = proto
self.rpc = await rpc_init(proto)
@ -86,7 +86,7 @@ class TwAddrData(AddrData,metaclass=AsyncInit):
if l and l.mmid.type == 'mmgen':
obj = l.mmid.obj
if len(addr_array) != 1:
message = self.msgs['multiple_acct_addrs'].strip().format( acct=acct, proj=g.proj_name )
message = self.msgs['multiple_acct_addrs'].strip().format( acct=acct, proj=gc.proj_name )
die(3, fmt( message, indent=' ' ))
al_id = AddrListID(
sid = SeedID(sid=obj.sid),
@ -96,7 +96,7 @@ class TwAddrData(AddrData,metaclass=AsyncInit):
out[al_id].append(AddrListEntry(self.proto,idx=obj.idx,addr=addr_array[0],comment=l.comment))
i += 1
vmsg(f'{i} {g.proj_name} addresses found, {len(twd)} accounts total')
vmsg(f'{i} {gc.proj_name} addresses found, {len(twd)} accounts total')
for al_id in out:
self.add(AddrList(

View file

@ -87,8 +87,8 @@ class AddrFile(MMGenObject):
self.file_header_mn.format(p.pw_fmt.upper())
if p.gen_passwds and p.pw_fmt in ('bip39','xmrseed') else
self.file_header ).strip()
from .globalvars import g
out = [fh.format(pnm=g.proj_name,n=TwComment.max_screen_width) + '\n']
from .globalvars import gc
out = [fh.format(pnm=gc.proj_name,n=TwComment.max_screen_width) + '\n']
if p.chksum:
out.append(f'# {capfirst(p.desc)} data checksum for {p.id_str}: {p.chksum}')

View file

@ -36,6 +36,8 @@ altcoin.py - Coin constants for Bitcoin-derived altcoins
# NBT: 150/191 c/u, 25/('B'), 26/('B')
import sys
from .globalvars import gc
from .util import msg
def test_equal(desc,a,b,*cdata):
@ -434,10 +436,9 @@ class CoinInfo(object):
@classmethod
def verify_core_coin_data(cls,quiet=False,verbose=False):
from .protocol import CoinProtocol,init_proto
from .globalvars import g
for network in ('mainnet','testnet'):
for coin in g.core_coins:
for coin in gc.core_coins:
e = cls.get_entry(coin,network)
if e:
proto = init_proto(coin,testnet=network=='testnet')
@ -718,8 +719,7 @@ def init_genonly_altcoins(usr_coin=None,testnet=False):
data[network] = CoinInfo.get_supported_coins(network)
trust_level = 0
else:
from .globalvars import g
if usr_coin.lower() in g.core_coins: # core coin, so return immediately
if usr_coin.lower() in gc.core_coins: # core coin, so return immediately
from .protocol import CoinProtocol
return CoinProtocol.coins[usr_coin.lower()].trust_level
for network in networks:

View file

@ -23,7 +23,7 @@ cfgfile: API for the MMGen runtime configuration file and related files
import os,re
from collections import namedtuple
from .globalvars import g
from .globalvars import g,gc
from .util import msg,ymsg,suf,fmt,fmt_list,oneshot_warning,strip_comment,capfirst
def mmgen_cfg_file(id_str):
@ -187,7 +187,7 @@ class CfgFileSampleSys(cfg_file_sample):
else:
# self.fn is used for error msgs only, so file need not exist on filesystem
self.fn = os.path.join(os.path.dirname(__file__),'data',self.fn_base)
self.data = g.get_mmgen_data_file(self.fn_base).splitlines()
self.data = gc.get_mmgen_data_file(self.fn_base).splitlines()
def make_metadata(self):
return [f'# Version {self.cur_ver} {self.computed_chksum}']

View file

@ -47,8 +47,8 @@ def nocolor(s):
def set_vt100():
'hack to put term into VT100 mode under MSWin'
from .globalvars import g
if g.platform == 'win':
from .globalvars import gc
if gc.platform == 'win':
from subprocess import run
run([],shell=True)

View file

@ -23,7 +23,7 @@ crypto: Random number, password hashing and symmetric encryption routines for th
import os
from collections import namedtuple
from .globalvars import g
from .globalvars import g,gc
from .opts import opt
from .util import (
msg,
@ -244,7 +244,7 @@ class Crypto:
avg_prec = sum(len(t.split('.')[1]) for t in time_data) // len(time_data)
if avg_prec < g.min_time_precision:
if avg_prec < gc.min_time_precision:
ymsg(f'WARNING: Avg. time precision of only {avg_prec} decimal points. User entropy quality is degraded!')
ret = key_data + '\n' + '\n'.join(time_data)
@ -300,7 +300,7 @@ class Crypto:
def get_hash_preset_from_user(
self,
old_preset = g.dfl_hash_preset,
old_preset = gc.dfl_hash_preset,
data_desc = 'data',
prompt = None ):
@ -338,7 +338,7 @@ class Crypto:
if opt.echo_passphrase:
pw = ' '.join(get_words_from_user( f'Enter {pw_desc} for {data_desc}: ' ))
else:
for i in range(g.passwd_max_tries):
for i in range(gc.passwd_max_tries):
pw = ' '.join(get_words_from_user( f'Enter {pw_desc} for {data_desc}: ' ))
pw_chk = ' '.join(get_words_from_user( f'Repeat {pw_desc}: ' ))
dmsg(f'Passphrases: [{pw}] [{pw_chk}]')

View file

@ -24,7 +24,7 @@ import os,time,importlib
from subprocess import run,PIPE,CompletedProcess
from collections import namedtuple
from .globalvars import g
from .globalvars import g,gc
from .color import set_vt100
from .util import msg,Msg_r,ymsg,die,remove_dups,oneshot_warning
from .flags import *
@ -51,7 +51,7 @@ class Daemon(Lockable):
def __init__(self,opts=None,flags=None):
self.platform = g.platform
self.platform = gc.platform
if self.platform == 'win':
self.use_pidfile = False
self.use_threads = True
@ -478,7 +478,7 @@ class CoinDaemon(Daemon):
assert self.test_suite, 'datadir removal restricted to test suite'
if self.state == 'stopped':
run([
('rm' if g.platform == 'win' else '/bin/rm'),
('rm' if gc.platform == 'win' else '/bin/rm'),
'-rf',
self.datadir ])
set_vt100()

View file

@ -43,8 +43,8 @@ class File:
import stat
if stat.S_ISBLK(st.st_mode):
mode = (os.O_RDONLY,os.O_RDWR)[bool(write)]
from .globalvars import g
if g.platform == 'win':
from .globalvars import gc
if gc.platform == 'win':
mode |= os.O_BINARY
try:
fd = os.open(fn, mode)

View file

@ -22,7 +22,7 @@ fileutil: Routines that read, write, execute or stat files
import sys,os
from .globalvars import g
from .globalvars import g,gc
from .color import set_vt100
from .util import (
msg,
@ -43,7 +43,7 @@ def check_or_create_dir(path):
if os.getenv('MMGEN_TEST_SUITE'):
from subprocess import run
run([
('rm' if g.platform == 'win' else '/bin/rm'),
('rm' if gc.platform == 'win' else '/bin/rm'),
'-rf',
path ])
set_vt100()
@ -205,7 +205,7 @@ def write_data_to_file(
else:
msg('Redirecting output to file')
if binary and g.platform == 'win':
if binary and gc.platform == 'win':
import msvcrt
msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)

View file

@ -29,6 +29,79 @@ def die(exit_val,s=''):
sys.stderr.write(s+'\n')
sys.exit(exit_val)
class GlobalConstants(Lockable):
"""
These values are non-configurable. They’re constant for a given machine,
user, executable and MMGen release.
"""
proj_name = 'MMGen'
proj_url = 'https://github.com/mmgen/mmgen'
author = 'The MMGen Project'
email = '<mmgen@tuta.io>'
Cdates = '2013-2023'
dfl_hash_preset = '3'
passwd_max_tries = 5
min_screen_width = 80
min_time_precision = 18
# must match CoinProtocol.coins
core_coins = ('btc','bch','ltc','eth','etc','zec','xmr')
prog_name = os.path.basename(sys.argv[0])
is_txprog = prog_name == 'mmgen-regtest' or prog_name.startswith('mmgen-tx')
for k in ('linux','win','msys'):
if sys.platform.startswith(k):
platform = { 'linux':'linux', 'win':'win', 'msys':'win' }[k]
break
else:
die(1,f'{sys.platform!r}: platform not supported by {proj_name}')
if os.getenv('HOME'): # Linux or MSYS2
home_dir = os.getenv('HOME')
elif platform == 'win': # Windows without MSYS2 - not supported
die(1,f'$HOME not set! {proj_name} for Windows must be run in MSYS2 environment')
else:
die(2,'$HOME is not set! Unable to determine home directory')
def get_mmgen_data_file(self,filename,package='mmgen'):
"""
this is an expensive import, so do only when required
"""
# Resource will be unpacked and then cleaned up if necessary, see:
# https://docs.python.org/3/library/importlib.html:
# Note: This module provides functionality similar to pkg_resources Basic
# Resource Access without the performance overhead of that package.
# https://importlib-resources.readthedocs.io/en/latest/migration.html
# https://setuptools.readthedocs.io/en/latest/pkg_resources.html
try:
from importlib.resources import files # Python 3.9
except ImportError:
from importlib_resources import files
return files(package).joinpath('data',filename).read_text()
@property
def version(self):
return self.get_mmgen_data_file(
filename = 'version',
package = 'mmgen_node_tools' if self.prog_name.startswith('mmnode-') else 'mmgen'
).strip()
@property
def release_date(self):
return self.get_mmgen_data_file(filename='release_date').strip()
gc = GlobalConstants()
class GlobalVars:
"""
These are used only by the test suite to redirect msg() and friends to /dev/null
"""
stdout = sys.stdout
stderr = sys.stderr
gv = GlobalVars()
class GlobalConfig(Lockable):
"""
Set global vars to default values
@ -44,15 +117,6 @@ class GlobalConfig(Lockable):
# Constants:
proj_name = 'MMGen'
proj_url = 'https://github.com/mmgen/mmgen'
prog_name = os.path.basename(sys.argv[0])
author = 'The MMGen Project'
email = '<mmgen@tuta.io>'
Cdates = '2013-2023'
is_txprog = prog_name == 'mmgen-regtest' or prog_name.startswith('mmgen-tx')
stdin_tty = sys.stdin.isatty()
stdout = sys.stdout
stderr = sys.stderr
@ -60,11 +124,9 @@ class GlobalConfig(Lockable):
http_timeout = 60
err_disp_timeout = 0.7
short_disp_timeout = 0.3
min_time_precision = 18
# Variables - these might be altered at runtime:
dfl_hash_preset = '3'
usr_randchars = 30
fee_adjust = 1.0
@ -134,27 +196,10 @@ class GlobalConfig(Lockable):
os.getenv('MMGEN_FORCE_COLOR')
)
for k in ('linux','win','msys'):
if sys.platform.startswith(k):
platform = { 'linux':'linux', 'win':'win', 'msys':'win' }[k]
break
else:
die(1,f'{sys.platform!r}: platform not supported by {proj_name}')
if os.getenv('HOME'): # Linux or MSYS2
home_dir = os.getenv('HOME')
elif platform == 'win': # Windows without MSYS2 - not supported
die(1,f'$HOME not set! {proj_name} for Windows must be run in MSYS2 environment')
else:
die(2,'$HOME is not set! Unable to determine home directory')
daemon_data_dir = '' # set by user
daemon_id = ''
blacklisted_daemons = ''
# must match CoinProtocol.coins
core_coins = ('btc','bch','ltc','eth','etc','zec','xmr')
# global var sets user opt:
global_sets_opt = (
'autochg_ignore_labels',
@ -297,7 +342,7 @@ class GlobalConfig(Lockable):
'fee_estimate_mode': _ov('nocase_pfx', ['conservative','economical']),
'rpc_backend': _ov('nocase_pfx', ['auto','httplib','curl','aiohttp','requests']),
}
if platform == 'win':
if gc.platform == 'win':
_skip_type_check = ('stdout','stderr')
auto_typeset_opts = {
@ -306,13 +351,10 @@ class GlobalConfig(Lockable):
'vsize_adj': float,
}
min_screen_width = 80
minconf = 1
max_tx_file_size = 100000
max_input_size = 1024 * 1024
passwd_max_tries = 5
max_urandchars = 80
min_urandchars = 10
@ -324,7 +366,7 @@ class GlobalConfig(Lockable):
short_disp_timeout = 0.1
if os.getenv('MMGEN_TEST_SUITE_POPEN_SPAWN'):
stdin_tty = True
if prog_name == 'unit_tests.py':
if gc.prog_name == 'unit_tests.py':
_set_ok += ('debug_subseed',)
_reset_ok += ('force_standalone_scrypt_module',)
@ -333,33 +375,6 @@ class GlobalConfig(Lockable):
if name[:11] == 'MMGEN_DEBUG':
os.environ[name] = '1'
def get_mmgen_data_file(self,filename,package='mmgen'):
"""
this is an expensive import, so do only when required
"""
# Resource will be unpacked and then cleaned up if necessary, see:
# https://docs.python.org/3/library/importlib.html:
# Note: This module provides functionality similar to pkg_resources Basic
# Resource Access without the performance overhead of that package.
# https://importlib-resources.readthedocs.io/en/latest/migration.html
# https://setuptools.readthedocs.io/en/latest/pkg_resources.html
try:
from importlib.resources import files # Python 3.9
except ImportError:
from importlib_resources import files
return files(package).joinpath('data',filename).read_text()
@property
def version(self):
return self.get_mmgen_data_file(
filename = 'version',
package = 'mmgen_node_tools' if self.prog_name.startswith('mmnode-') else 'mmgen'
).strip()
@property
def release_date(self):
return self.get_mmgen_data_file(filename='release_date').strip()
@property
def data_dir_root(self):
"""
@ -374,7 +389,7 @@ class GlobalConfig(Lockable):
from test.include.common import get_test_data_dir
self._data_dir_root = get_test_data_dir()
else:
self._data_dir_root = os.path.join(self.home_dir,'.'+self.proj_name.lower())
self._data_dir_root = os.path.join(gc.home_dir,'.'+gc.proj_name.lower())
return self._data_dir_root
@property

View file

@ -20,7 +20,7 @@
help: help notes for MMGen suite commands
"""
from .globalvars import g
from .globalvars import gc
def help_notes_func(proto,opt,k):
@ -156,30 +156,30 @@ EXAMPLES:
Send 0.123 {proto.coin} to an external {proto.name} address, returning the change to a
specific MMGen address in the tracking wallet:
$ {g.prog_name} {sample_addr},0.123 01ABCDEF:{mmtype}:7
$ {gc.prog_name} {sample_addr},0.123 01ABCDEF:{mmtype}:7
Same as above, but select the change address automatically:
$ {g.prog_name} {sample_addr},0.123 01ABCDEF:{mmtype}
$ {gc.prog_name} {sample_addr},0.123 01ABCDEF:{mmtype}
Same as above, but select the change address automatically by address type:
$ {g.prog_name} {sample_addr},0.123 {mmtype}
$ {gc.prog_name} {sample_addr},0.123 {mmtype}
Same as above, but reduce verbosity and specify fee of 20 satoshis
per byte:
$ {g.prog_name} -q -f 20s {sample_addr},0.123 {mmtype}
$ {gc.prog_name} -q -f 20s {sample_addr},0.123 {mmtype}
Send entire balance of selected inputs minus fee to an external {proto.name}
address:
$ {g.prog_name} {sample_addr}
$ {gc.prog_name} {sample_addr}
Send entire balance of selected inputs minus fee to first unused wallet
address of specified type:
$ {g.prog_name} {mmtype}
$ {gc.prog_name} {mmtype}
"""
def txcreate():
@ -235,9 +235,9 @@ must also be supplied on the command line if the data can't be found in the
default wallet.
""".format(
wd = (f'{coind_exec()} wallet dump or ' if isinstance(proto,mainnet) else ''),
pnm = g.proj_name,
pnm = gc.proj_name,
pnu = proto.name,
pnl = g.proj_name.lower() )
pnl = gc.proj_name.lower() )
def seedsplit():
from .seedsplit import SeedShareIdx,SeedShareCount,MasterShareIdx

View file

@ -29,9 +29,9 @@ def launch(mod,package='mmgen'):
mod = 'addrgen'
import sys,os
from .globalvars import g
from .globalvars import gc
if g.platform == 'linux' and sys.stdin.isatty():
if gc.platform == 'linux' and sys.stdin.isatty():
import termios,atexit
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)

View file

@ -22,7 +22,7 @@ mmgen-addrgen: Generate a series or range of addresses from an MMGen
"""
import mmgen.opts as opts
from .globalvars import g
from .globalvars import g,gc
from .opts import opt
from .addr import MMGenAddrType
from .addrfile import AddrFile
@ -30,7 +30,7 @@ from .wallet import Wallet
import mmgen.addrlist
if g.prog_name == 'mmgen-keygen':
if gc.prog_name == 'mmgen-keygen':
gen_what = 'keys'
gen_clsname = 'KeyAddrList'
gen_desc = 'secret keys'
@ -49,7 +49,7 @@ opts_data = {
'desc': """
Generate a range or list of {desc} from an {pnm} wallet,
mnemonic, seed or brainwallet
""".format(desc=gen_desc,pnm=g.proj_name),
""".format(desc=gen_desc,pnm=gc.proj_name),
'usage':'[opts] [seed source] <index list or range(s)>',
'options': """
-h, --help Print this help message
@ -69,7 +69,7 @@ opts_data = {
is required only for brainwallet and incognito inputs
with non-standard (< {dsl}-bit) seed lengths.
-p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
for password hashing (default: '{g.dfl_hash_preset}')
for password hashing (default: '{gc.dfl_hash_preset}')
-z, --show-hash-presets Show information on available hash presets
-P, --passwd-file= f Get wallet passphrase from file 'f'
-q, --quiet Produce quieter output; suppress some warnings
@ -111,9 +111,10 @@ FMT CODES:
kgs=help_notes('keygen_backends'),
coin_id=help_notes('coin_id'),
dsl=help_notes('dfl_seed_len'),
pnm=g.proj_name,
pnm=gc.proj_name,
what=gen_what,
g=g,
gc=gc,
),
'notes': lambda help_notes,s: s.format(
n_addrkey=note_addrkey,

View file

@ -23,7 +23,7 @@ mmgen-addrimport: Import addresses into a MMGen coin daemon tracking wallet
from collections import namedtuple
import mmgen.opts as opts
from .globalvars import g
from .globalvars import gc
from .opts import opt
from .util import msg,qmsg,suf,die,fmt,async_run
from .addrlist import AddrList,KeyAddrList
@ -31,7 +31,7 @@ from .tw.shared import TwLabel
opts_data = {
'text': {
'desc': f'Import addresses into an {g.proj_name} tracking wallet',
'desc': f'Import addresses into an {gc.proj_name} tracking wallet',
'usage':'[opts] [MMGen address file]',
'options': """
-h, --help Print this help message
@ -78,8 +78,8 @@ addrimport_msgs = {
by the number of addresses imported and typically takes just a few minutes.
""",
'bad_args': f"""
You must specify either an {g.proj_name} address file, a single address with
the ‘--address’ option, or a flat list of non-{g.proj_name} addresses with
You must specify either an {gc.proj_name} address file, a single address with
the ‘--address’ option, or a flat list of non-{gc.proj_name} addresses with
the ‘--addrlist’ option.
"""
}
@ -102,7 +102,7 @@ def parse_cmd_args(rpc,cmd_args):
proto = proto,
addrlist = get_lines_from_file(
infile,
f'non-{g.proj_name} addresses',
f'non-{gc.proj_name} addresses',
trim_comments = True ) )
else:
al = import_mmgen_list(infile)

View file

@ -22,7 +22,7 @@ mmgen-passgen: Generate a series or range of passwords from an MMGen
"""
import mmgen.opts as opts
from .globalvars import g
from .globalvars import g,gc
from .opts import opt
from .addrlist import AddrIdxList
from .passwdlist import PasswordList
@ -35,7 +35,7 @@ opts_data = {
'sets': [('print_checksum',True,'quiet',True)],
'text': {
'desc': f"""
Generate a range or list of passwords from an {g.proj_name} wallet,
Generate a range or list of passwords from an {gc.proj_name} wallet,
mnemonic, seed or brainwallet for the given ID string
""",
'usage':'[opts] [seed source] <ID string> <index list or range(s)>',
@ -57,7 +57,7 @@ opts_data = {
is required only for brainwallet and incognito inputs
with non-standard (< {dsl}-bit) seed lengths.
-p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
for password hashing (default: '{g.dfl_hash_preset}')
for password hashing (default: '{gc.dfl_hash_preset}')
-z, --show-hash-presets Show information on available hash presets
-P, --passwd-file= f Get wallet passphrase from file 'f'
-q, --quiet Produce quieter output; suppress some warnings
@ -86,17 +86,17 @@ PASSWORD FORMATS:
EXAMPLES:
Generate ten base58 passwords of length {i58.dfl_len} for Alice's email account:
{g.prog_name} alice@nowhere.com 1-10
{gc.prog_name} alice@nowhere.com 1-10
Generate ten base58 passwords of length 16 for Alice's email account:
{g.prog_name} --passwd-len=16 alice@nowhere.com 1-10
{gc.prog_name} --passwd-len=16 alice@nowhere.com 1-10
Generate ten base32 passwords of length {i32.dfl_len} for Alice's email account:
{g.prog_name} --passwd-fmt=b32 alice@nowhere.com 1-10
{gc.prog_name} --passwd-fmt=b32 alice@nowhere.com 1-10
Generate three BIP39 mnemonic seed phrases of length {i39.dfl_len} for Alice's
Trezor device:
{g.prog_name} --passwd-fmt=bip39 mytrezor 1-3
{gc.prog_name} --passwd-fmt=bip39 mytrezor 1-3
All passwords are cryptographically unlinkable with each other, including
passwords with the same format but different length, so Alice needn't worry
@ -116,9 +116,10 @@ FMT CODES:
},
'code': {
'options': lambda help_notes,s: s.format(
g=g,pnm=g.proj_name,
g=g,pnm=gc.proj_name,
dsl=help_notes('dfl_seed_len'),
dpf=PasswordList.dfl_pw_fmt,
gc=gc,
),
'notes': lambda help_notes,s: s.format(
o=opts,g=g,i58=pwi['b58'],i32=pwi['b32'],i39=pwi['bip39'],
@ -128,6 +129,7 @@ FMT CODES:
n_bw=help_notes('brainwallet'),
pfi=help_notes('password_formats'),
n_fmt=help_notes('fmt_codes'),
gc=gc,
)
}
}
@ -178,7 +180,7 @@ if keypress_confirm('Encrypt password list?'):
af.encrypt()
af.write(binary=True,desc='encrypted password list')
else:
if g.test_suite_popen_spawn and g.platform == 'win':
if g.test_suite_popen_spawn and gc.platform == 'win':
import time
time.sleep(0.1)
af.write(desc='password list')

View file

@ -22,13 +22,13 @@ mmgen-regtest: Coin daemon regression test mode setup and operations for the MMG
"""
import mmgen.opts as opts
from .globalvars import g
from .globalvars import g,gc
from .util import die,async_run
opts_data = {
'sets': [('yes', True, 'quiet', True)],
'text': {
'desc': f'Coin daemon regression test mode setup and operations for the {g.proj_name} suite',
'desc': f'Coin daemon regression test mode setup and operations for the {gc.proj_name} suite',
'usage': '[opts] <command>',
'options': """
-h, --help Print this help message

View file

@ -22,7 +22,7 @@ mmgen-seedjoin: Regenerate an MMGen deterministic wallet from seed shares
"""
import mmgen.opts as opts
from .globalvars import g
from .globalvars import g,gc
from .opts import opt
from .util import msg,msg_r,qmsg,die
from .color import yellow
@ -53,7 +53,7 @@ opts_data = {
-L, --label= l Specify a label 'l' for output wallet
-M, --master-share=i Use a master share with index 'i' (min:{ms_min}, max:{ms_max})
-p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
for password hashing (default: '{g.dfl_hash_preset}')
for password hashing (default: '{gc.dfl_hash_preset}')
-z, --show-hash-presets Show information on available hash presets
-P, --passwd-file= f Get wallet passphrase from file 'f'
-q, --quiet Produce quieter output; suppress some warnings
@ -86,6 +86,7 @@ FMT CODES:
ms_min=MasterShareIdx.min_val,
ms_max=MasterShareIdx.max_val,
g=g,
gc=gc,
),
'notes': lambda help_notes,s: s.format(
f=help_notes('fmt_codes'),

View file

@ -30,7 +30,7 @@ from .common import *
opts_data = {
'text': {
'desc': f"""
Split funds in an {g.proj_name} wallet after a chain fork using a
Split funds in an {gc.proj_name} wallet after a chain fork using a
timelocked transaction
""",
'usage':'[opts] [output addr1] [output addr2]',
@ -54,7 +54,7 @@ opts_data = {
'notes': f"""\n
This command creates two transactions: one (with the timelock) to be broadcast
on the long chain and one on the short chain after a replayable chain fork.
Only {g.proj_name} addresses may be spent to.
Only {gc.proj_name} addresses may be spent to.
The command must be run on the longest chain. The user is reponsible for
ensuring that the current chain is the longest. The other chain is specified
@ -99,7 +99,7 @@ if opt.other_coin.lower() not in [e[2] for e in proto.forks if e[3] == True]:
die(1,f'{opt.other_coin!r}: not a replayable fork of {proto.coin} chain')
if len(cmd_args) != 2:
die(1,f'This command requires exactly two {g.proj_name} addresses as arguments')
die(1,f'This command requires exactly two {gc.proj_name} addresses as arguments')
from .addr import MMGenID
try:

View file

@ -23,13 +23,13 @@ mmgen-tool: Perform various MMGen- and cryptocoin-related operations.
import sys,os,importlib
import mmgen.opts as opts
from .globalvars import g
from .globalvars import g,gc
from .opts import opt
from .util import msg,Msg,die,capfirst,suf,async_run
opts_data = {
'text': {
'desc': f'Perform various {g.proj_name}- and cryptocoin-related operations',
'desc': f'Perform various {gc.proj_name}- and cryptocoin-related operations',
'usage': '[opts] <command> <command args>',
'options': """
-d, --outdir= d Specify an alternate directory 'd' for output
@ -41,7 +41,7 @@ opts_data = {
for {coin_id}: {kgs}
-l, --list List available commands
-p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
for password hashing (default: '{g.dfl_hash_preset}')
for password hashing (default: '{gc.dfl_hash_preset}')
-P, --passwd-file= f Get passphrase from file 'f'.
-q, --quiet Produce quieter output
-r, --usr-randchars=n Get 'n' characters of additional randomness from
@ -65,10 +65,11 @@ Type ‘{pn} help <command>’ for help on a particular command
kgs=help_notes('keygen_backends'),
coin_id=help_notes('coin_id'),
g=g,
gc=gc,
),
'notes': lambda s, help_notes: s.format(
ch=help_notes('tool_help'),
pn=g.prog_name)
pn=gc.prog_name)
}
}
@ -269,8 +270,7 @@ def process_args(cmd,cmd_args,cls):
die(1,"'Binary input data must be supplied via STDIN")
if have_stdin_input and arg_type == 'str' and isinstance(arg,bytes):
from .globalvars import g
NL = '\r\n' if g.platform == 'win' else '\n'
NL = '\r\n' if gc.platform == 'win' else '\n'
arg = arg.decode()
if arg[-len(NL):] == NL: # rstrip one newline
arg = arg[:-len(NL)]
@ -346,7 +346,7 @@ def get_cmd_cls(cmd):
def get_mod_cls(modname):
return getattr(importlib.import_module(f'mmgen.tool.{modname}'),'tool_cmd')
if g.prog_name == 'mmgen-tool' and not opt._lock:
if gc.prog_name == 'mmgen-tool' and not opt._lock:
po = opts.init( opts_data, parse_only=True )

View file

@ -22,7 +22,7 @@ mmgen-txbump: Increase the fee on a replaceable (replace-by-fee) MMGen
"""
import mmgen.opts as opts
from .globalvars import g
from .globalvars import gc
from .opts import opt
from .util import msg,msg_r,qmsg,die,async_run
from .color import green
@ -32,11 +32,11 @@ opts_data = {
'sets': [('yes', True, 'quiet', True)],
'text': {
'desc': f"""
Increase the fee on a replaceable (RBF) {g.proj_name} transaction,
Increase the fee on a replaceable (RBF) {gc.proj_name} transaction,
creating a new transaction, and optionally sign and send the
new transaction
""",
'usage': f'[opts] <{g.proj_name} TX file> [seed source] ...',
'usage': f'[opts] <{gc.proj_name} TX file> [seed source] ...',
'options': """
-h, --help Print this help message
--, --longhelp Print help message for long options (common options)
@ -66,7 +66,7 @@ opts_data = {
for the transaction's change output, if present)
-O, --old-incog-fmt Specify old-format incognito input
-p, --hash-preset= p Use the scrypt hash parameters defined by preset 'p'
for password hashing (default: '{g.dfl_hash_preset}')
for password hashing (default: '{gc.dfl_hash_preset}')
-P, --passwd-file= f Get {pnm} wallet passphrase from file 'f'
-q, --quiet Suppress warnings; overwrite files without prompting
-s, --send Sign and send the transaction (the default if seed
@ -87,9 +87,9 @@ FMT CODES:
},
'code': {
'options': lambda help_notes,proto,s: s.format(
g=g,
pnm=g.proj_name,
pnl=g.proj_name.lower(),
gc=gc,
pnm=gc.proj_name,
pnl=gc.proj_name.lower(),
fu=help_notes('rel_fee_desc'),
fl=help_notes('fee_spec_letters'),
kgs=help_notes('keygen_backends'),

Some files were not shown because too many files have changed in this diff Show more