From 3f81e7eeaaaa3fc346806330c03fdbc83e6457a5 Mon Sep 17 00:00:00 2001 From: z-bowen Date: Wed, 12 Sep 2018 14:12:02 +0200 Subject: [PATCH] Problem: `MigrationElection` needed to be added to the list of allowed operations Solution: Added it --- bigchaindb/__init__.py | 2 ++ bigchaindb/commands/bigchaindb.py | 35 +++++++++++++++++++ .../common/schema/transaction_v2.0.yaml | 1 + 3 files changed, 38 insertions(+) diff --git a/bigchaindb/__init__.py b/bigchaindb/__init__.py index e1762f5d..7b10446b 100644 --- a/bigchaindb/__init__.py +++ b/bigchaindb/__init__.py @@ -7,6 +7,7 @@ import logging from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config from bigchaindb.lib import BigchainDB # noqa +from bigchaindb.migrations.migration_election import MigrationElection from bigchaindb.version import __version__ # noqa from bigchaindb.core import App # noqa @@ -99,4 +100,5 @@ from bigchaindb.elections.vote import Vote # noqa Transaction.register_type(Transaction.CREATE, models.Transaction) Transaction.register_type(Transaction.TRANSFER, models.Transaction) Transaction.register_type(ValidatorElection.OPERATION, ValidatorElection) +Transaction.register_type(MigrationElection.OPERATION, MigrationElection) Transaction.register_type(Vote.OPERATION, Vote) diff --git a/bigchaindb/commands/bigchaindb.py b/bigchaindb/commands/bigchaindb.py index 96d555bb..0a6f6d5d 100644 --- a/bigchaindb/commands/bigchaindb.py +++ b/bigchaindb/commands/bigchaindb.py @@ -13,6 +13,7 @@ import copy import json import sys +from bigchaindb.migrations.migration_election import MigrationElection from bigchaindb.utils import load_node_key from bigchaindb.common.exceptions import (DatabaseDoesNotExist, ValidationError) @@ -159,6 +160,40 @@ def run_election_new_upsert_validator(args, bigchain): return False +def run_election_new_migration(args, bigchain): + """Initiates an election to halt block production + + :param args: dict + args = { + 'sk': the path to the private key of the node calling the election (str) + } + :param bigchain: an instance of BigchainDB + :return: election_id or `False` in case of failure + """ + + try: + key = load_node_key(args.sk) + voters = MigrationElection.recipients(bigchain) + election = MigrationElection.generate([key.public_key], + voters, + {}, None).sign([key.private_key]) + election.validate(bigchain) + except ValidationError as e: + logger.error(e) + return False + except FileNotFoundError as fd_404: + logger.error(fd_404) + return False + + resp = bigchain.write_transaction(election, 'broadcast_tx_commit') + if resp == (202, ''): + logger.info('[SUCCESS] Submitted proposal with id: {}'.format(election.id)) + return election.id + else: + logger.error('Failed to commit election proposal') + return False + + def run_election_approve(args, bigchain): """Approve an election diff --git a/bigchaindb/common/schema/transaction_v2.0.yaml b/bigchaindb/common/schema/transaction_v2.0.yaml index 562c0d86..30c04064 100644 --- a/bigchaindb/common/schema/transaction_v2.0.yaml +++ b/bigchaindb/common/schema/transaction_v2.0.yaml @@ -63,6 +63,7 @@ definitions: - CREATE - TRANSFER - VALIDATOR_ELECTION + - MIGRATION_ELECTION - VOTE asset: type: object