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