use relative imports throughout

This commit is contained in:
The MMGen Project 2020-04-09 19:32:23 +00:00
commit 701e7a77e5
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
40 changed files with 236 additions and 236 deletions

View file

@ -21,9 +21,9 @@ addr.py: Address generation/display routines for the MMGen suite
"""
from hashlib import sha256,sha512
from mmgen.common import *
from mmgen.obj import *
from mmgen.baseconv import *
from .common import *
from .obj import *
from .baseconv import *
pnm = g.proj_name
@ -53,7 +53,7 @@ class AddrGenerator(MMGenObject):
class AddrGeneratorP2PKH(AddrGenerator):
def to_addr(self,pubhex):
from mmgen.protocol import hash160
from .protocol import hash160
assert type(pubhex) == PubKey
return CoinAddr(g.proto.pubhash2addr(hash160(pubhex),p2sh=False))
@ -72,7 +72,7 @@ class AddrGeneratorSegwit(AddrGenerator):
class AddrGeneratorBech32(AddrGenerator):
def to_addr(self,pubhex):
assert pubhex.compressed,'Uncompressed public keys incompatible with Segwit'
from mmgen.protocol import hash160
from .protocol import hash160
return CoinAddr(g.proto.pubhash2bech32addr(hash160(pubhex)))
def to_segwit_redeem_script(self,pubhex):
@ -86,10 +86,10 @@ class AddrGeneratorEthereum(AddrGenerator):
assert not g.use_internal_keccak_module
from sha3 import keccak_256
except:
from mmgen.keccak import keccak_256
from .keccak import keccak_256
self.keccak_256 = keccak_256
from mmgen.protocol import hash256
from .protocol import hash256
self.hash256 = hash256
return AddrGenerator.__init__(addr_type)
@ -111,7 +111,7 @@ class AddrGeneratorZcashZ(AddrGenerator):
s = bytearray(s + bytes(32))
s[0] |= 0xc0
s[32] = t
from mmgen.sha2 import Sha256
from .sha2 import Sha256
return Sha256(s,preprocess=False).digest()
def to_addr(self,pubhex): # pubhex is really privhex
@ -119,7 +119,7 @@ class AddrGeneratorZcashZ(AddrGenerator):
assert len(key) == 32,'{}: incorrect privkey length'.format(len(key))
from nacl.bindings import crypto_scalarmult_base
p2 = crypto_scalarmult_base(self.zhash256(key,1))
from mmgen.protocol import _b58chk_encode
from .protocol import _b58chk_encode
ver_bytes = g.proto.addr_fmt_to_ver_bytes('zcash_z')
ret = _b58chk_encode(ver_bytes + self.zhash256(key,0) + p2)
return CoinAddr(ret)
@ -131,7 +131,7 @@ class AddrGeneratorZcashZ(AddrGenerator):
vk[32] &= 0xf8
vk[63] &= 0x7f
vk[63] |= 0x40
from mmgen.protocol import _b58chk_encode
from .protocol import _b58chk_encode
ver_bytes = g.proto.addr_fmt_to_ver_bytes('viewkey')
ret = _b58chk_encode(ver_bytes + vk)
return ZcashViewKey(ret)
@ -147,17 +147,17 @@ class AddrGeneratorMonero(AddrGenerator):
assert not g.use_internal_keccak_module
from sha3 import keccak_256
except:
from mmgen.keccak import keccak_256
from .keccak import keccak_256
self.keccak_256 = keccak_256
from mmgen.protocol import hash256
from .protocol import hash256
self.hash256 = hash256
if opt.use_old_ed25519:
from mmgen.ed25519 import edwards,encodepoint,B,scalarmult
from .ed25519 import edwards,encodepoint,B,scalarmult
else:
from mmgen.ed25519ll_djbec import scalarmult
from mmgen.ed25519 import edwards,encodepoint,B
from .ed25519ll_djbec import scalarmult
from .ed25519 import edwards,encodepoint,B
self.edwards = edwards
self.encodepoint = encodepoint
@ -233,7 +233,7 @@ class KeyGenerator(MMGenObject):
@classmethod
def test_for_secp256k1(self,silent=False):
try:
from mmgen.secp256k1 import priv2pub
from .secp256k1 import priv2pub
m = 'Unable to execute priv2pub() from secp256k1 extension module'
assert priv2pub(bytes.fromhex('deadbeef'*8),1),m
return True
@ -280,7 +280,7 @@ class KeyGeneratorSecp256k1(KeyGenerator):
desc = 'mmgen-secp256k1'
def to_pubhex(self,privhex):
assert type(privhex) == PrivKey
from mmgen.secp256k1 import priv2pub
from .secp256k1 import priv2pub
return PubKey(priv2pub(bytes.fromhex(privhex),int(privhex.compressed)).hex(),compressed=privhex.compressed)
class KeyGeneratorDummy(KeyGenerator):
@ -494,14 +494,14 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
scramble_key = g.coin.lower()
else:
scramble_key = (g.coin.lower()+':','')[is_btcfork] + self.al_id.mmtype.name
from mmgen.crypto import scramble_seed
from .crypto import scramble_seed
if g.proto.is_testnet():
scramble_key += ':testnet'
dmsg_sc('str',scramble_key)
return scramble_seed(seed,scramble_key.encode())
def encrypt(self,desc='new key list'):
from mmgen.crypto import mmgen_encrypt
from .crypto import mmgen_encrypt
self.fmt_data = mmgen_encrypt(self.fmt_data.encode(),desc,'')
self.ext += '.'+g.mmenc_ext
@ -697,7 +697,7 @@ Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
else:
mmtype = MMGenAddrType(al_mmtype,on_fail='raise')
from mmgen.protocol import CoinProtocol
from .protocol import CoinProtocol
base_coin = CoinProtocol(al_coin or 'BTC',testnet=False).base_coin
return base_coin,mmtype,tn
@ -780,7 +780,7 @@ class KeyList(AddrList):
chksum_rec_f = lambda foo,e: (str(e.idx), e.addr, e.sec.wif)
def is_bip39_str(s):
from mmgen.bip39 import bip39
from .bip39 import bip39
return bool(bip39.tohex(s.split(),wl_id='bip39'))
def is_xmrseed(s):
@ -918,7 +918,7 @@ Record this checksum: it will be used to verify the password file in the future
pw_bytes = self.pw_len // 2
good_pw_len = seed.byte_len * 2
elif pf == 'bip39':
from mmgen.bip39 import bip39
from .bip39 import bip39
pw_bytes = bip39.nwords2seedlen(self.pw_len,in_bytes=True)
good_pw_len = bip39.seedlen2nwords(seed.byte_len,in_bytes=True)
elif pf == 'xmrseed':
@ -952,7 +952,7 @@ Record this checksum: it will be used to verify the password file in the future
# take most significant part
return hex_sec[:self.pw_len]
elif self.pw_fmt == 'bip39':
from mmgen.bip39 import bip39
from .bip39 import bip39
pw_len_hex = bip39.nwords2seedlen(self.pw_len,in_hex=True)
# take most significant part
return ' '.join(bip39.fromhex(hex_sec[:pw_len_hex],wl_id='bip39'))
@ -960,7 +960,7 @@ Record this checksum: it will be used to verify the password file in the future
pw_len_hex = baseconv.seedlen_map_rev['xmrseed'][self.pw_len] * 2
# take most significant part
bytes_trunc = bytes.fromhex(hex_sec[:pw_len_hex])
from mmgen.protocol import MoneroProtocol
from .protocol import MoneroProtocol
bytes_preproc = MoneroProtocol.preprocess_key(bytes_trunc,None)
return ' '.join(baseconv.frombytes(bytes_preproc,wl_id='xmrseed'))
else:
@ -982,11 +982,11 @@ Record this checksum: it will be used to verify the password file in the future
scramble_key = '{}:{}:{}'.format(self.pw_fmt,self.pw_len,self.pw_id_str)
if self.hex2bip39:
from mmgen.bip39 import bip39
from .bip39 import bip39
pwlen = bip39.nwords2seedlen(self.pw_len,in_hex=True)
scramble_key = '{}:{}:{}'.format('hex',pwlen,self.pw_id_str)
from mmgen.crypto import scramble_seed
from .crypto import scramble_seed
dmsg_sc('str',scramble_key)
return scramble_seed(seed,scramble_key.encode())

View file

@ -21,8 +21,8 @@ baseconv.py: base conversion class for the MMGen suite
"""
from hashlib import sha256
from mmgen.exception import *
from mmgen.util import die
from .exception import *
from .util import die
def is_b58_str(s): return set(list(s)) <= set(baseconv.digits['b58'])
def is_b32_str(s): return set(list(s)) <= set(baseconv.digits['b32'])
@ -76,13 +76,13 @@ class baseconv(object):
if mn_id in cls.digits:
return
if mn_id == 'mmgen':
from mmgen.mn_electrum import words
from .mn_electrum import words
cls.digits[mn_id] = words
elif mn_id == 'xmrseed':
from mmgen.mn_monero import words
from .mn_monero import words
cls.digits[mn_id] = words
elif mn_id == 'tirosh':
from mmgen.mn_tirosh import words
from .mn_tirosh import words
cls.digits[mn_id] = words[:cls.mn_base]
else:
raise ValueError('{}: unrecognized mnemonic ID'.format(mn_id))
@ -109,7 +109,7 @@ class baseconv(object):
cls.init_mn(wl_id)
wl = cls.digits[wl_id]
from mmgen.util import qmsg,compare_chksums
from .util import qmsg,compare_chksums
ret = 'Wordlist: {}\nLength: {} words'.format(wl_id,len(wl))
new_chksum = cls.get_wordlist_chksum(wl_id)
@ -202,7 +202,7 @@ class baseconv(object):
def fromhex(cls,hexstr,wl_id,pad=None,tostr=False):
"convert hex string to list or string data of base 'wl_id'"
from mmgen.util import is_hex_str
from .util import is_hex_str
if not is_hex_str(hexstr):
m = ('{h!r}:','seed data')[pad=='seed'] + ' not a hexadecimal string'
raise HexadecimalStringError(m.format(h=hexstr))

View file

@ -22,9 +22,9 @@ bip39.py - Data and routines for BIP39 mnemonic seed phrases
from hashlib import sha256
from mmgen.exception import *
from mmgen.baseconv import *
from mmgen.util import is_hex_str
from .exception import *
from .baseconv import *
from .util import is_hex_str
# implements a subset of the baseconv API
class bip39(baseconv):

View file

@ -27,8 +27,8 @@ cfg.py: API for the MMGen runtime configuration file and related files
import sys,os,re,hashlib
from collections import namedtuple
from mmgen.globalvars import *
from mmgen.util import *
from .globalvars import *
from .util import *
def cfg_file(id_str):
return CfgFile.get_cls_by_id(id_str)()

View file

@ -93,12 +93,12 @@ def init_color(num_colors='auto'):
def start_mscolor():
import sys
from mmgen.globalvars import g
from .globalvars import g
try:
import colorama
colorama.init(strip=True,convert=True)
except:
from mmgen.util import msg
from .util import msg
msg('Import of colorama module failed')
else:
g.stdout = sys.stdout

View file

@ -21,16 +21,16 @@ common.py: Common imports for all MMGen scripts
"""
import sys,os
from mmgen.exception import *
from mmgen.globalvars import *
from .exception import *
from .globalvars import *
import mmgen.opts as opts
from mmgen.opts import opt
from mmgen.util import *
from .opts import opt
from .util import *
def help_notes(k):
from mmgen.obj import SubSeedIdxRange,SeedShareIdx,SeedShareCount,MasterShareIdx
from .obj import SubSeedIdxRange,SeedShareIdx,SeedShareCount,MasterShareIdx
from .wallet import Wallet
from mmgen.tx import MMGenTX
from .tx import MMGenTX
def fee_spec_letters(use_quotes=False):
cu = g.proto.coin_amt.units
sep,conj = ((',',' or '),("','","' or '"))[use_quotes]

View file

@ -23,7 +23,7 @@ crypto.py: Cryptographic and related routines for the MMGen suite
from cryptography.hazmat.primitives.ciphers import Cipher,algorithms,modes
from cryptography.hazmat.backends import default_backend
from hashlib import sha256
from mmgen.common import *
from .common import *
crmsg = {
'usr_rand_notice': """
@ -158,7 +158,7 @@ def _get_random_data_from_user(uchars,desc,test_suite=False):
prompt = 'You may begin typing. {} symbols left: '
import time
from mmgen.term import get_char_raw
from .term import get_char_raw
key_data,time_data = '',[]
for i in range(uchars):

View file

@ -23,8 +23,8 @@ daemon.py: Daemon control interface for the MMGen suite
import shutil
from subprocess import run,PIPE
from collections import namedtuple
from mmgen.exception import *
from mmgen.common import *
from .exception import *
from .common import *
class Daemon(MMGenObject):
@ -253,7 +253,7 @@ class MoneroWalletDaemon(Daemon):
def state(self):
if not self.test_socket(g.monero_wallet_rpc_host,self.rpc_port):
return 'stopped'
from mmgen.rpc import MoneroWalletRPCConnection
from .rpc import MoneroWalletRPCConnection
try:
MoneroWalletRPCConnection(
g.monero_wallet_rpc_host,
@ -337,7 +337,7 @@ class CoinDaemon(Daemon):
me.desc = 'test suite daemon'
rel_datadir = os.path.join('test','daemons',daemon_id)
else:
from mmgen.protocol import CoinProtocol
from .protocol import CoinProtocol
me.datadir = CoinProtocol(daemon_id,False).daemon_data_dir
if test_suite:
@ -523,7 +523,7 @@ class EthereumDaemon(CoinDaemon):
@property
def state(self):
from mmgen.rpc import EthereumRPCConnection
from .rpc import EthereumRPCConnection
try:
conn = EthereumRPCConnection('localhost',self.rpc_port,socket_timeout=0.2)
except:

View file

@ -102,9 +102,9 @@ if os.getenv('MMGEN_DEBUG') or os.getenv('MMGEN_TEST_SUITE') or os.getenv('MMGEN
# Check that all immutables have been initialized. Expensive, so do only when testing.
def immutable_attr_init_check(self):
from mmgen.globalvars import g
from .globalvars import g
if g.test_suite:
from mmgen.util import rdie
from .util import rdie
cls = type(self)
for attrname in sorted({a for a in self.valid_attrs if a[0] != '_'}):
for o in (cls,cls.__bases__[0]): # assume there's only one base class

View file

@ -22,10 +22,10 @@ filename.py: Filename class and methods for the MMGen suite
import sys,os
from mmgen.exception import BadFileExtension,FileNotFound
from mmgen.obj import *
from mmgen.util import die,get_extension
from mmgen.seed import *
from .exception import BadFileExtension,FileNotFound
from .obj import *
from .util import die,get_extension
from .seed import *
class Filename(MMGenObject):
@ -40,7 +40,7 @@ class Filename(MMGenObject):
self.atime = None
from .wallet import Wallet
from mmgen.tx import MMGenTX
from .tx import MMGenTX
if ftype:
if isinstance(ftype,type):
if issubclass(ftype,(Wallet,MMGenTX)):

View file

@ -23,7 +23,7 @@ globalvars.py: Constants and configuration options for the MMGen suite
import sys,os
from decimal import Decimal
from collections import namedtuple
from mmgen.devtools import *
from .devtools import *
# Global vars are set to dfl values in class g.
# They're overridden in this order:

View file

@ -20,7 +20,7 @@
license.py: Copyright notice and text of GPLv3
"""
from mmgen.globalvars import g
from .globalvars import g
warning = """
{pnm} Copyright (C) {g.Cdates} by {g.author} {g.email}. This

View file

@ -27,7 +27,7 @@ def launch(mod):
if mod == 'keygen': mod = 'addrgen'
import sys,os
from mmgen.globalvars import g
from .globalvars import g
if g.platform == 'linux' and sys.stdin.isatty():
import termios,atexit
@ -49,7 +49,7 @@ def launch(mod):
try: m = '{}'.format(e.args[0])
except: m = repr(e.args[0])
from mmgen.util import die,ydie,rdie
from .util import die,ydie,rdie
d = [ (ydie,2,'\nMMGen Unhandled Exception ({n}): {m}'),
(die, 1,'{m}'),
(ydie,2,'{m}'),

View file

@ -21,9 +21,9 @@ mmgen-addrgen: Generate a series or range of addresses from an MMGen
deterministic wallet
"""
from mmgen.common import *
from mmgen.crypto import *
from mmgen.addr import *
from .common import *
from .crypto import *
from .addr import *
from .wallet import Wallet
if g.prog_name == 'mmgen-keygen':

View file

@ -22,9 +22,9 @@ mmgen-addrimport: Import addresses into a MMGen coin daemon tracking wallet
import time
from mmgen.common import *
from mmgen.addr import AddrList,KeyAddrList
from mmgen.obj import TwLabel,is_coin_addr
from .common import *
from .addr import AddrList,KeyAddrList
from .obj import TwLabel,is_coin_addr
ai_msgs = lambda k: {
'rescan': """
@ -76,7 +76,7 @@ cmd_args = opts.init(opts_data)
def import_mmgen_list(infile):
al = (AddrList,KeyAddrList)[bool(opt.keyaddr_file)](infile)
if al.al_id.mmtype in ('S','B'):
from mmgen.tx import segwit_is_active
from .tx import segwit_is_active
if not segwit_is_active():
rdie(2,'Segwit is not active on this chain. Cannot import Segwit addresses')
return al
@ -102,7 +102,7 @@ qmsg('OK. {} addresses{}'.format(al.num_addrs,m))
err_msg = None
from mmgen.tw import TrackingWallet
from .tw import TrackingWallet
tw = TrackingWallet(mode='w')
if g.token:

View file

@ -30,7 +30,7 @@ part_label = 'MMGEN_TX'
wallet_dir = '/dev/shm/autosign'
key_fn = 'autosign.key'
from mmgen.common import *
from .common import *
prog_name = os.path.basename(sys.argv[0])
opts_data = {
'text': {
@ -111,10 +111,10 @@ exit_if_mswin('autosigning')
import mmgen.tx
import mmgen.altcoins.eth.tx
from mmgen.txsign import txsign
from mmgen.protocol import CoinProtocol,init_coin
from .txsign import txsign
from .protocol import CoinProtocol,init_coin
if g.test_suite:
from mmgen.daemon import CoinDaemon
from .daemon import CoinDaemon
if opt.stealth_led: opt.led = True
@ -362,7 +362,7 @@ def setup():
opt.hash_preset = '1'
opt.set_by_user = ['hash_preset']
opt.passwd_file = os.path.join(tx_dir,key_fn)
from mmgen.obj import MMGenWalletLabel
from .obj import MMGenWalletLabel
opt.label = MMGenWalletLabel('Autosign Wallet')
ss_out = Wallet(ss=ss_in)
ss_out.write_to_file(desc='autosign wallet',outdir=wallet_dir)

View file

@ -21,11 +21,11 @@ mmgen-passgen: Generate a series or range of passwords from an MMGen
deterministic wallet
"""
from mmgen.common import *
from mmgen.crypto import *
from mmgen.addr import PasswordList,AddrIdxList
from .common import *
from .crypto import *
from .addr import PasswordList,AddrIdxList
from .wallet import Wallet
from mmgen.obj import MMGenPWIDString
from .obj import MMGenPWIDString
pwi = PasswordList.pw_info
pwi_fs = '{:8} {:1} {:26} {:<7} {:<7} {}'

View file

@ -21,7 +21,7 @@ mmgen-regtest: Coin daemon regression test mode setup and operations for the MMG
suite
"""
from mmgen.common import *
from .common import *
opts_data = {
'sets': [('yes', True, 'quiet', True)],
@ -58,7 +58,7 @@ opts_data = {
cmd_args = opts.init(opts_data)
from mmgen.regtest import MMGenRegtest
from .regtest import MMGenRegtest
def check_num_args():
m = getattr(MMGenRegtest,cmd_args[0])

View file

@ -21,8 +21,8 @@ mmgen/main_seedjoin: Regenerate an MMGen deterministic wallet from seed shares
created by 'mmgen-seedsplit'
"""
from mmgen.common import *
from mmgen.obj import MasterShareIdx,SeedSplitIDString,MMGenWalletLabel
from .common import *
from .obj import MasterShareIdx,SeedSplitIDString,MMGenWalletLabel
from .seed import Seed,SeedShareMasterJoining
from .wallet import Wallet

View file

@ -24,7 +24,7 @@ mmgen-split: Split funds after a replayable chain fork using a timelocked transa
import time
from mmgen.common import *
from .common import *
opts_data = {
'text': {
@ -97,7 +97,7 @@ if len(cmd_args) != 2:
fs = 'This command requires exactly two {} addresses as arguments'
die(1,fs.format(g.proj_name))
from mmgen.obj import MMGenID
from .obj import MMGenID
try:
mmids = [MMGenID(a,on_fail='die') for a in cmd_args]
except:
@ -106,8 +106,8 @@ except:
if mmids[0] == mmids[1]:
die(2,'Both transactions have the same output! ({})'.format(mmids[0]))
from mmgen.tx import MMGenSplitTX
from mmgen.protocol import init_coin
from .tx import MMGenSplitTX
from .protocol import init_coin
if opt.tx_fees:
for idx,g_coin in ((1,opt.other_coin),(0,g.coin)):

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