clean code
This commit is contained in:
parent
c89bdd06b4
commit
c30a652465
@ -1,7 +1,5 @@
|
|||||||
import {fromBase64, fromBech32, fromHex, toBase64, toBech32, toHex} from '@cosmjs/encoding'
|
import {fromBase64, fromBech32, fromHex, toBase64, toBech32, toHex} from '@cosmjs/encoding'
|
||||||
import { Ripemd160, sha256 } from '@cosmjs/crypto'
|
import { Ripemd160, sha256 } from '@cosmjs/crypto'
|
||||||
import { cosmos } from '@ping-pub/codegen'
|
|
||||||
import type { PubKey } from '@ping-pub/codegen/src/cosmos/crypto/ed25519/keys'
|
|
||||||
|
|
||||||
export function decodeAddress(address: string) {
|
export function decodeAddress(address: string) {
|
||||||
return fromBech32(address)
|
return fromBech32(address)
|
||||||
@ -25,41 +23,27 @@ export function valoperToPrefix(valoper?: string) {
|
|||||||
}
|
}
|
||||||
return toBech32(prefix.replace('valoper', ''), data)
|
return toBech32(prefix.replace('valoper', ''), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decodeKey(consensusPubkey: {typeUrl: string, value: Uint8Array}) {
|
export function consensusPubkeyToHexAddress(consensusPubkey?: {"@type": string, key: string}) {
|
||||||
let raw = null
|
|
||||||
if (consensusPubkey.typeUrl === '/cosmos.crypto.ed25519.PubKey') {
|
|
||||||
const pubkey = cosmos.crypto.ed25519.PubKey.decode(consensusPubkey.value)
|
|
||||||
return pubkey
|
|
||||||
}
|
|
||||||
|
|
||||||
if (consensusPubkey.typeUrl === '/cosmos.crypto.secp256k1.PubKey') {
|
|
||||||
const pubkey = cosmos.crypto.secp256k1.PubKey.decode(consensusPubkey.value)
|
|
||||||
return pubkey
|
|
||||||
}
|
|
||||||
return raw
|
|
||||||
|
|
||||||
}
|
|
||||||
export function consensusPubkeyToHexAddress(consensusPubkey?: {typeUrl: string, value: Uint8Array}) {
|
|
||||||
if(!consensusPubkey) return ""
|
if(!consensusPubkey) return ""
|
||||||
let raw = ""
|
let raw = ""
|
||||||
if (consensusPubkey.typeUrl === '/cosmos.crypto.ed25519.PubKey') {
|
if (consensusPubkey['@type'] === '/cosmos.crypto.ed25519.PubKey') {
|
||||||
const pubkey = decodeKey(consensusPubkey)
|
const pubkey = fromBase64(consensusPubkey.key)
|
||||||
if(pubkey) return toHex(sha256(pubkey.key)).slice(0, 40).toUpperCase()
|
if(pubkey) return toHex(sha256(pubkey)).slice(0, 40).toUpperCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consensusPubkey.typeUrl === '/cosmos.crypto.secp256k1.PubKey') {
|
if (consensusPubkey['@type'] === '/cosmos.crypto.secp256k1.PubKey') {
|
||||||
const pubkey = decodeKey(consensusPubkey)
|
const pubkey = fromBase64(consensusPubkey.key)
|
||||||
if(pubkey) return toHex(new Ripemd160().update(sha256(pubkey.key)).digest())
|
if(pubkey) return toHex(new Ripemd160().update(sha256(pubkey)).digest())
|
||||||
}
|
}
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pubKeyToValcons(consensusPubkey: {typeUrl: string, value: Uint8Array}, prefix: string) {
|
export function pubKeyToValcons(consensusPubkey: {"@type": string, key: string}, prefix: string) {
|
||||||
const pubkey = decodeKey(consensusPubkey)
|
const pubkey = fromBase64(consensusPubkey.key)
|
||||||
if(pubkey) {
|
if(pubkey) {
|
||||||
const addressData = sha256(pubkey.key).slice(0, 20)
|
const addressData = sha256(pubkey).slice(0, 20)
|
||||||
return toBech32(`${prefix}valcons`, addressData)
|
return toBech32(`${prefix}valcons`, addressData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
import type { LCDClient } from "@osmonauts/lcd";
|
|
||||||
import type { QueryAnnualProvisionsRequest, QueryAnnualProvisionsResponseSDKType, QueryInflationRequest, QueryInflationResponseSDKType, QueryParamsRequest, QueryParamsResponseSDKType } from '@ping-pub/codegen/src/cosmos/mint/v1beta1/query'
|
|
||||||
|
|
||||||
export class OsmosisMintClient {
|
|
||||||
req: LCDClient;
|
|
||||||
|
|
||||||
constructor({
|
|
||||||
requestClient
|
|
||||||
}: {
|
|
||||||
requestClient: LCDClient;
|
|
||||||
}) {
|
|
||||||
this.req = requestClient;
|
|
||||||
this.params = this.params.bind(this);
|
|
||||||
this.inflation = this.inflation.bind(this);
|
|
||||||
this.annualProvisions = this.annualProvisions.bind(this);
|
|
||||||
}
|
|
||||||
/* Params returns the total set of minting parameters. */
|
|
||||||
|
|
||||||
|
|
||||||
async params(_params: QueryParamsRequest = {}): Promise<QueryParamsResponseSDKType> {
|
|
||||||
const endpoint = `cosmos/mint/v1beta1/params`;
|
|
||||||
return await this.req.get<QueryParamsResponseSDKType>(endpoint);
|
|
||||||
}
|
|
||||||
/* Inflation returns the current minting inflation value. */
|
|
||||||
|
|
||||||
|
|
||||||
async inflation(_params: QueryInflationRequest = {}): Promise<QueryInflationResponseSDKType> {
|
|
||||||
const endpoint = `cosmos/mint/v1beta1/inflation`;
|
|
||||||
return await this.req.get<QueryInflationResponseSDKType>(endpoint);
|
|
||||||
}
|
|
||||||
/* AnnualProvisions current minting annual provisions value. */
|
|
||||||
|
|
||||||
|
|
||||||
async annualProvisions(_params: QueryAnnualProvisionsRequest = {}): Promise<QueryAnnualProvisionsResponseSDKType> {
|
|
||||||
const endpoint = `cosmos/mint/v1beta1/annual_provisions`;
|
|
||||||
return await this.req.get<QueryAnnualProvisionsResponseSDKType>(endpoint);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,3 @@
|
|||||||
export * from './address'
|
export * from './address'
|
||||||
export * from './client'
|
|
||||||
export * from './http'
|
export * from './http'
|
||||||
export * from './misc'
|
export * from './misc'
|
@ -1,6 +1,5 @@
|
|||||||
import { sha256 } from "@cosmjs/crypto";
|
import { sha256 } from "@cosmjs/crypto";
|
||||||
import { toHex } from "@cosmjs/encoding";
|
import { toHex } from "@cosmjs/encoding";
|
||||||
import { PageRequest } from "@ping-pub/codegen/src/cosmos/base/query/v1beta1/pagination";
|
|
||||||
|
|
||||||
export function newPageRequest(param: {
|
export function newPageRequest(param: {
|
||||||
key?: Uint8Array,
|
key?: Uint8Array,
|
||||||
@ -9,9 +8,7 @@ export function newPageRequest(param: {
|
|||||||
countTotal?: boolean,
|
countTotal?: boolean,
|
||||||
reverse?: boolean
|
reverse?: boolean
|
||||||
}) {
|
}) {
|
||||||
return PageRequest.fromPartial(
|
return param
|
||||||
param
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hashTx(raw: Uint8Array) {
|
export function hashTx(raw: Uint8Array) {
|
||||||
|
@ -9,14 +9,6 @@ export interface Request<T> {
|
|||||||
adapter: (source: any) => T
|
adapter: (source: any) => T
|
||||||
}
|
}
|
||||||
|
|
||||||
interface User {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Post {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// use snake style, since the all return object use snake style.
|
// use snake style, since the all return object use snake style.
|
||||||
export interface RequestRegistry {
|
export interface RequestRegistry {
|
||||||
auth_params: Request<any>
|
auth_params: Request<any>
|
||||||
@ -66,9 +58,9 @@ export interface RequestRegistry {
|
|||||||
base_tendermint_validatorsets_latest: Request<any>;
|
base_tendermint_validatorsets_latest: Request<any>;
|
||||||
base_tendermint_validatorsets_height: Request<any>;
|
base_tendermint_validatorsets_height: Request<any>;
|
||||||
|
|
||||||
tx_txs: Request<any>;
|
tx_txs: Request<Txs>;
|
||||||
tx_txs_block: Request<any>;
|
tx_txs_block: Request<Txs>;
|
||||||
tx_hash: Request<any>;
|
tx_hash: Request<Tx>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { decodeTxRaw, type DecodedTxRaw } from '@cosmjs/proto-signing'
|
import { decodeTxRaw, type DecodedTxRaw } from '@cosmjs/proto-signing'
|
||||||
import { createBaseClientForChain } from "@/libs/client";
|
|
||||||
import { useBlockchain } from "@/stores";
|
import { useBlockchain } from "@/stores";
|
||||||
import type { GetLatestBlockResponse, GetLatestBlockResponseSDKType } from "@ping-pub/codegen/src/cosmos/base/tendermint/v1beta1/query";
|
|
||||||
import { hashTx } from "@/libs";
|
import { hashTx } from "@/libs";
|
||||||
|
import type { Block } from "@/types";
|
||||||
|
|
||||||
export const useBlockModule = defineStore('blockModule', {
|
export const useBlockModule = defineStore('blockModule', {
|
||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
latest: {} as GetLatestBlockResponse,
|
latest: {} as Block,
|
||||||
current: {} as GetLatestBlockResponse,
|
current: {} as Block,
|
||||||
recents: [] as GetLatestBlockResponse[]
|
recents: [] as Block[]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
@ -2,7 +2,6 @@ import { useBlockchain, useCoingecko, useBaseStore, useBankStore, useFormatter,
|
|||||||
import { useDistributionStore } from "@/stores/useDistributionStore";
|
import { useDistributionStore } from "@/stores/useDistributionStore";
|
||||||
import { useMintStore } from "@/stores/useMintStore";
|
import { useMintStore } from "@/stores/useMintStore";
|
||||||
import { useStakingStore } from "@/stores/useStakingStore";
|
import { useStakingStore } from "@/stores/useStakingStore";
|
||||||
import { ProposalStatus, type ProposalSDKType, Proposal } from "@ping-pub/codegen/src/cosmos/gov/v1beta1/gov";
|
|
||||||
import numeral from "numeral";
|
import numeral from "numeral";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useBlockchain, useFormatter, useMintStore, useStakingStore } from '@/stores';
|
import { useBlockchain, useFormatter, useMintStore, useStakingStore } from '@/stores';
|
||||||
import type { QueryValidatorResponseSDKType } from '@ping-pub/codegen/src/cosmos/staking/v1beta1/query';
|
|
||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import ValidatorCommissionRate from '@/components/ValidatorCommissionRate.vue'
|
import ValidatorCommissionRate from '@/components/ValidatorCommissionRate.vue'
|
||||||
import type { Coin, DecCoin } from '@ping-pub/codegen/src/cosmos/base/v1beta1/coin';
|
|
||||||
import { consensusPubkeyToHexAddress, operatorAddressToAccount, pubKeyToValcons, valoperToPrefix } from '@/libs';
|
import { consensusPubkeyToHexAddress, operatorAddressToAccount, pubKeyToValcons, valoperToPrefix } from '@/libs';
|
||||||
import { computed } from '@vue/reactivity';
|
import { computed } from '@vue/reactivity';
|
||||||
import type { GetTxsEventResponse } from '@ping-pub/codegen/src/cosmos/tx/v1beta1/service';
|
import type { Coin } from '@/types';
|
||||||
|
import type { Txs } from '@/types/Txs';
|
||||||
|
|
||||||
const props = defineProps(['validator', 'chain'])
|
const props = defineProps(['validator', 'chain'])
|
||||||
|
|
||||||
@ -17,11 +16,11 @@ const format = useFormatter()
|
|||||||
|
|
||||||
const validator: string = props.validator
|
const validator: string = props.validator
|
||||||
|
|
||||||
const v = ref({} as QueryValidatorResponseSDKType)
|
const v = ref({})
|
||||||
const cache = JSON.parse(localStorage.getItem('avatars')||'{}')
|
const cache = JSON.parse(localStorage.getItem('avatars')||'{}')
|
||||||
const avatars = ref( cache || {} )
|
const avatars = ref( cache || {} )
|
||||||
const identity = ref("")
|
const identity = ref("")
|
||||||
const rewards = ref([] as DecCoin[])
|
const rewards = ref([] as Coin[])
|
||||||
const addresses = ref({} as {
|
const addresses = ref({} as {
|
||||||
account: string
|
account: string
|
||||||
operAddress: string
|
operAddress: string
|
||||||
@ -38,7 +37,7 @@ staking.fetchValidatorDelegation(validator, addresses.value.account).then(x => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const txs = ref({} as GetTxsEventResponse)
|
const txs = ref({} as Txs)
|
||||||
|
|
||||||
blockchain.rpc.txs([`message.sender='${addresses.value.account}'`]).then(x => {
|
blockchain.rpc.txs([`message.sender='${addresses.value.account}'`]).then(x => {
|
||||||
console.log("txs", x)
|
console.log("txs", x)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import { useBaseStore, useFormatter, useStakingStore } from '@/stores';
|
import { useBaseStore, useFormatter, useStakingStore } from '@/stores';
|
||||||
import { toBase64, toHex } from '@cosmjs/encoding';
|
import { toBase64, toHex } from '@cosmjs/encoding';
|
||||||
import { pubkeyToAddress } from '@cosmjs/tendermint-rpc';
|
import { pubkeyToAddress } from '@cosmjs/tendermint-rpc';
|
||||||
import type { ValidatorSDKType } from '@ping-pub/codegen/src/cosmos/staking/v1beta1/staking';
|
|
||||||
import { computed } from '@vue/reactivity';
|
import { computed } from '@vue/reactivity';
|
||||||
import { onMounted, ref, type DebuggerEvent } from 'vue';
|
import { onMounted, ref, type DebuggerEvent } from 'vue';
|
||||||
import { consensusPubkeyToHexAddress } from '@/libs'
|
import { consensusPubkeyToHexAddress } from '@/libs'
|
||||||
@ -14,7 +13,7 @@ const avatars = ref( cache || {} )
|
|||||||
const latest = ref({} as Record<string, number>)
|
const latest = ref({} as Record<string, number>)
|
||||||
const yesterday = ref({} as Record<string, number>)
|
const yesterday = ref({} as Record<string, number>)
|
||||||
const tab = ref('active')
|
const tab = ref('active')
|
||||||
const unbondList = ref([] as ValidatorSDKType[])
|
const unbondList = ref([])
|
||||||
const base = useBaseStore()
|
const base = useBaseStore()
|
||||||
onMounted(()=> {
|
onMounted(()=> {
|
||||||
fetchChange(0)
|
fetchChange(0)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
|
||||||
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div>Hello wallet</div>
|
<div>Hello wallet</div>
|
||||||
</template>
|
</template>
|
@ -4,9 +4,6 @@ import ChainSummary from '@/components/ChainSummary.vue';
|
|||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useBlockchain } from '@/stores';
|
import { useBlockchain } from '@/stores';
|
||||||
|
|
||||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
|
||||||
import { QueryClient, setupBankExtension, setupDistributionExtension, setupGovExtension, setupMintExtension, setupStakingExtension } from "@cosmjs/stargate";
|
|
||||||
|
|
||||||
const dashboard = useDashboard()
|
const dashboard = useDashboard()
|
||||||
|
|
||||||
dashboard.$subscribe((mutation, state) => {
|
dashboard.$subscribe((mutation, state) => {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { useDashboard, type ChainConfig, type Endpoint, EndpointType } from "./useDashboard";
|
import { useDashboard, type ChainConfig, type Endpoint, EndpointType } from "./useDashboard";
|
||||||
import { LCDClient } from '@osmonauts/lcd'
|
|
||||||
import type { VerticalNavItems } from '@/@layouts/types'
|
import type { VerticalNavItems } from '@/@layouts/types'
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
import { useStakingStore } from "./useStakingStore";
|
import { useStakingStore } from "./useStakingStore";
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { useBlockchain } from "./useBlockchain";
|
import { useBlockchain } from "./useBlockchain";
|
||||||
import Long from "long";
|
|
||||||
import numeral from "numeral";
|
import numeral from "numeral";
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import duration from 'dayjs/plugin/duration'
|
import duration from 'dayjs/plugin/duration'
|
||||||
@ -9,8 +8,8 @@ import updateLocale from 'dayjs/plugin/updateLocale'
|
|||||||
import utc from 'dayjs/plugin/utc'
|
import utc from 'dayjs/plugin/utc'
|
||||||
import localeData from 'dayjs/plugin/localeData'
|
import localeData from 'dayjs/plugin/localeData'
|
||||||
import { useStakingStore } from "./useStakingStore";
|
import { useStakingStore } from "./useStakingStore";
|
||||||
import { fromBech32, toBase64, toHex } from "@cosmjs/encoding";
|
import { toHex } from "@cosmjs/encoding";
|
||||||
import { consensusPubkeyToHexAddress, operatorAddressToAccount } from "@/libs";
|
import { consensusPubkeyToHexAddress } from "@/libs";
|
||||||
|
|
||||||
dayjs.extend(localeData)
|
dayjs.extend(localeData)
|
||||||
dayjs.extend(duration)
|
dayjs.extend(duration)
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { useBlockchain } from "./useBlockchain";
|
import { useBlockchain } from "./useBlockchain";
|
||||||
import { createGovRestClientForChain } from "@/libs/client";
|
|
||||||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
|
||||||
import { QueryClient } from "@cosmjs/stargate";
|
|
||||||
|
|
||||||
export const useGovStore = defineStore('govStore', {
|
export const useGovStore = defineStore('govStore', {
|
||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
deposit: {} as DepositParams,
|
deposit: {},
|
||||||
voting: {} as VotingParams,
|
voting: {},
|
||||||
tally: {} as TallyParams,
|
tally: {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user