From 3268d1968a91e39dba705eb5c0e711bb707fd70f Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Thu, 25 Jan 2018 22:57:30 +0100 Subject: [PATCH] [enh] #46: Add-up pubkeys amounts: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - retrieve pubkey amounts from outside display f(). - rename argument from "pubkey" –> "pubkeys". - allows passing many pubkeys as argument. - display pubkeys amounts in a loop. - display add-up at the end whether several pubkeys have been specified. --- src/commands.py | 25 ++++++++++++++++--------- src/silkaj.py | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/commands.py b/src/commands.py index 2cc5ec73..d777753c 100644 --- a/src/commands.py +++ b/src/commands.py @@ -218,21 +218,28 @@ def list_issuers(ep, nbr, last): def cmd_amount(ep, c): - if c.contains_definitions('pubkey'): - pubkey = c.get_definition('pubkey') - pubkey = check_public_key(pubkey, True) - if not pubkey: - return + if c.contains_definitions("pubkeys"): + pubkeys = c.get_definition("pubkeys").split(":") + for pubkey in pubkeys: + pubkey = check_public_key(pubkey, True) + if not pubkey: + return + total = [0, 0] + for pubkey in pubkeys: + value = get_amount_from_pubkey(ep, pubkey) + show_amount_from_pubkey(ep, pubkey, value) + total[0] += value[0] + total[1] += value[1] + if (len(pubkeys) > 1): + show_amount_from_pubkey(ep, "Total", total) else: seed = auth_method(c) pubkey = get_publickey_from_seed(seed) + show_amount_from_pubkey(ep, pubkey, get_amount_from_pubkey(ep, pubkey)) - show_amount_from_pubkey(ep, pubkey) +def show_amount_from_pubkey(ep, pubkey, value): -def show_amount_from_pubkey(ep, pubkey): - - value = get_amount_from_pubkey(ep, pubkey) totalAmountInput = value[0] amount = value[1] # output diff --git a/src/silkaj.py b/src/silkaj.py index 711f0fbf..59d207d0 100755 --- a/src/silkaj.py +++ b/src/silkaj.py @@ -19,8 +19,8 @@ def usage(): \nCommands: \ \n - info: Display information about currency \ \n \ - \n - amount: Get amount of one account \ - \n --pubkey=<pubkey[:checksum]>\ + \n - amount: Get amount of accounts \ + \n --pubkeys=<pubkey:pubkey:pubkey>\ \n --auth-scrypt [script parameters -n <N> -r <r> -p <p>] (default: 4096,16,1)\ \n --auth-seed | --auth-file [--file=<path file>] | --auth-wif\ \n \ -- GitLab