Skip to content

Commit

Permalink
obj.py: remove 'on_fail' keyword arg
Browse files Browse the repository at this point in the history
- During initialization, data objects now invariably raise an exception on
  failure (ObjectInitError by default, configurable via the 'exc' attribute).

- For callers that need to handle the exception, the new get_obj() wrapper is
  provided.

Testing:

    $ test/objtest.py -S
    $ test/objtest.py -S --getobj
  • Loading branch information
mmgen committed Jun 1, 2020
1 parent 5e745f2 commit 0852321
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 144 deletions.
2 changes: 1 addition & 1 deletion mmgen/addr.py
Expand Up @@ -1159,7 +1159,7 @@ async def add_tw_data(self,wallet):
twd = await self.get_tw_data(wallet)
out,i = {},0
for acct,addr_array in twd:
l = TwLabel(self.proto,acct,on_fail='silent')
l = get_obj(TwLabel,proto=self.proto,text=acct,silent=True)
if l and l.mmid.type == 'mmgen':
obj = l.mmid.obj
if len(addr_array) != 1:
Expand Down
4 changes: 2 additions & 2 deletions mmgen/altcoins/eth/tw.py
Expand Up @@ -257,7 +257,7 @@ async def get_unspent_rpc(self):
if self.addrs:
wl = [d for d in wl if d['addr'] in self.addrs]
return [{
'account': TwLabel(self.proto,d['mmid']+' '+d['comment'],on_fail='raise'),
'account': TwLabel(self.proto,d['mmid']+' '+d['comment']),
'address': d['addr'],
'amount': await self.wallet.get_balance(d['addr']),
'confirmations': 0, # TODO
Expand Down Expand Up @@ -298,7 +298,7 @@ async def __ainit__(self,proto,usr_addr_list,minconf,showempty,showbtcaddrs,all_
from mmgen.obj import CoinAddr
for mmid,d in list(tw_dict.items()):
# if d['confirmations'] < minconf: continue # cannot get confirmations for eth account
label = TwLabel(self.proto,mmid+' '+d['comment'],on_fail='raise')
label = TwLabel(self.proto,mmid+' '+d['comment'])
if usr_addr_list and (label.mmid not in usr_addr_list):
continue
bal = await self.wallet.get_balance(d['addr'])
Expand Down
3 changes: 2 additions & 1 deletion mmgen/exception.py
Expand Up @@ -40,10 +40,11 @@ class InvalidTokenAddress(Exception): mmcode = 2
class UnrecognizedTokenSymbol(Exception): mmcode = 2
class TokenNotInBlockchain(Exception): mmcode = 2
class TokenNotInWallet(Exception): mmcode = 2
class BadTwComment(Exception): mmcode = 2
class BadTwLabel(Exception): mmcode = 2
class BaseConversionError(Exception): mmcode = 2
class BaseConversionPadError(Exception): mmcode = 2
class TransactionChainMismatch(Exception):mmcode = 2
class ObjectInitError(Exception): mmcode = 2

# 3: yellow hl, 'MMGen Error' + exception + message
class RPCFailure(Exception): mmcode = 3
Expand Down
2 changes: 1 addition & 1 deletion mmgen/main_split.py
Expand Up @@ -104,7 +104,7 @@

from .obj import MMGenID
try:
mmids = [MMGenID(a,on_fail='die') for a in cmd_args]
mmids = [MMGenID(a) for a in cmd_args]
except:
die(1,'Command line arguments must be valid MMGen IDs')

Expand Down
4 changes: 2 additions & 2 deletions mmgen/main_wallet.py
Expand Up @@ -148,10 +148,10 @@
from .obj import SubSeedIdx
ss_idx = SubSeedIdx(cmd_args.pop())
elif invoked_as == 'seedsplit':
from .obj import SeedSplitSpecifier
from .obj import get_obj,SeedSplitSpecifier
master_share = MasterShareIdx(opt.master_share) if opt.master_share else None
if cmd_args:
sss = SeedSplitSpecifier(cmd_args.pop(),on_fail='silent')
sss = get_obj(SeedSplitSpecifier,s=cmd_args.pop(),silent=True)
if master_share:
if not sss:
sss = SeedSplitSpecifier('1:2')
Expand Down

0 comments on commit 0852321

Please sign in to comment.