From 87eaf4da553e8e3df738f0e67d304aaa7c4f9ad0 Mon Sep 17 00:00:00 2001 From: Lev Berman Date: Tue, 18 Sep 2018 18:22:27 +0200 Subject: [PATCH] Extend `election show` with migration data. --- bigchaindb/commands/bigchaindb.py | 2 +- bigchaindb/commands/election_types.py | 2 ++ .../migrations/chain_migration_election.py | 23 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/bigchaindb/commands/bigchaindb.py b/bigchaindb/commands/bigchaindb.py index 58db7ac0..ddc7a5f5 100644 --- a/bigchaindb/commands/bigchaindb.py +++ b/bigchaindb/commands/bigchaindb.py @@ -118,7 +118,6 @@ def run_election_new(args, bigchain): def create_new_election(sk, bigchain, election_class, data): - try: key = load_node_key(sk) voters = election_class.recipients(bigchain) @@ -362,6 +361,7 @@ def create_parser(): help='The election_id of the election.') approve_election_parser.add_argument('--private-key', dest='sk', + required=True, help='Path to the private key of the election initiator.') show_election_parser = election_subparser.add_parser('show', diff --git a/bigchaindb/commands/election_types.py b/bigchaindb/commands/election_types.py index 4745b85d..cfa58b9e 100644 --- a/bigchaindb/commands/election_types.py +++ b/bigchaindb/commands/election_types.py @@ -13,6 +13,7 @@ elections = { }, '--private-key': { 'dest': 'sk', + 'required': True, 'help': 'Path to the private key of the election initiator.' } } @@ -22,6 +23,7 @@ elections = { 'args': { '--private-key': { 'dest': 'sk', + 'required': True, 'help': 'Path to the private key of the election initiator.' } } diff --git a/bigchaindb/migrations/chain_migration_election.py b/bigchaindb/migrations/chain_migration_election.py index 129e6684..52f8b020 100644 --- a/bigchaindb/migrations/chain_migration_election.py +++ b/bigchaindb/migrations/chain_migration_election.py @@ -1,3 +1,5 @@ +import json + from bigchaindb.common.schema import TX_SCHEMA_CHAIN_MIGRATION_ELECTION from bigchaindb.elections.election import Election @@ -20,3 +22,24 @@ class ChainMigrationElection(Election): def on_approval(self, bigchain, *args, **kwargs): bigchain.migrate_abci_chain() + + def show_election(self, bigchain): + output = super().show_election(bigchain) + chain = bigchain.get_latest_abci_chain() + if chain is None or chain['is_synced']: + return output + + output += f'\nchain_id={chain["chain_id"]}' + block = bigchain.get_latest_block() + output += f'\napp_hash={block["app_hash"]}' + validators = [ + { + 'pub_key': { + 'type': 'tendermint/PubKeyEd25519', + 'value': k, + }, + 'power': v, + } for k, v in self.get_validators(bigchain).items() + ] + output += f'\nvalidators={json.dumps(validators, indent=4)}' + return output