Merge pull request #306 from AndreMiras/feature/show_signer_valcons_address

Show signer address (valcons) in validator details
This commit is contained in:
ping 2023-01-13 09:05:31 +08:00 committed by GitHub
commit 0875a5e12a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import { import {
Bech32, fromBase64, fromBech32, fromHex, toBase64, toBech32, toHex, fromBase64, fromBech32, fromHex, toBase64, toBech32, toHex,
} from '@cosmjs/encoding' } from '@cosmjs/encoding'
import { sha256, stringToPath } from '@cosmjs/crypto' import { sha256, stringToPath } from '@cosmjs/crypto'
// ledger // ledger
@ -82,20 +82,26 @@ export async function connectLedger(transport = 'usb') {
return new CosmosApp(trans) return new CosmosApp(trans)
} }
export function operatorAddressToAccount(operAddress) { export function valoperToPrefix(valoper) {
const { prefix, data } = Bech32.decode(operAddress) const prefixIndex = valoper.indexOf('valoper')
if (prefix === 'iva') { // handle special cases if (prefixIndex === -1) return null
return Bech32.encode('iaa', data) return valoper.slice(0, prefixIndex)
}
if (prefix === 'crocncl') { // handle special cases
return Bech32.encode('cro', data)
}
return Bech32.encode(prefix.replace('valoper', ''), data)
} }
// TODO, not tested export function operatorAddressToAccount(operAddress) {
export function pubkeyToAccountAddress(pubkey, prefix) { const { prefix, data } = fromBech32(operAddress)
return Bech32.encode(prefix, pubkey, 40) if (prefix === 'iva') { // handle special cases
return toBech32('iaa', data)
}
if (prefix === 'crocncl') { // handle special cases
return toBech32('cro', data)
}
return toBech32(prefix.replace('valoper', ''), data)
}
export function pubKeyToValcons(pubkey, prefix) {
const addressData = sha256(fromBase64(pubkey.key)).slice(0, 20)
return toBech32(`${prefix}valcons`, addressData)
} }
export function toETHAddress(cosmosAddress) { export function toETHAddress(cosmosAddress) {

View File

@ -224,6 +224,7 @@
:operator-address="validator.operator_address" :operator-address="validator.operator_address"
:consensus-pubkey="validator.consensus_pubkey" :consensus-pubkey="validator.consensus_pubkey"
:account-address="accountAddress" :account-address="accountAddress"
:valcons-address="valconsAddress"
/> />
</b-col> </b-col>
</b-row> </b-row>
@ -273,7 +274,7 @@ import {
} from 'bootstrap-vue' } from 'bootstrap-vue'
import { import {
percent, formatToken, StakingParameters, Validator, operatorAddressToAccount, consensusPubkeyToHexAddress, toDay, abbrMessage, abbrAddress, percent, formatToken, StakingParameters, Validator, operatorAddressToAccount, consensusPubkeyToHexAddress, toDay, abbrMessage, abbrAddress, valoperToPrefix, pubKeyToValcons,
} from '@/libs/utils' } from '@/libs/utils'
import { keybase } from '@/libs/fetch' import { keybase } from '@/libs/fetch'
import OperationModal from '@/views/components/OperationModal/index.vue' import OperationModal from '@/views/components/OperationModal/index.vue'
@ -314,6 +315,7 @@ export default {
latestHeight: 0, latestHeight: 0,
accountAddress: '-', accountAddress: '-',
hexAddress: '-', hexAddress: '-',
valconsAddress: '-',
stakingPool: {}, stakingPool: {},
mintInflation: 0, mintInflation: 0,
stakingParameter: new StakingParameters(), stakingParameter: new StakingParameters(),
@ -384,8 +386,10 @@ export default {
return percent(value) return percent(value)
}, },
processAddress(operAddress, consensusPubkey) { processAddress(operAddress, consensusPubkey) {
const prefix = valoperToPrefix(operAddress)
this.accountAddress = operatorAddressToAccount(operAddress) this.accountAddress = operatorAddressToAccount(operAddress)
this.hexAddress = consensusPubkeyToHexAddress(consensusPubkey) this.hexAddress = consensusPubkeyToHexAddress(consensusPubkey)
this.valconsAddress = pubKeyToValcons(consensusPubkey, prefix)
this.$http.getStakingDelegatorDelegation(this.accountAddress, operAddress).then(d => { this.$http.getStakingDelegatorDelegation(this.accountAddress, operAddress).then(d => {
this.selfDelegation = d this.selfDelegation = d
}) })

View File

@ -98,6 +98,29 @@
<small @click="copy(hexAddress)">{{ hexAddress }}</small> <small @click="copy(hexAddress)">{{ hexAddress }}</small>
</b-media-body> </b-media-body>
</b-media> </b-media>
<b-media
class="mb-1"
no-body
>
<b-media-aside class="mr-1">
<b-avatar
rounded
variant="light-primary"
size="34"
>
<feather-icon
icon="HashIcon"
size="18"
/>
</b-avatar>
</b-media-aside>
<b-media-body class="text-truncate">
<h6 class="mb-0">
Signer Address
</h6>
<small @click="copy(valconsAddress)">{{ valconsAddress }}</small>
</b-media-body>
</b-media>
</b-card> </b-card>
</template> </template>
@ -138,6 +161,10 @@ export default {
type: String, type: String,
default: '-', default: '-',
}, },
valconsAddress: {
type: String,
default: '-',
},
}, },
methods: { methods: {
copy(v) { copy(v) {