Browse Source

Merge #96: Add summary flag to wallet tool

eeadc60 Implement wallet-tool 'summary' flag (mecampbellsoup)
master
Adam Gibson 8 years ago
parent
commit
5be5846946
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 32
      jmclient/jmclient/wallet_utils.py

32
jmclient/jmclient/wallet_utils.py

@ -208,7 +208,10 @@ class WalletViewBranch(WalletViewBase):
self.xpub = xpub if xpub else "" self.xpub = xpub if xpub else ""
self.branchentries = branchentries self.branchentries = branchentries
def serialize(self, entryseparator="\n"): def serialize(self, entryseparator="\n", summarize=False):
if summarize:
return ""
else:
lines = [self.serialize_branch_header()] lines = [self.serialize_branch_header()]
for we in self.branchentries: for we in self.branchentries:
lines.append(we.serialize()) lines.append(we.serialize())
@ -239,12 +242,16 @@ class WalletViewAccount(WalletViewBase):
assert all([isinstance(x, WalletViewBranch) for x in branches]) assert all([isinstance(x, WalletViewBranch) for x in branches])
self.branches = branches self.branches = branches
def serialize(self, entryseparator="\n"): def serialize(self, entryseparator="\n", summarize=False):
header = self.account_name + self.separator + str(self.account) header = self.account_name + self.separator + str(self.account)
if self.xpub: if self.xpub:
header = header + self.separator + self.xpub header = header + self.separator + self.xpub
footer = "Balance for mixdepth " + str( footer = "Balance for mixdepth " + str(
self.account) + ":" + self.separator + self.get_fmt_balance() self.account) + ":" + self.separator + self.get_fmt_balance()
if summarize:
return self.serclass(entryseparator.join(
[x.serialize("", summarize=True) for x in self.branches] + [footer]))
else:
return self.serclass(entryseparator.join([header] + [ return self.serclass(entryseparator.join([header] + [
x.serialize(entryseparator) for x in self.branches] + [footer])) x.serialize(entryseparator) for x in self.branches] + [footer]))
@ -259,11 +266,15 @@ class WalletView(WalletViewBase):
assert all([isinstance(x, WalletViewAccount) for x in accounts]) assert all([isinstance(x, WalletViewAccount) for x in accounts])
self.accounts = accounts self.accounts = accounts
def serialize(self, entryseparator="\n"): def serialize(self, entryseparator="\n", summarize=False):
header = self.wallet_name header = self.wallet_name
footer = "Total balance:" + self.separator + self.get_fmt_balance() footer = "Total balance:" + self.separator + self.get_fmt_balance()
if summarize:
return self.serclass(entryseparator.join([header] + [
x.serialize("", summarize=True) for x in self.accounts] + [footer]))
else:
return self.serclass(entryseparator.join([header] + [ return self.serclass(entryseparator.join([header] + [
x.serialize(entryseparator) for x in self.accounts] + [footer])) x.serialize(entryseparator, summarize=False) for x in self.accounts] + [footer]))
def get_imported_privkey_branch(wallet, m, showprivkey): def get_imported_privkey_branch(wallet, m, showprivkey):
if m in wallet.imported_privkeys: if m in wallet.imported_privkeys:
@ -311,7 +322,7 @@ def wallet_showutxos(wallet, showprivkey):
return json.dumps(unsp, indent=4) return json.dumps(unsp, indent=4)
def wallet_display(wallet, gaplimit, showprivkey, displayall=False, def wallet_display(wallet, gaplimit, showprivkey, displayall=False,
serialized=True): serialized=True, summarized=False):
"""build the walletview object, """build the walletview object,
then return its serialization directly if serialized, then return its serialization directly if serialized,
else return the WalletView object. else return the WalletView object.
@ -344,8 +355,8 @@ def wallet_display(wallet, gaplimit, showprivkey, displayall=False,
entrylist.append(WalletViewEntry(rootpath, m, forchange, k, entrylist.append(WalletViewEntry(rootpath, m, forchange, k,
addr, [balance, balance], addr, [balance, balance],
priv=privkey, used=used)) priv=privkey, used=used))
branchlist.append(WalletViewBranch(rootpath, m, forchange, entrylist, branchlist.append(WalletViewBranch(rootpath, m, forchange,
xpub=xpub_key)) entrylist, xpub=xpub_key))
ipb = get_imported_privkey_branch(wallet, m, showprivkey) ipb = get_imported_privkey_branch(wallet, m, showprivkey)
if ipb: if ipb:
branchlist.append(ipb) branchlist.append(ipb)
@ -356,7 +367,7 @@ def wallet_display(wallet, gaplimit, showprivkey, displayall=False,
xpub=xpub_account)) xpub=xpub_account))
walletview = WalletView(rootpath, acctlist) walletview = WalletView(rootpath, acctlist)
if serialized: if serialized:
return walletview.serialize() return walletview.serialize(summarize=summarized)
else: else:
return walletview return walletview
@ -871,8 +882,9 @@ def wallet_tool_main(wallet_root_path):
if method == "display": if method == "display":
return wallet_display(wallet, options.gaplimit, options.showprivkey) return wallet_display(wallet, options.gaplimit, options.showprivkey)
elif method == "displayall": elif method == "displayall":
return wallet_display(wallet, options.gaplimit, options.showprivkey, return wallet_display(wallet, options.gaplimit, options.showprivkey, displayall=True)
displayall=True) elif method == "summary":
return wallet_display(wallet, options.gaplimit, options.showprivkey, summarized=True)
elif method == "history": elif method == "history":
if not isinstance(jm_single().bc_interface, BitcoinCoreInterface): if not isinstance(jm_single().bc_interface, BitcoinCoreInterface):
print('showing history only available when using the Bitcoin Core ' + print('showing history only available when using the Bitcoin Core ' +

Loading…
Cancel
Save