diff --git a/package.json b/package.json index c1f0fb3e..aded964e 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dependencies": { "@chenfengyuan/vue-countdown": "2", "@cosmjs/tendermint-rpc": "^0.32.2", + "cosmjs-types": "^0.9.0", "@cosmjs/stargate": "^0.32.2", "@cosmjs/crypto": "^0.32.2", "@cosmjs/encoding": "^0.32.2", diff --git a/src/components/dynamic/TxsElement.vue b/src/components/dynamic/TxsElement.vue index d90acd04..0e669e54 100644 --- a/src/components/dynamic/TxsElement.vue +++ b/src/components/dynamic/TxsElement.vue @@ -5,14 +5,16 @@ import { computed } from '@vue/reactivity'; import { hashTx } from '@/libs'; import { useBlockchain, useFormatter } from '@/stores'; const props = defineProps({ - value: { type: Array }, + value: { type: Array }, }); const txs = computed(() => { - return props.value?.map((x) => ({ - hash: hashTx(fromBase64(x)), - tx: decodeTxRaw(fromBase64(x)), - })) || [] + return ( + props.value?.map((x) => ({ + hash: hashTx(x), + tx: decodeTxRaw(x), + })) || [] + ); }); const format = useFormatter(); @@ -23,7 +25,7 @@ const chain = useBlockchain(); - + @@ -31,9 +33,11 @@ const chain = useBlockchain();
HashHash Msgs Memo
- {{ - item.hash - }} + {{ item.hash }} {{ diff --git a/src/libs/address.ts b/src/libs/address.ts index ade9ab2b..8e39c290 100644 --- a/src/libs/address.ts +++ b/src/libs/address.ts @@ -7,6 +7,7 @@ import { toHex, } from '@cosmjs/encoding'; import { Ripemd160, sha256 } from '@cosmjs/crypto'; +import type { Any } from 'cosmjs-types/google/protobuf/any'; export function decodeAddress(address: string) { return fromBech32(address); @@ -33,30 +34,24 @@ export function operatorAddressToAccount(operAddress?: string) { return toBech32(prefix.replace('valoper', ''), data); } -export function consensusPubkeyToHexAddress(consensusPubkey?: { - '@type': string; - key: string; -}) { +export function consensusPubkeyToHexAddress(consensusPubkey?: Any) { if (!consensusPubkey) return ''; let raw = ''; - if (consensusPubkey['@type'] === '/cosmos.crypto.ed25519.PubKey') { - const pubkey = fromBase64(consensusPubkey.key); + if (consensusPubkey.typeUrl === '/cosmos.crypto.ed25519.PubKey') { + const pubkey = consensusPubkey.value; if (pubkey) return toHex(sha256(pubkey)).slice(0, 40).toUpperCase(); } - if (consensusPubkey['@type'] === '/cosmos.crypto.secp256k1.PubKey') { - const pubkey = fromBase64(consensusPubkey.key); + if (consensusPubkey.typeUrl === '/cosmos.crypto.secp256k1.PubKey') { + const pubkey = consensusPubkey.value; if (pubkey) return toHex(new Ripemd160().update(sha256(pubkey)).digest()); } return raw; } -export function pubKeyToValcons( - consensusPubkey: { '@type': string; key: string }, - prefix: string -) { - if (consensusPubkey && consensusPubkey.key) { - const pubkey = fromBase64(consensusPubkey.key); +export function pubKeyToValcons(consensusPubkey: Any, prefix: string) { + if (consensusPubkey && consensusPubkey.value) { + const pubkey = consensusPubkey.value; if (pubkey) { const addressData = sha256(pubkey).slice(0, 20); return toBech32(`${prefix}valcons`, addressData); diff --git a/src/libs/client.ts b/src/libs/client.ts index fcda050a..0b8277a5 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -462,9 +462,9 @@ export class CosmosRestClient extends BaseRestClient { // this.registry.staking_validators_delegations_delegator, // { validator_addr, delegator_addr } // ); - const res = await this.queryClient.staking.delegatorValidator( - validator_addr, - delegator_addr + const res = await this.queryClient.staking.delegation( + delegator_addr, + validator_addr ); console.log(res); return res; @@ -498,9 +498,9 @@ export class CosmosRestClient extends BaseRestClient { return res; // return this.request(this.registry.base_tendermint_block_latest, {}); } - async getBaseBlockAt(height: string | number) { + async getBaseBlockAt(height: string | number | undefined) { // return this.request(this.registry.base_tendermint_block_height, { height }); - const res = await this.tmClient.block(Number(height)); + const res = await this.tmClient.block(height ? Number(height) : undefined); console.log(res); return res; } @@ -559,6 +559,8 @@ export class CosmosRestClient extends BaseRestClient { }), order_by: page?.reverse ? 'desc' : 'asc', }); + console.log(res); + return res; } // query ibc sending msgs // ?&pagination.reverse=true&events=send_packet.packet_src_channel='${channel}'&events=send_packet.packet_src_port='${port}' diff --git a/src/modules/[chain]/block/[height].vue b/src/modules/[chain]/block/[height].vue index 34e55542..362a1654 100644 --- a/src/modules/[chain]/block/[height].vue +++ b/src/modules/[chain]/block/[height].vue @@ -8,12 +8,13 @@ import { onBeforeRouteUpdate } from 'vue-router'; import { useBaseStore, useFormatter } from '@/stores'; import type { Block } from '@/types'; import Countdown from '@/components/Countdown.vue'; +import type { BlockResponse } from '@cosmjs/tendermint-rpc'; const props = defineProps(['height', 'chain']); const store = useBaseStore(); const format = useFormatter() -const current = ref({} as Block) +const current = ref({} as BlockResponse) const target = ref(Number(props.height || 0)) const height = computed(() => { @@ -24,7 +25,7 @@ const isFutureBlock = computed({ get: () => { const latest = store.latest?.block?.header.height const isFuture = latest ? target.value > Number(latest) : true - if (!isFuture && !current.value.block_id) store.fetchBlock(target.value).then(x => current.value = x) + if (!isFuture && !current.value.blockId) store.fetchBlock(target.value).then(x => current.value = x) return isFuture }, set: val => { @@ -120,7 +121,7 @@ onBeforeRouteUpdate(async (to, from, next) => {
- +
@@ -131,12 +132,12 @@ onBeforeRouteUpdate(async (to, from, next) => {

{{ $t('account.transactions') }}

- +

{{ $t('block.last_commit') }}

- +
diff --git a/src/modules/[chain]/indexStore.ts b/src/modules/[chain]/indexStore.ts index 4b503292..d1325ca7 100644 --- a/src/modules/[chain]/indexStore.ts +++ b/src/modules/[chain]/indexStore.ts @@ -10,6 +10,7 @@ import { useDistributionStore } from '@/stores/useDistributionStore'; import { useMintStore } from '@/stores/useMintStore'; import { useStakingStore } from '@/stores/useStakingStore'; import type { Coin, Tally } from '@/types'; +import type { Pool } from 'cosmjs-types/cosmos/staking/v1beta1/staking'; import numeral from 'numeral'; import { defineStore } from 'pinia'; @@ -148,8 +149,6 @@ export const useIndexModule = defineStore('module-index', { const mintStore = useMintStore(); const formatter = useFormatter(); - console.log('base', JSON.stringify(base, null, 2)); - return [ { title: 'Height', @@ -163,7 +162,7 @@ export const useIndexModule = defineStore('module-index', { color: 'error', icon: 'mdi-human-queue', stats: String( - base?.latest?.block?.last_commit?.signatures.length || 0 + base?.latest?.block?.lastCommit?.signatures.length || 0 ), change: 0, }, @@ -179,9 +178,8 @@ export const useIndexModule = defineStore('module-index', { color: 'warning', icon: 'mdi-lock', stats: formatter.formatTokenAmount({ - // @ts-ignore - amount: this.pool.bonded_tokens, - denom: staking.params.bond_denom, + amount: this.pool.bondedTokens, + denom: staking.params.bondDenom, }), change: 0, }, @@ -199,7 +197,7 @@ export const useIndexModule = defineStore('module-index', { stats: formatter.formatTokens( // @ts-ignore this.communityPool?.filter( - (x: Coin) => x.denom === staking.params.bond_denom + (x: Coin) => x.denom === staking.params.bondDenom ) ), change: 0, diff --git a/src/modules/[chain]/staking/[validator].vue b/src/modules/[chain]/staking/[validator].vue index f3c8222e..f67c424e 100644 --- a/src/modules/[chain]/staking/[validator].vue +++ b/src/modules/[chain]/staking/[validator].vue @@ -15,10 +15,19 @@ import { pubKeyToValcons, valoperToPrefix, } from '@/libs'; -import { PageRequest, type Coin, type Delegation, type PaginatedDelegations, type PaginatedTxs, type Validator } from '@/types'; +import { + PageRequest, + type Coin, + type Delegation, + type PaginatedDelegations, + type PaginatedTxs, + type Validator, +} from '@/types'; import PaginationBar from '@/components/PaginationBar.vue'; import { fromBase64, toBase64 } from '@cosmjs/encoding'; import { stringToUint8Array, uint8ArrayToString } from '@/libs/utils'; +import type { TxSearchResponse } from '@cosmjs/tendermint-rpc'; +import type { DelegationResponse } from 'cosmjs-types/cosmos/staking/v1beta1/staking'; const props = defineProps(['validator', 'chain']); @@ -36,7 +45,7 @@ const avatars = ref(cache || {}); const identity = ref(''); const rewards = ref([] as Coin[] | undefined); const commission = ref([] as Coin[] | undefined); -const delegations = ref({} as PaginatedDelegations) +const delegations = ref({} as PaginatedDelegations); const addresses = ref( {} as { account: string; @@ -45,7 +54,7 @@ const addresses = ref( valCons: string; } ); -const selfBonded = ref({} as Delegation); +const selfBonded = ref({} as DelegationResponse); addresses.value.account = operatorAddressToAccount(validator); // load self bond @@ -53,11 +62,11 @@ staking .fetchValidatorDelegation(validator, addresses.value.account) .then((x) => { if (x) { - selfBonded.value = x.delegation_response; + selfBonded.value = x.delegationResponse!; } }); -const txs = ref({} as PaginatedTxs); +const txs = ref({} as TxSearchResponse); blockchain.rpc.getTxsBySender(addresses.value.account).then((x) => { txs.value = x; @@ -125,7 +134,8 @@ onMounted(() => { staking.fetchValidator(validator).then((res) => { v.value = res.validator; identity.value = res.validator?.description?.identity || ''; - if (identity.value && !avatars.value[identity.value]) loadAvatar(identity.value); + if (identity.value && !avatars.value[identity.value]) + loadAvatar(identity.value); const prefix = valoperToPrefix(v.value.operator_address) || ''; addresses.value.hex = consensusPubkeyToHexAddress( @@ -162,7 +172,6 @@ onMounted(() => { // Disable delegations due to its bad performance // Comment out the following code if you want to enable it // pageload(1) - } }); let showCopyToast = ref(0); @@ -193,62 +202,82 @@ function pageload(p: number) { page.setPage(p); page.limit = 10; - blockchain.rpc.getStakingValidatorsDelegations(validator, page).then(res => { - delegations.value = res - }) + blockchain.rpc + .getStakingValidatorsDelegations(validator, page) + .then((res) => { + delegations.value = res; + }); } -const events = ref({} as PaginatedTxs) +const events = ref({} as PaginatedTxs); enum EventType { Delegate = 'delegate', Unbond = 'unbond', } -const selectedEventType = ref(EventType.Delegate) +const selectedEventType = ref(EventType.Delegate); function loadPowerEvents(p: number, type: EventType) { - selectedEventType.value = type + selectedEventType.value = type; page.setPage(p); page.setPageSize(5); - blockchain.rpc.getTxs("?order_by=2&events={type}.validator='{validator}'", { type: selectedEventType.value, validator }, page).then(res => { - events.value = res - }) + blockchain.rpc + .getTxs( + "?order_by=2&events={type}.validator='{validator}'", + { type: selectedEventType.value, validator }, + page + ) + .then((res) => { + events.value = res; + }); } function pagePowerEvents(page: number) { - loadPowerEvents(page, selectedEventType.value) + loadPowerEvents(page, selectedEventType.value); } -pagePowerEvents(1) +pagePowerEvents(1); -function mapEvents(events: {type: string, attributes: {key: string, value: string}[]}[]) { +function mapEvents( + events: { type: string; attributes: { key: string; value: string }[] }[] +) { const attributes = events - .filter(x => x.type=== selectedEventType.value) - .filter(x => x.attributes.findIndex(attr => attr.value === validator || attr.value === toBase64(stringToUint8Array(validator))) > -1) - .map(x => { - // check if attributes need to decode - const output = {} as {[key: string]: string } + .filter((x) => x.type === selectedEventType.value) + .filter( + (x) => + x.attributes.findIndex( + (attr) => + attr.value === validator || + attr.value === toBase64(stringToUint8Array(validator)) + ) > -1 + ) + .map((x) => { + // check if attributes need to decode + const output = {} as { [key: string]: string }; - if(x.attributes.findIndex(a => a.key === `amount`) > -1) { - x.attributes.forEach(attr => { - output[attr.key] = attr.value - }) - } else x.attributes.forEach(attr => { - output[uint8ArrayToString(fromBase64(attr.key))] = uint8ArrayToString(fromBase64(attr.value)) - }) - return output - }) - - return attributes + if (x.attributes.findIndex((a) => a.key === `amount`) > -1) { + x.attributes.forEach((attr) => { + output[attr.key] = attr.value; + }); + } else + x.attributes.forEach((attr) => { + output[uint8ArrayToString(fromBase64(attr.key))] = uint8ArrayToString( + fromBase64(attr.value) + ); + }); + return output; + }); + return attributes; } function mapDelegators(messages: any[]) { - if(!messages) return [] - return Array.from(new Set(messages.map(x => x.delegator_address || x.grantee))) + if (!messages) return []; + return Array.from( + new Set(messages.map((x) => x.delegator_address || x.grantee)) + ); } -