add v0.46.0 compatible

This commit is contained in:
liangping 2022-08-28 12:22:46 +08:00
parent bc25fce1cc
commit b0492e7260
8 changed files with 78 additions and 65 deletions

View File

@ -60,19 +60,19 @@ export default class ChainFetch {
}
async getLatestBlock(config = null) {
const conf = config || this.getSelectedConfig()
if (conf.chain_name === 'injective') {
return ChainFetch.fetch('https://tm.injective.network', '/block').then(data => Block.create(commonProcess(data)))
}
return this.get(`/blocks/latest?${new Date().getTime()}`, config).then(data => Block.create(data))
// const conf = config || this.getSelectedConfig()
// if (conf.chain_name === 'injective') {
// return ChainFetch.fetch('https://tm.injective.network', '/cosmos/base/tendermint/v1beta1/block').then(data => Block.create(commonProcess(data)))
// }
return this.get('/cosmos/base/tendermint/v1beta1/blocks/latest', config).then(data => Block.create(data))
}
async getBlockByHeight(height, config = null) {
const conf = config || this.getSelectedConfig()
if (conf.chain_name === 'injective') {
return ChainFetch.fetch('https://tm.injective.network', `/block?height=${height}`).then(data => Block.create(commonProcess(data)))
}
return this.get(`/blocks/${height}`, config).then(data => Block.create(data))
// const conf = config || this.getSelectedConfig()
// if (conf.chain_name === 'injective') {
// return ChainFetch.fetch('https://tm.injective.network', `/cosmos/base/tendermint/v1beta1/block?height=${height}`).then(data => Block.create(commonProcess(data)))
// }
return this.get(`/cosmos/base/tendermint/v1beta1/blocks/${height}`, config).then(data => Block.create(data))
}
async getSlashingSigningInfo(config = null) {
@ -94,7 +94,7 @@ export default class ChainFetch {
}
async getTxsByRecipient(recipient) {
return this.get(`/txs?message.recipient=${recipient}`)
return this.get(`/cosmos/tx/v1beta1/txs?message.recipient=${recipient}`)
}
async getTxsByHeight(height) {
@ -102,22 +102,32 @@ export default class ChainFetch {
}
async getValidatorDistribution(address) {
return this.get(`/distribution/validators/${address}`).then(data => {
const ret = ValidatorDistribution.create(commonProcess(data))
ret.versionFixed(this.config.sdk_version)
// return this.get(`/distribution/validators/${address}`).then(data => {
return Promise.all([
this.get(`/cosmos/distribution/v1beta1/validators/${address}/commission`),
this.get(`/cosmos/distribution/v1beta1/validators/${address}/outstanding_rewards`),
]).then(data => {
const ret = ValidatorDistribution.create({
operator_address: address,
self_bond_rewards: data[1].rewards.rewards,
val_commission: data[0].commission.commission,
})
return ret
})
}
async getStakingDelegatorDelegation(delegatorAddr, validatorAddr) {
return this.get(`/staking/delegators/${delegatorAddr}/delegations/${validatorAddr}`).then(data => StakingDelegation.create(commonProcess(data)))
return this.get(`/cosmos/staking/v1beta1/validators/${validatorAddr}/delegations/${delegatorAddr}`).then(data => StakingDelegation.create(commonProcess(data).delegation_response))
}
async getBankTotal(denom) {
if (compareVersions(this.config.sdk_version, '0.40') < 0) {
return this.get(`/supply/total/${denom}`).then(data => ({ amount: commonProcess(data), denom }))
}
return this.get(`/bank/total/${denom}`).then(data => commonProcess(data))
if (compareVersions(this.config.sdk_version, '0.46') < 0) {
return this.get(`/bank/total/${denom}`).then(data => commonProcess(data))
}
return this.get(`/cosmos/bank/v1beta1/supply/${denom}`).then(data => commonProcess(data))
}
async getBankTotals() {
@ -128,7 +138,7 @@ export default class ChainFetch {
}
async getStakingPool() {
return this.get('/staking/pool').then(data => new StakingPool().init(commonProcess(data)))
return this.get('/cosmos/staking/v1beta1/pool').then(data => new StakingPool().init(commonProcess(data.pool)))
}
async getMintingInflation() {
@ -139,29 +149,29 @@ export default class ChainFetch {
return this.get('/echelon/inflation/v1/inflation_rate').then(data => Number(data.inflation_rate / 100 || 0))
}
if (this.isModuleLoaded('minting')) {
return this.get('/minting/inflation').then(data => Number(commonProcess(data)))
return this.get('/cosmos/mint/v1beta1/inflation').then(data => Number(commonProcess(data.inflation)))
}
return 0
}
async getStakingParameters() {
return this.get('/staking/parameters').then(data => {
return this.get('/cosmos/staking/v1beta1/params').then(data => {
this.getSelectedConfig()
return StakingParameters.create(commonProcess(data), this.config.chain_name)
return StakingParameters.create(commonProcess(data.params), this.config.chain_name)
})
}
async getValidatorList(config = null) {
return this.get('/staking/validators', config).then(data => {
const vals = commonProcess(data).map(i => new Validator().init(i))
return this.get('/cosmos/staking/v1beta1/validators?pagination.limit=200&status=BOND_STATUS_BONDED', config).then(data => {
const vals = commonProcess(data.validators).map(i => new Validator().init(i))
localStorage.setItem(`validators-${this.config.chain_name}`, JSON.stringify(vals))
return vals
})
}
async getValidatorUnbondedList() {
return this.get('/cosmos/staking/v1beta1/validators?status=BOND_STATUS_UNBONDED').then(data => {
const result = commonProcess(data)
return this.get('/cosmos/staking/v1beta1/validators?pagination.limit&status=BOND_STATUS_UNBONDED').then(data => {
const result = commonProcess(data.validators)
const vals = result.validators ? result.validators : result
return vals.map(i => new Validator().init(i))
})
@ -180,12 +190,12 @@ export default class ChainFetch {
}
async getStakingValidator(address) {
return this.get(`/staking/validators/${address}`).then(data => new Validator().init(commonProcess(data)))
return this.get(`/cosmos/staking/v1beta1/validators/${address}`).then(data => new Validator().init(commonProcess(data).validator))
}
async getSlashingParameters() {
if (this.isModuleLoaded('slashing')) {
return this.get('/slashing/parameters').then(data => commonProcess(data))
return this.get('/cosmos/slashing/v1beta1/params').then(data => commonProcess(data.params))
}
return null
}
@ -228,33 +238,33 @@ export default class ChainFetch {
return result
}
if (this.isModuleLoaded('minting')) {
return this.get('/minting/parameters').then(data => commonProcess(data))
return this.get('/cosmos/mint/v1beta1/params').then(data => commonProcess(data.params))
}
return null
}
async getDistributionParameters() {
return this.get('/distribution/parameters').then(data => commonProcess(data))
return this.get('/cosmos/distribution/v1beta1/params').then(data => commonProcess(data.params))
}
async getGovernanceParameterDeposit() {
return this.get('/gov/parameters/deposit').then(data => commonProcess(data))
return this.get('/cosmos/gov/v1beta1/params/deposit').then(data => commonProcess(data.deposit_params))
}
async getGovernanceParameterTallying() {
return this.get('/gov/parameters/tallying').then(data => commonProcess(data))
return this.get('/cosmos/gov/v1beta1/params/tallying').then(data => commonProcess(data.tally_params))
}
async getGovernanceParameterVoting() {
return this.get('/gov/parameters/voting').then(data => commonProcess(data))
return this.get('/cosmos/gov/v1beta1/params/voting').then(data => commonProcess(data.voting_params))
}
async getGovernanceTally(pid, total, conf) {
return this.get(`/gov/proposals/${pid}/tally`, conf).then(data => new ProposalTally().init(commonProcess(data), total))
return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/tally`, conf).then(data => new ProposalTally().init(commonProcess(data), total))
}
getGovernance(pid) {
return this.get(`/gov/proposals/${pid}`).then(data => {
return this.get(`/cosmos/gov/v1beta1/proposals/${pid}`).then(data => {
const p = new Proposal().init(commonProcess(data), 0)
p.versionFixed(this.config.sdk_version)
return p
@ -275,7 +285,7 @@ export default class ChainFetch {
return Array.isArray(result) ? result.reverse().map(d => new Deposit().init(d)) : result
})
}
return this.get(`/gov/proposals/${pid}/deposits`).then(data => {
return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/deposits`).then(data => {
const result = commonProcess(data)
return Array.isArray(result) ? result.reverse().map(d => new Deposit().init(d)) : result
})
@ -283,7 +293,7 @@ export default class ChainFetch {
async getGovernanceVotes(pid, next = '', limit = 50) {
if (compareVersions(this.config.sdk_version, '0.40') < 0) {
return this.get(`/gov/proposals/${pid}/votes`).then(data => ({
return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/votes`).then(data => ({
votes: commonProcess(data).map(d => new Votes().init(d)),
pagination: {},
}))
@ -361,14 +371,14 @@ export default class ChainFetch {
}
async getAuthAccount(address, config = null) {
return this.get('/auth/accounts/'.concat(address), config).then(data => {
return this.get('/cosmos/auth/v1beta1/accounts/'.concat(address), config).then(data => {
const result = commonProcess(data)
return result.value ? result : { value: result }
})
}
async getBankAccountBalance(address) {
return this.get('/bank/balances/'.concat(address)).then(data => commonProcess(data))
return this.get('/cosmos/bank/v1beta1/balances/'.concat(address)).then(data => commonProcess(data).balances)
}
async getStakingReward(address, config = null) {
@ -379,7 +389,7 @@ export default class ChainFetch {
}
async getStakingValidators(address) {
return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/validators`).then(data => commonProcess(data))
return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/validators?pagination.size=200`).then(data => commonProcess(data.validators))
}
async getStakingDelegations(address, config = null) {
@ -413,7 +423,7 @@ export default class ChainFetch {
}
async getBankBalances(address, config = null) {
return this.get('/bank/balances/'.concat(address), config).then(data => commonProcess(data))
return this.get('/cosmos/bank/v1beta1/balances/'.concat(address), config).then(data => commonProcess(data))
}
async getCommunityPool(config = null) {
@ -458,7 +468,7 @@ export default class ChainFetch {
}
static async getBankBalance(baseurl, address) {
return ChainFetch.fetch(baseurl, '/bank/balances/'.concat(address)).then(data => commonProcess(data))
return ChainFetch.fetch(baseurl, '/cosmos/bank/v1beta1/balances/'.concat(address)).then(data => commonProcess(data))
}
async getGravityPools() {

View File

@ -1,5 +1,5 @@
import {
Bech32, fromBase64, fromBech32, fromHex, toBech32, toHex,
Bech32, fromBase64, fromBech32, fromHex, toBase64, toBech32, toHex,
} from '@cosmjs/encoding'
import { sha256, stringToPath } from '@cosmjs/crypto'
// ledger
@ -193,6 +193,15 @@ export function getUserCurrencySign() {
export function consensusPubkeyToHexAddress(consensusPubkey) {
let raw = null
if (typeof consensusPubkey === 'object') {
if (consensusPubkey['@type'] === '/cosmos.crypto.ed25519.PubKey') {
raw = toBase64(fromHex(toHex(sha256(fromBase64(consensusPubkey.key))).slice(0, 40)))
return raw
}
// /cosmos.crypto.secp256k1.PubKey
if (consensusPubkey['@type'] === '/cosmos.crypto.secp256k1.PubKey') {
raw = toBase64(fromHex(new RIPEMD160().update(Buffer.from(sha256(fromBase64(consensusPubkey.key)))).digest('hex')))
return raw
}
if (consensusPubkey.type === 'tendermint/PubKeySecp256k1') {
raw = new RIPEMD160().update(Buffer.from(sha256(fromBase64(consensusPubkey.value)))).digest('hex').toUpperCase()
return raw

View File

@ -403,18 +403,13 @@ const router = new VueRouter({
})
router.beforeEach((to, from, next) => {
const c = String(to.params.chain).toLowerCase()
const configs = JSON.parse(localStorage.getItem('chains'))
const conf = Object.values(configs).find(i => i.chain_name === c || i.alias === c)
if (!configs || conf) {
if (configs && to.params.chain) {
const c = String(to.params.chain).toLowerCase()
const conf = Object.values(configs).find(i => i.chain_name === c || i.alias === c)
if (conf) {
store.commit('select', { chain_name: conf.chain_name })
}
next()
} else if (c) {
if (c === 'index.php') {
next({ name: '/' })
next()
} else {
next({ name: 'chain-404' })
}

View File

@ -120,10 +120,6 @@ export default {
this.latestTime = toDay(res.block.header.time, 'long')
})
this.$http.getMarketChart().then(res => {
this.marketData = res
})
this.$http.getStakingParameters().then(res => {
this.staking = this.normalize(res, 'Staking Parameters')
Promise.all([this.$http.getStakingPool(), this.$http.getBankTotal(res.bond_denom)])

View File

@ -259,7 +259,6 @@
:total-rows="transactions.total_count"
:per-page="transactions.limit"
:value="transactions.page_number"
align="center"
class="mt-1"
@change="pageload"
/>

View File

@ -11,7 +11,7 @@
<b-card-title>
Starting New Node From State Sync
</b-card-title>
<b class="mt-1">1. Install Binary (Version: {{ version }})</b><br>
<b class="mt-1">1. Install Binary (Version: {{ app_version }})</b><br>
We need to install the binary first and make sure that the version is the one currently in use on mainnet.
<br><br>
<b class="mt-1">2. Enable State Sync</b><br>
@ -69,7 +69,8 @@ export default {
data() {
const { rpc, snapshot_provider } = this.$store.state.chains.selected
let servers = ''
if (rpc && Array.isArray(rpc)) {
console.log('rpc', rpc)
if (rpc && Array.isArray(rpc) && rpc.length > 0) {
let serv = rpc
if (serv.length === 1) {
serv = serv.concat(serv)
@ -88,7 +89,7 @@ export default {
? `# Comma separated list of nodes to keep persistent connections to \npersistent_peers = "${peers}" `
: 'OMG There is NO available providers, but you can try it.'
return {
version: '',
app_version: '',
snapshot_provider,
servers,
providers,
@ -125,9 +126,9 @@ trust_period = "168h" # 2/3 of unbonding time`
})
}
this.$http.getNodeInfo().then(res => {
this.version = res.application_version.version
this.app_version = res.application_version.version
this.daemon = res.application_version.app_name
})
}).catch()
})
},
methods: {

View File

@ -108,7 +108,7 @@ import {
import {
consensusPubkeyToHexAddress, getCachedValidators, timeIn, toDay,
} from '@/libs/utils'
import { Bech32, toHex } from '@cosmjs/encoding'
import { fromBech32, toBase64 } from '@cosmjs/encoding'
export default {
components: {
@ -171,7 +171,7 @@ export default {
if (res.info) {
res.info.forEach(x => {
if (x.address) {
const hex = toHex(Bech32.decode(x.address).data).toUpperCase()
const hex = toBase64(fromBech32(x.address).data)
this.missing[hex] = x
}
})

View File

@ -324,9 +324,12 @@ export default {
if (this.address) {
return this.address
}
const chain = this.$store.state.chains.selected.chain_name
const selectedAddress = this.accounts.address.find(x => x.chain === chain)
return selectedAddress?.addr
if (this.accounts) {
const chain = this.$store.state.chains.selected.chain_name
const selectedAddress = this.accounts?.address.find(x => x.chain === chain)
return selectedAddress?.addr
}
return null
},
selectedChain() {
let config = null