forked from cerc-io/cosmos-explorer
Merge pull request #528 from freak12techno/add-consensus-prefix-to-config
feat: add consensus prefix to config
This commit is contained in:
commit
3aec1c5a6e
@ -1,8 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
fromBase64,
|
fromBase64,
|
||||||
fromBech32,
|
fromBech32,
|
||||||
fromHex,
|
|
||||||
toBase64,
|
|
||||||
toBech32,
|
toBech32,
|
||||||
toHex,
|
toHex,
|
||||||
} from '@cosmjs/encoding';
|
} from '@cosmjs/encoding';
|
||||||
@ -12,13 +10,6 @@ export function decodeAddress(address: string) {
|
|||||||
return fromBech32(address);
|
return fromBech32(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function valoperToPrefix(valoper?: string) {
|
|
||||||
if (!valoper) return '';
|
|
||||||
const prefixIndex = valoper.indexOf('valoper');
|
|
||||||
if (prefixIndex === -1) return null;
|
|
||||||
return valoper.slice(0, prefixIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function operatorAddressToAccount(operAddress?: string) {
|
export function operatorAddressToAccount(operAddress?: string) {
|
||||||
if (!operAddress) return '';
|
if (!operAddress) return '';
|
||||||
const { prefix, data } = fromBech32(operAddress);
|
const { prefix, data } = fromBech32(operAddress);
|
||||||
@ -59,7 +50,7 @@ export function pubKeyToValcons(
|
|||||||
const pubkey = fromBase64(consensusPubkey.key);
|
const pubkey = fromBase64(consensusPubkey.key);
|
||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
const addressData = sha256(pubkey).slice(0, 20);
|
const addressData = sha256(pubkey).slice(0, 20);
|
||||||
return toBech32(`${prefix}valcons`, addressData);
|
return toBech32(prefix, addressData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
|
@ -13,7 +13,6 @@ import {
|
|||||||
consensusPubkeyToHexAddress,
|
consensusPubkeyToHexAddress,
|
||||||
operatorAddressToAccount,
|
operatorAddressToAccount,
|
||||||
pubKeyToValcons,
|
pubKeyToValcons,
|
||||||
valoperToPrefix,
|
|
||||||
} from '@/libs';
|
} 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 PaginationBar from '@/components/PaginationBar.vue';
|
||||||
@ -127,13 +126,12 @@ onMounted(() => {
|
|||||||
identity.value = res.validator?.description?.identity || '';
|
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) || '<Invalid>';
|
|
||||||
addresses.value.hex = consensusPubkeyToHexAddress(
|
addresses.value.hex = consensusPubkeyToHexAddress(
|
||||||
v.value.consensus_pubkey
|
v.value.consensus_pubkey
|
||||||
);
|
);
|
||||||
addresses.value.valCons = pubKeyToValcons(
|
addresses.value.valCons = pubKeyToValcons(
|
||||||
v.value.consensus_pubkey,
|
v.value.consensus_pubkey,
|
||||||
prefix
|
blockchain.current.bech32ConsensusPrefix,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
blockchain.rpc
|
blockchain.rpc
|
||||||
|
@ -57,6 +57,7 @@ export interface ChainConfig {
|
|||||||
chainName: string;
|
chainName: string;
|
||||||
prettyName: string;
|
prettyName: string;
|
||||||
bech32Prefix: string;
|
bech32Prefix: string;
|
||||||
|
bech32ConsensusPrefix: string;
|
||||||
chainId: string;
|
chainId: string;
|
||||||
coinType: string;
|
coinType: string;
|
||||||
assets: Asset[];
|
assets: Asset[];
|
||||||
@ -89,6 +90,7 @@ export interface ChainConfig {
|
|||||||
|
|
||||||
export interface LocalConfig {
|
export interface LocalConfig {
|
||||||
addr_prefix: string;
|
addr_prefix: string;
|
||||||
|
consensus_prefix?: string;
|
||||||
alias: string;
|
alias: string;
|
||||||
api: string[] | Endpoint[];
|
api: string[] | Endpoint[];
|
||||||
provider_chain: {
|
provider_chain: {
|
||||||
@ -153,6 +155,7 @@ export function fromLocal(lc: LocalConfig): ChainConfig {
|
|||||||
cosmosSdk: lc.sdk_version
|
cosmosSdk: lc.sdk_version
|
||||||
}
|
}
|
||||||
conf.bech32Prefix = lc.addr_prefix;
|
conf.bech32Prefix = lc.addr_prefix;
|
||||||
|
conf.bech32ConsensusPrefix = lc.consensus_prefix ?? lc.addr_prefix + 'valcons';
|
||||||
conf.chainName = lc.chain_name;
|
conf.chainName = lc.chain_name;
|
||||||
conf.coinType = lc.coin_type;
|
conf.coinType = lc.coin_type;
|
||||||
conf.prettyName = lc.registry_name || lc.chain_name;
|
conf.prettyName = lc.registry_name || lc.chain_name;
|
||||||
@ -177,6 +180,7 @@ export function fromDirectory(source: DirectoryChain): ChainConfig {
|
|||||||
const conf = {} as ChainConfig;
|
const conf = {} as ChainConfig;
|
||||||
(conf.assets = source.assets),
|
(conf.assets = source.assets),
|
||||||
(conf.bech32Prefix = source.bech32_prefix),
|
(conf.bech32Prefix = source.bech32_prefix),
|
||||||
|
(conf.bech32ConsensusPrefix = source.bech32_prefix + 'valcons'),
|
||||||
(conf.chainId = source.chain_id),
|
(conf.chainId = source.chain_id),
|
||||||
(conf.chainName = source.chain_name),
|
(conf.chainName = source.chain_name),
|
||||||
(conf.prettyName = source.pretty_name),
|
(conf.prettyName = source.pretty_name),
|
||||||
|
Loading…
Reference in New Issue
Block a user