forked from LaconicNetwork/cosmos-explorer
Finish validator detail
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
export default class BlockData {
|
||||
constructor() {
|
||||
this.txs = []
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new BlockData()
|
||||
self.txs = element.txs
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import BlockId from './block-id'
|
||||
|
||||
export default class BlockHeader {
|
||||
constructor() {
|
||||
this.version = {
|
||||
block: '0',
|
||||
}
|
||||
this.chain_id = ''
|
||||
this.height = 0
|
||||
this.time = '2021-08-02T01:12:43.42506492Z'
|
||||
this.last_block_id = new BlockId()
|
||||
this.last_commit_hash = ''
|
||||
this.data_hash = ''
|
||||
this.validators_hash = ''
|
||||
this.next_validators_hash = ''
|
||||
this.consensus_hash = ''
|
||||
this.app_hash = ''
|
||||
this.last_results_hash = ''
|
||||
this.evidence_hash = ''
|
||||
this.proposer_address = ''
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new BlockHeader()
|
||||
self.version = element.version
|
||||
self.chain_id = element.chain_id
|
||||
self.height = element.height
|
||||
self.time = element.time
|
||||
self.last_block_id = element.last_block_id
|
||||
self.last_commit_hash = element.last_commit_hash
|
||||
self.data_hash = element.data_hash
|
||||
self.validators_hash = element.validators_hash
|
||||
self.next_validators_hash = element.next_validators_hash
|
||||
self.consensus_hash = element.consensus_hash
|
||||
self.app_hash = element.app_hash
|
||||
self.last_results_hash = element.last_results_hash
|
||||
self.evidence_hash = element.evidence_hash
|
||||
self.proposer_address = element.proposer_address
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export default class BlockId {
|
||||
constructor() {
|
||||
this.hash = ''
|
||||
this.parts = { total: 0, hash: '' }
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new BlockId()
|
||||
self.hash = element.hash
|
||||
self.parts = element.parts
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import BlockData from './block-data'
|
||||
import BlockHeader from './block-header'
|
||||
import BlockLastCommit from './block-last-commit'
|
||||
|
||||
export default class BlockInner {
|
||||
constructor() {
|
||||
this.header = new BlockHeader()
|
||||
this.data = new BlockData()
|
||||
this.evidence = { evidence: [] }
|
||||
this.last_commit = new BlockLastCommit()
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new BlockInner()
|
||||
self.header = BlockHeader.create(element.header)
|
||||
self.data = BlockData.create(element.data)
|
||||
self.evidence = element.evidence
|
||||
self.last_commit = BlockLastCommit.create(element.last_commit)
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import BlockId from './block-id'
|
||||
import Signature from './signature'
|
||||
|
||||
export default class BlockLastCommit {
|
||||
constructor() {
|
||||
this.height = 0
|
||||
this.round = 0
|
||||
this.block_id = new BlockId()
|
||||
this.signatures = []
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new BlockLastCommit()
|
||||
self.height = Number(element.height)
|
||||
self.round = Number(element.round)
|
||||
self.block_id = element.block_id
|
||||
self.signatures = element.signatures.map(x => Signature.create(x))
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import BlockId from './block-id'
|
||||
import BlockInner from './block-inner'
|
||||
|
||||
export default class Block {
|
||||
constructor() {
|
||||
this.block_id = new BlockId()
|
||||
this.block = new BlockInner()
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new Block()
|
||||
self.block_id = BlockId.create(element.block_id)
|
||||
self.block = BlockInner.create(element.block)
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import dayjs from 'dayjs'
|
||||
import {
|
||||
Bech32, fromBase64, fromHex, toHex,
|
||||
} from '@cosmjs/encoding'
|
||||
import { sha256 } from '@cosmjs/crypto'
|
||||
|
||||
export function toDay(time) {
|
||||
return dayjs(time).format('YYYY-MM-DD HH:mm')
|
||||
@@ -23,6 +27,22 @@ export function tokenFormatter(tokens) {
|
||||
return formatToken(tokens)
|
||||
}
|
||||
|
||||
export function operatorAddressToAccount(operAddress) {
|
||||
const { prefix, data } = Bech32.decode(operAddress)
|
||||
return Bech32.encode(prefix.replace('valoper', ''), data)
|
||||
}
|
||||
|
||||
export function consensusPubkeyToHexAddress(consensusPubkey) {
|
||||
let raw = null
|
||||
if (typeof consensusPubkey === 'object') {
|
||||
raw = toHex(fromBase64(consensusPubkey.value))
|
||||
} else {
|
||||
raw = toHex(Bech32.decode(consensusPubkey).data).toUpperCase().replace('1624DE6420', '')
|
||||
}
|
||||
const address = toHex(sha256(fromHex(raw))).slice(0, 40).toUpperCase()
|
||||
return address
|
||||
}
|
||||
|
||||
export * from 'compare-versions'
|
||||
|
||||
export class Data {
|
||||
|
||||
@@ -6,6 +6,9 @@ export { default as Votes } from './votes'
|
||||
export { default as Deposit } from './deposit'
|
||||
export { default as Validator } from './validator'
|
||||
export { default as StakingParameters } from './staking-parameters'
|
||||
export { default as Block } from './block'
|
||||
export { default as ValidatorDistribution } from './validator-distribution'
|
||||
export { default as StakingDelegation } from './staking-delegation'
|
||||
export * from './data'
|
||||
|
||||
export default class Test {}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
export default class Signature {
|
||||
constructor() {
|
||||
this.block_id_flag = 2
|
||||
this.validator_address = ''
|
||||
this.timestamp = ''
|
||||
this.signature = ''
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new Signature()
|
||||
self.block_id_flag = element.block_id_flag
|
||||
self.validator_address = element.validator_address
|
||||
self.timestamp = element.timestamp
|
||||
self.signature = element.signature
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export default class StakingDelegation {
|
||||
constructor() {
|
||||
this.delegation = {}
|
||||
this.balance = {}
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new StakingDelegation()
|
||||
self.delegation = element.delegation
|
||||
self.balance = element.balance
|
||||
return self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import compareVersions from 'compare-versions'
|
||||
|
||||
export default class ValidatorDistribution {
|
||||
constructor() {
|
||||
this.element = {}
|
||||
this.operator_address = ''
|
||||
this.self_bond_rewards = []
|
||||
this.val_commission = []
|
||||
}
|
||||
|
||||
static create(element) {
|
||||
const self = new ValidatorDistribution()
|
||||
self.element = element
|
||||
self.operator_address = element.operator_address
|
||||
self.self_bond_rewards = element.self_bond_rewards
|
||||
self.val_commission = element.val_commission
|
||||
return self
|
||||
}
|
||||
|
||||
versionFixed(ver) {
|
||||
if (compareVersions(ver, '0.40') >= 0) {
|
||||
this.val_commission = this.element.val_commission.commission
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ export default class Validator {
|
||||
this.unbonding_height = 0
|
||||
this.unbonding_time = '1970-01-01T00:00:00Z'
|
||||
this.commission = new ValidatorCommission()
|
||||
this.min_self_delegation = 1
|
||||
}
|
||||
|
||||
init(element) {
|
||||
@@ -30,6 +31,7 @@ export default class Validator {
|
||||
this.unbonding_height = element.unbonding_height
|
||||
this.unbonding_time = element.unbonding_time
|
||||
this.commission = new ValidatorCommission().init(element.commission)
|
||||
this.min_self_delegation = element.min_self_delegation
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user