mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
moved show_election_status to planetmint
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
789ca8476d
commit
a4a08c64ae
@ -226,7 +226,7 @@ def run_election_show(args, planet):
|
||||
logger.error(f"No election found with election_id {args.election_id}")
|
||||
return
|
||||
|
||||
response = election.show_election(planet)
|
||||
response = planet.show_election_status(election)
|
||||
|
||||
logger.info(response)
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ MongoDB.
|
||||
|
||||
"""
|
||||
import logging
|
||||
import json
|
||||
from collections import namedtuple
|
||||
from uuid import uuid4
|
||||
|
||||
@ -20,7 +21,7 @@ import requests
|
||||
import planetmint
|
||||
from planetmint.config import Config
|
||||
from planetmint import backend, config_utils, fastquery
|
||||
from planetmint.transactions.common.transaction import VALIDATOR_ELECTION, Transaction
|
||||
from planetmint.transactions.common.transaction import CHAIN_MIGRATION_ELECTION, VALIDATOR_ELECTION, Transaction
|
||||
from planetmint.transactions.common.exceptions import (
|
||||
DuplicateTransaction,
|
||||
InvalidSignature,
|
||||
@ -42,7 +43,7 @@ from planetmint.transactions.common.transaction_mode_types import (
|
||||
BROADCAST_TX_ASYNC,
|
||||
BROADCAST_TX_SYNC,
|
||||
)
|
||||
from planetmint.tendermint_utils import encode_transaction, merkleroot, key_from_base64
|
||||
from planetmint.tendermint_utils import encode_transaction, merkleroot, key_from_base64, public_key_to_base64
|
||||
from planetmint import exceptions as core_exceptions
|
||||
from planetmint.transactions.types.elections.election import Election
|
||||
from planetmint.validation import BaseValidationRules
|
||||
@ -741,4 +742,40 @@ class Planetmint(object):
|
||||
|
||||
return recipients
|
||||
|
||||
def show_election_status(self, transaction):
|
||||
data = transaction.asset["data"]
|
||||
if "public_key" in data.keys():
|
||||
data["public_key"] = public_key_to_base64(data["public_key"]["value"])
|
||||
response = ""
|
||||
for k, v in data.items():
|
||||
if k != "seed":
|
||||
response += f"{k}={v}\n"
|
||||
response += f"status={self.get_election_status(transaction)}"
|
||||
|
||||
if transaction.operation == CHAIN_MIGRATION_ELECTION:
|
||||
response = self.append_chain_migration_status(response)
|
||||
|
||||
return response
|
||||
|
||||
def append_chain_migration_status(self, status):
|
||||
chain = self.get_latest_abci_chain()
|
||||
if chain is None or chain["is_synced"]:
|
||||
return status
|
||||
|
||||
status += f'\nchain_id={chain["chain_id"]}'
|
||||
block = self.get_latest_block()
|
||||
status += f'\napp_hash={block["app_hash"]}'
|
||||
validators = [
|
||||
{
|
||||
"pub_key": {
|
||||
"type": "tendermint/PubKeyEd25519",
|
||||
"value": k,
|
||||
},
|
||||
"power": v,
|
||||
}
|
||||
for k, v in self.get_validator_dict().items()
|
||||
]
|
||||
status += f"\nvalidators={json.dumps(validators, indent=4)}"
|
||||
return status
|
||||
|
||||
Block = namedtuple("Block", ("app_hash", "height", "transactions"))
|
||||
|
||||
@ -24,27 +24,5 @@ class ChainMigrationElection(Election):
|
||||
def on_approval(self, planet, *args, **kwargs): # TODO: move somewhere else
|
||||
planet.migrate_abci_chain()
|
||||
|
||||
def show_election(self, planet): # TODO: move somewhere else
|
||||
output = super().show_election(planet)
|
||||
chain = planet.get_latest_abci_chain()
|
||||
if chain is None or chain["is_synced"]:
|
||||
return output
|
||||
|
||||
output += f'\nchain_id={chain["chain_id"]}'
|
||||
block = planet.get_latest_block()
|
||||
output += f'\napp_hash={block["app_hash"]}'
|
||||
validators = [
|
||||
{
|
||||
"pub_key": {
|
||||
"type": "tendermint/PubKeyEd25519",
|
||||
"value": k,
|
||||
},
|
||||
"power": v,
|
||||
}
|
||||
for k, v in planet.get_validator_dict().items()
|
||||
]
|
||||
output += f"\nvalidators={json.dumps(validators, indent=4)}"
|
||||
return output
|
||||
|
||||
def on_rollback(self, planet, new_height): # TODO: move somewhere else
|
||||
planet.delete_abci_chain(new_height)
|
||||
|
||||
@ -134,18 +134,6 @@ class Election(Transaction):
|
||||
|
||||
return False
|
||||
|
||||
def show_election(self, planet): # TODO: move somewhere else
|
||||
data = self.asset["data"]
|
||||
if "public_key" in data.keys():
|
||||
data["public_key"] = public_key_to_base64(data["public_key"]["value"])
|
||||
response = ""
|
||||
for k, v in data.items():
|
||||
if k != "seed":
|
||||
response += f"{k}={v}\n"
|
||||
response += f"status={planet.get_election_status(self)}"
|
||||
|
||||
return response
|
||||
|
||||
@classmethod
|
||||
def _get_initiated_elections(cls, height, txns): # TODO: move somewhere else
|
||||
elections = []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user