From 52de37764406e59bbc9fee6f28b9b02a6eb5557b Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Mon, 27 Mar 2023 09:59:27 +0800 Subject: [PATCH] rpc endpoint version --- packages/dashboard/chains/mainnet/cosmos.json | 29 +-- .../src/components/ProposalProcess.vue | 17 +- .../components/ValidatorCommissionRate.vue | 155 ++++++++++++ .../components/dynamic/ArrayBytesElement.vue | 15 ++ .../src/components/dynamic/ArrayElement.vue | 31 +++ .../components/dynamic/ArrayObjectElement.vue | 30 +++ .../components/dynamic/DynamicComponent.vue | 11 + .../src/components/dynamic/NumberElement.vue | 6 + .../src/components/dynamic/ObjectElement.vue | 19 ++ .../src/components/dynamic/TextElement.vue | 6 + .../src/components/dynamic/TxsElement.vue | 35 +++ .../src/components/dynamic/UInt8Array.vue | 16 ++ .../dashboard/src/components/dynamic/index.ts | 37 +++ packages/dashboard/src/libs/address.ts | 51 +++- packages/dashboard/src/libs/client.rpc.ts | 33 ++- packages/dashboard/src/libs/misc.ts | 6 + .../dashboard/src/modules/[chain]/block.ts | 38 --- .../src/modules/[chain]/block/[height].vue | 58 +++++ .../src/modules/[chain]/block/block.ts | 62 +++++ .../src/modules/[chain]/block/index.vue | 74 ++++++ .../dashboard/src/modules/[chain]/index.vue | 6 +- .../src/modules/[chain]/indexStore.ts | 19 +- .../modules/[chain]/staking/[validator].vue | 223 +++++++++++++++++- .../src/modules/[chain]/staking/index.vue | 60 ++--- .../src/modules/[chain]/tx/[hash].vue | 66 ++++++ packages/dashboard/src/stores/useBaseStore.ts | 5 +- .../dashboard/src/stores/useBlockchain.ts | 7 +- packages/dashboard/src/stores/useFormatter.ts | 50 +++- packages/dashboard/src/stores/useGovStore.ts | 4 +- packages/dashboard/src/stores/useMintStore.ts | 11 +- .../dashboard/src/stores/useStakingStore.ts | 6 +- 31 files changed, 1037 insertions(+), 149 deletions(-) create mode 100644 packages/dashboard/src/components/ValidatorCommissionRate.vue create mode 100644 packages/dashboard/src/components/dynamic/ArrayBytesElement.vue create mode 100644 packages/dashboard/src/components/dynamic/ArrayElement.vue create mode 100644 packages/dashboard/src/components/dynamic/ArrayObjectElement.vue create mode 100644 packages/dashboard/src/components/dynamic/DynamicComponent.vue create mode 100644 packages/dashboard/src/components/dynamic/NumberElement.vue create mode 100644 packages/dashboard/src/components/dynamic/ObjectElement.vue create mode 100644 packages/dashboard/src/components/dynamic/TextElement.vue create mode 100644 packages/dashboard/src/components/dynamic/TxsElement.vue create mode 100644 packages/dashboard/src/components/dynamic/UInt8Array.vue create mode 100644 packages/dashboard/src/components/dynamic/index.ts delete mode 100644 packages/dashboard/src/modules/[chain]/block.ts create mode 100644 packages/dashboard/src/modules/[chain]/block/[height].vue create mode 100644 packages/dashboard/src/modules/[chain]/block/block.ts create mode 100644 packages/dashboard/src/modules/[chain]/block/index.vue create mode 100644 packages/dashboard/src/modules/[chain]/tx/[hash].vue diff --git a/packages/dashboard/chains/mainnet/cosmos.json b/packages/dashboard/chains/mainnet/cosmos.json index 71193408..338532b7 100644 --- a/packages/dashboard/chains/mainnet/cosmos.json +++ b/packages/dashboard/chains/mainnet/cosmos.json @@ -7,38 +7,11 @@ "address": "http://rpc-cosmoshub.freshstaking.com:26657/", "provider": "FreshSTAKING" }, - { - "address": "https://rpc.cosmos.bh.rocks/", - "provider": "BlockHunters 🎯" - }, - { - "address": "https://cosmoshub-rpc.lavenderfive.com/", - "provider": "Lavender.Five Nodes 🐝" - }, { "address": "https://cosmos-rpc.polkachu.com/", "provider": "Polkachu" }, - { - "address": "https://rpc.cosmos.dragonstake.io/", - "provider": "DragonStake" - }, - { - "address": "https://cosmos-rpc.rockrpc.net/", - "provider": "RockawayX Infra" - }, - { - "address": "https://rpc-cosmoshub.pupmos.network/", - "provider": "PUPMØS" - }, - { - "address": "https://cosmos-rpc.icycro.org/", - "provider": "IcyCRO 🧊" - }, - { - "address": "https://rpc.cosmos.interbloc.org/", - "provider": "Interbloc" - }, + { "address": "https://rpc.cosmoshub.strange.love/", "provider": "strangelove-ventures" diff --git a/packages/dashboard/src/components/ProposalProcess.vue b/packages/dashboard/src/components/ProposalProcess.vue index a66b9bef..09b5d065 100644 --- a/packages/dashboard/src/components/ProposalProcess.vue +++ b/packages/dashboard/src/components/ProposalProcess.vue @@ -8,21 +8,24 @@ const props = defineProps({ tally: { type: Object as PropType<{ yes: string, no: string, - no_with_veto: string, + noWithVeto: string, abstain: string }>}, pool: { type: Object as PropType<{ - not_bonded_tokens: string; - bonded_tokens: string; + notBondedTokens: string; + bondedTokens: string; }>, }, }) const format = useFormatter() -const yes = computed(() => (format.calculatePercent(props.tally?.yes, props.pool?.bonded_tokens))) -const no = computed(() => ref(format.calculatePercent(props.tally?.no, props.pool?.bonded_tokens))) -const abstain = computed(() => (format.calculatePercent(props.tally?.abstain, props.pool?.bonded_tokens))) -const veto = computed(() => (format.calculatePercent(props.tally?.no_with_veto, props.pool?.bonded_tokens))) +const yes = computed(() => (format.calculatePercent(props.tally?.yes, props.pool?.bondedTokens))) +const no = computed(() => ref(format.calculatePercent(props.tally?.no, props.pool?.bondedTokens))) +const abstain = computed(() => (format.calculatePercent(props.tally?.abstain, props.pool?.bondedTokens))) +const veto = computed(() => (format.calculatePercent(props.tally?.noWithVeto, props.pool?.bondedTokens))) + + +console.log(yes.value, no.value, abstain.value, veto.value) + diff --git a/packages/dashboard/src/modules/[chain]/staking/index.vue b/packages/dashboard/src/modules/[chain]/staking/index.vue index 2c45735c..5c10b81e 100644 --- a/packages/dashboard/src/modules/[chain]/staking/index.vue +++ b/packages/dashboard/src/modules/[chain]/staking/index.vue @@ -1,9 +1,11 @@ + \ No newline at end of file diff --git a/packages/dashboard/src/stores/useBaseStore.ts b/packages/dashboard/src/stores/useBaseStore.ts index a0bc9d7f..dd964e7c 100644 --- a/packages/dashboard/src/stores/useBaseStore.ts +++ b/packages/dashboard/src/stores/useBaseStore.ts @@ -59,9 +59,12 @@ export const useBaseStore = defineStore('baseStore', { async fetchLatestValidators(offset = 0) { return this.blockchain.rpc.validatorsAtHeight() }, - async fetchBlock(height: number) { + async fetchBlock(height?: number) { return this.blockchain.rpc.block(height) }, + async fetchAbciInfo() { + return this.blockchain.rpc.abciInfo() + } // async fetchNodeInfo() { // return this.blockchain.rpc.no() // } diff --git a/packages/dashboard/src/stores/useBlockchain.ts b/packages/dashboard/src/stores/useBlockchain.ts index 1a75b91d..08201fae 100644 --- a/packages/dashboard/src/stores/useBlockchain.ts +++ b/packages/dashboard/src/stores/useBlockchain.ts @@ -9,6 +9,8 @@ import { useBaseStore } from "./useBaseStore"; import { useGovStore } from "./useGovStore"; import { RPCClient } from '../libs/client.rpc' import { ref } from "vue"; +import { useMintStore } from "./useMintStore"; +import { useBlockModule } from "@/modules/[chain]/block/block"; export const useBlockchain = defineStore("blockchain", { state: () => { @@ -94,14 +96,13 @@ export const useBlockchain = defineStore("blockchain", { }, actions: { async initial() { - console.log('begin Setup') await this.randomSetupEndpoint() - console.log('rpc setup') await useStakingStore().init() useBankStore().initial() useBaseStore().initial() useGovStore().initial() - + useMintStore().initial() + useBlockModule().initial() }, async randomSetupEndpoint() { diff --git a/packages/dashboard/src/stores/useFormatter.ts b/packages/dashboard/src/stores/useFormatter.ts index 1fc32f55..57feeca8 100644 --- a/packages/dashboard/src/stores/useFormatter.ts +++ b/packages/dashboard/src/stores/useFormatter.ts @@ -9,6 +9,9 @@ import updateLocale from 'dayjs/plugin/updateLocale' import utc from 'dayjs/plugin/utc' import localeData from 'dayjs/plugin/localeData' import type { PoolSDKType } from "@ping-pub/codegen/src/cosmos/staking/v1beta1/staking"; +import { useStakingStore } from "./useStakingStore"; +import { fromBech32, toBase64, toHex } from "@cosmjs/encoding"; +import { consensusPubkeyToHexAddress, operatorAddressToAccount } from "@/libs"; dayjs.extend(localeData) dayjs.extend(duration) @@ -41,6 +44,9 @@ export const useFormatter = defineStore('formatter', { getters: { blockchain() { return useBlockchain() + }, + staking() { + return useStakingStore() } }, actions: { @@ -56,7 +62,7 @@ export const useFormatter = defineStore('formatter', { let denom = token.denom const conf = this.blockchain.current?.assets?.find(x => x.base === token.denom || x.base.denom === token.denom) if(conf) { - let unit = {exponent: 0, denom: ''} + let unit = {exponent: 6, denom: ''} // find the max exponent for display conf.denom_units.forEach(x => { if(x.exponent >= unit.exponent) { @@ -64,7 +70,7 @@ export const useFormatter = defineStore('formatter', { } }) if(unit && unit.exponent > 0) { - amount = amount / Math.pow(10, unit?.exponent) + amount = amount / Math.pow(10, unit.exponent || 6) denom = unit.denom.toUpperCase() } } @@ -72,8 +78,9 @@ export const useFormatter = defineStore('formatter', { } return '-' }, - formatTokens(tokens: { denom: string, amount: string;}[], withDenom = true) : string { - return tokens.map(x => this.formatToken(x, withDenom)).join(', ') + formatTokens(tokens?: { denom: string, amount: string;}[], withDenom = true, fmt='0.0a') : string { + if(!tokens) return '' + return tokens.map(x => this.formatToken(x, withDenom, fmt)).join(', ') }, calculateBondedRatio(pool: {bonded_tokens: string, not_bonded_tokens: string}|undefined) { if(pool && pool.bonded_tokens) { @@ -85,6 +92,11 @@ export const useFormatter = defineStore('formatter', { } return '-' }, + validator(address: Uint8Array) { + const txt = toHex(address).toUpperCase() + const validator = this.staking.validators.find(x => consensusPubkeyToHexAddress(x.consensusPubkey) === txt) + return validator?.description?.moniker + }, calculatePercent(input?: string, total?: string|number ) { if(!input || !total) return '0' const percent = Number(input)/Number(total) @@ -93,7 +105,13 @@ export const useFormatter = defineStore('formatter', { formatDecimalToPercent(decimal: string) { return numeral(decimal).format('0.[00]%') }, - percent(decimal?: string) { + formatCommissionRate(v?: string) { + console.log(v) + if(!v) return '-' + const rate = Number(v) / Number("1000000000000000000") + return this.percent(rate) + }, + percent(decimal?: string|number) { return decimal ? numeral(decimal).format('0.[00]%') : '-' }, numberAndSign(input: number, fmt="+0,0") { @@ -117,7 +135,27 @@ export const useFormatter = defineStore('formatter', { return dayjs(time).toNow() } return dayjs(time).format('YYYY-MM-DD HH:mm:ss') - } + }, + messages(msgs: {typeUrl: string}[]) { + if(msgs) { + const sum: Record = msgs.map(msg => { + return msg.typeUrl.substring(msg.typeUrl.lastIndexOf('.') + 1).replace('Msg', '') + }).reduce((s, c) => { + const sh: Record = s + if (sh[c]) { + sh[c] += 1 + } else { + sh[c] = 1 + } + return sh + }, {}) + const output: string[] = [] + Object.keys(sum).forEach(k => { + output.push(sum[k] > 1 ? `${k}×${sum[k]}` : k) + }) + return output.join(', ') + } + }, } }) diff --git a/packages/dashboard/src/stores/useGovStore.ts b/packages/dashboard/src/stores/useGovStore.ts index 9f9c74a3..e6d5ca1a 100644 --- a/packages/dashboard/src/stores/useGovStore.ts +++ b/packages/dashboard/src/stores/useGovStore.ts @@ -33,7 +33,9 @@ export const useGovStore = defineStore('govStore', { depositor: '', pagination, } - return this.blockchain.rpc.proposals(proposalStatus, '', '') + const proposals = await this.blockchain.rpc.proposals(proposalStatus, '', '') + console.log(proposals) + return proposals }, async fetchParams() { // this.blockchain.rpc.govParam().then(x => { diff --git a/packages/dashboard/src/stores/useMintStore.ts b/packages/dashboard/src/stores/useMintStore.ts index 6b6cb97a..acf6e14c 100644 --- a/packages/dashboard/src/stores/useMintStore.ts +++ b/packages/dashboard/src/stores/useMintStore.ts @@ -5,11 +5,11 @@ import { createMintClientForChain } from "@/libs/client"; import { createRpcQueryExtension } from '@ping-pub/codegen/src/cosmos/mint/v1beta1/query.rpc.Query' import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; import { QueryClient, setupMintExtension } from "@cosmjs/stargate"; - +import { cosmos } from '@ping-pub/codegen' export const useMintStore = defineStore('mintStore', { state: () => { return { - inflation: "", + inflation: "0", } }, getters: { @@ -18,11 +18,14 @@ export const useMintStore = defineStore('mintStore', { } }, actions: { + initial() { + this.fetchInflation() + }, async fetchInflation() { this.blockchain.rpc.inflation().then(x => { - this.inflation = String(x) + this.inflation = x.inflation }).catch(err => { - this.inflation = "" + this.inflation = "0" }) } } diff --git a/packages/dashboard/src/stores/useStakingStore.ts b/packages/dashboard/src/stores/useStakingStore.ts index 9894bef9..1fcd74f2 100644 --- a/packages/dashboard/src/stores/useStakingStore.ts +++ b/packages/dashboard/src/stores/useStakingStore.ts @@ -5,12 +5,13 @@ import type { Params, Pool, Validator} from "@ping-pub/codegen/src/cosmos/stakin import { get } from "@/libs/http"; import type { BondStatusString } from "@/libs/client.rpc"; +import type { QueryParamsResponse } from "@ping-pub/codegen/src/cosmos/staking/v1beta1/query"; export const useStakingStore = defineStore('stakingStore', { state: () => { return { validators: [] as Validator[], - params: {} , + params: {} as QueryParamsResponse, pool: {} as Pool | undefined, } }, @@ -51,6 +52,9 @@ export const useStakingStore = defineStore('stakingStore', { async fetchValidator(validatorAddr: string) { return this.blockchain.rpc.validator(validatorAddr) }, + async fetchValidatorDelegation(validatorAddr: string, delegatorAddr: string) { + return (await this.blockchain.rpc.validatorDelegation(validatorAddr, delegatorAddr)).delegationResponse + }, async fetchValidators(status: BondStatusString) { return this.blockchain.rpc.validators(status, undefined).then(res => { const vals = res.validators.sort((a, b) => (Number(b.delegatorShares) - Number(a.delegatorShares)))