Problem: MigrationElection needed to be added to the list of allowed operations

Solution: Added it
This commit is contained in:
z-bowen 2018-09-12 14:12:02 +02:00
parent 4493cad6d6
commit 3f81e7eeaa
3 changed files with 38 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import logging
from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config from bigchaindb.log import DEFAULT_LOGGING_CONFIG as log_config
from bigchaindb.lib import BigchainDB # noqa from bigchaindb.lib import BigchainDB # noqa
from bigchaindb.migrations.migration_election import MigrationElection
from bigchaindb.version import __version__ # noqa from bigchaindb.version import __version__ # noqa
from bigchaindb.core import App # 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.CREATE, models.Transaction)
Transaction.register_type(Transaction.TRANSFER, models.Transaction) Transaction.register_type(Transaction.TRANSFER, models.Transaction)
Transaction.register_type(ValidatorElection.OPERATION, ValidatorElection) Transaction.register_type(ValidatorElection.OPERATION, ValidatorElection)
Transaction.register_type(MigrationElection.OPERATION, MigrationElection)
Transaction.register_type(Vote.OPERATION, Vote) Transaction.register_type(Vote.OPERATION, Vote)

View File

@ -13,6 +13,7 @@ import copy
import json import json
import sys import sys
from bigchaindb.migrations.migration_election import MigrationElection
from bigchaindb.utils import load_node_key from bigchaindb.utils import load_node_key
from bigchaindb.common.exceptions import (DatabaseDoesNotExist, from bigchaindb.common.exceptions import (DatabaseDoesNotExist,
ValidationError) ValidationError)
@ -159,6 +160,40 @@ def run_election_new_upsert_validator(args, bigchain):
return False 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): def run_election_approve(args, bigchain):
"""Approve an election """Approve an election

View File

@ -63,6 +63,7 @@ definitions:
- CREATE - CREATE
- TRANSFER - TRANSFER
- VALIDATOR_ELECTION - VALIDATOR_ELECTION
- MIGRATION_ELECTION
- VOTE - VOTE
asset: asset:
type: object type: object