From 851f7c174e2dc8b5c5d4a5568b811958c2d33b77 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Thu, 24 Nov 2022 21:32:05 +0800 Subject: [PATCH 1/8] fetch from provider chain --- src/libs/fetch.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libs/fetch.js b/src/libs/fetch.js index efa523be..16bc1de5 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -128,8 +128,8 @@ export default class ChainFetch { // return ret // }) return Promise.all([ - this.get(`/cosmos/distribution/v1beta1/validators/${address}/commission`), - this.get(`/cosmos/distribution/v1beta1/validators/${address}/outstanding_rewards`), + this.get(`/cosmos/distribution/v1beta1/validators/${address}/commission`, null, true), + this.get(`/cosmos/distribution/v1beta1/validators/${address}/outstanding_rewards`, null, true), ]).then(data => { const ret = ValidatorDistribution.create({ operator_address: address, @@ -159,7 +159,7 @@ export default class ChainFetch { } async getStakingPool() { - return this.get('/cosmos/staking/v1beta1/pool').then(data => new StakingPool().init(commonProcess(data.pool))) + return this.get('/cosmos/staking/v1beta1/pool', null, true).then(data => new StakingPool().init(commonProcess(data.pool))) } async getMintingInflation() { @@ -176,7 +176,7 @@ export default class ChainFetch { } async getStakingParameters() { - return this.get('/cosmos/staking/v1beta1/params').then(data => { + return this.get('/cosmos/staking/v1beta1/params', null, true).then(data => { this.getSelectedConfig() return StakingParameters.create(commonProcess(data.params), this.config.chain_name) }) @@ -223,7 +223,7 @@ export default class ChainFetch { } async getStakingValidator(address) { - return this.get(`/cosmos/staking/v1beta1/validators/${address}`).then(data => new Validator().init(commonProcess(data).validator)) + return this.get(`/cosmos/staking/v1beta1/validators/${address}`, null, true).then(data => new Validator().init(commonProcess(data).validator)) } async getSlashingParameters() { @@ -277,7 +277,7 @@ export default class ChainFetch { } async getDistributionParameters() { - return this.get('/cosmos/distribution/v1beta1/params').then(data => commonProcess(data.params)) + return this.get('/cosmos/distribution/v1beta1/params', null, true).then(data => commonProcess(data.params)) } async getGovernanceParameterDeposit() { @@ -421,22 +421,22 @@ export default class ChainFetch { async getStakingReward(address, config = null) { if (compareVersions(config ? config.sdk_version : this.config.sdk_version, '0.40') < 0) { - return this.get(`/distribution/delegators/${address}/rewards`, config).then(data => commonProcess(data)) + return this.get(`/distribution/delegators/${address}/rewards`, config, true).then(data => commonProcess(data)) } - return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/rewards`, config).then(data => commonProcess(data)) + return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/rewards`, config, true).then(data => commonProcess(data)) } async getValidatorSlashs(address, config = null) { - return this.get(`/cosmos/distribution/v1beta1/validators/${address}/slashes`, config).then(data => commonProcess(data)) + return this.get(`/cosmos/distribution/v1beta1/validators/${address}/slashes`, config, true).then(data => commonProcess(data)) } async getStakingValidators(address) { - return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/validators?pagination.size=200`).then(data => commonProcess(data.validators)) + return this.get(`/cosmos/distribution/v1beta1/delegators/${address}/validators?pagination.size=200`, null, true).then(data => commonProcess(data.validators)) } async getStakingDelegations(address, config = null) { if (compareVersions(config ? config.sdk_version : this.config.sdk_version, '0.40') < 0) { - return this.get(`/staking/delegators/${address}/delegations`, config).then(data => commonProcess(data).map(x => { + return this.get(`/staking/delegators/${address}/delegations`, config, true).then(data => commonProcess(data).map(x => { const xh = x if (!xh.delegation) { xh.delegation = { @@ -447,21 +447,21 @@ export default class ChainFetch { return xh })) } - return this.get(`/cosmos/staking/v1beta1/delegations/${address}`, config).then(data => commonProcess(data)) + return this.get(`/cosmos/staking/v1beta1/delegations/${address}`, config, true).then(data => commonProcess(data)) } async getStakingRedelegations(address, config = null) { if (compareVersions(config ? config.sdk_version : this.config.sdk_version, '0.40') < 0) { - return this.get(`/staking/redelegations?delegator=${address}`, config).then(data => commonProcess(data)) + return this.get(`/staking/redelegations?delegator=${address}`, config, true).then(data => commonProcess(data)) } - return this.get(`/cosmos/staking/v1beta1/delegators/${address}/redelegations`, config).then(data => commonProcess(data)) + return this.get(`/cosmos/staking/v1beta1/delegators/${address}/redelegations`, config, true).then(data => commonProcess(data)) } async getStakingUnbonding(address, config = null) { if (compareVersions(config ? config.sdk_version : this.config.sdk_version, '0.40') < 0) { - return this.get(`/staking/delegators/${address}/unbonding_delegations`, config).then(data => commonProcess(data)) + return this.get(`/staking/delegators/${address}/unbonding_delegations`, config, true).then(data => commonProcess(data)) } - return this.get(`/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`, config).then(data => commonProcess(data)) + return this.get(`/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`, config, true).then(data => commonProcess(data)) } async getBankBalances(address, config = null) { @@ -469,7 +469,7 @@ export default class ChainFetch { } async getCommunityPool(config = null) { - return this.get('/cosmos/distribution/v1beta1/community_pool', config).then(data => commonProcess(data)) + return this.get('/cosmos/distribution/v1beta1/community_pool', config, true).then(data => commonProcess(data)) } async getAllIBCDenoms(config = null) { From 91c779a7e4cb7ca07bc5b3b23213921934d23d38 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 25 Nov 2022 09:31:34 +0800 Subject: [PATCH 2/8] compatible to 0.46.6 --- src/libs/data/proposal-tally.js | 10 ++++----- src/libs/data/proposal.js | 13 ++++++----- src/libs/fetch.js | 33 +++++++++++++++++++--------- src/views/GovernanceProposalView.vue | 29 +++++++++++------------- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/libs/data/proposal-tally.js b/src/libs/data/proposal-tally.js index 0bbb0b44..578436c7 100644 --- a/src/libs/data/proposal-tally.js +++ b/src/libs/data/proposal-tally.js @@ -9,16 +9,16 @@ export default class ProposalTally { } init(element, total) { - const subtotal = Number(element.yes) + Number(element.no) + Number(element.abstain) + Number(element.no_with_veto) + const subtotal = Number(element.yes || element.yes_count) + Number(element.no || element.no_count) + Number(element.abstain || element.abstain_count) + Number(element.no_with_veto || element.no_with_veto_count) if (total < 1) { this.total = subtotal + 1 } else { this.total = total } - this.yes = Number(element.yes) / this.total - this.no = Number(element.no) / this.total - this.veto = Number(element.no_with_veto) / this.total - this.abstain = Number(element.abstain) / this.total + this.yes = Number(element.yes || element.yes_count) / this.total + this.no = Number(element.no || element.no_count) / this.total + this.veto = Number(element.no_with_veto || element.no_with_veto_count) / this.total + this.abstain = Number(element.abstain || element.abstain_count) / this.total this.turnout = subtotal / this.total return this } diff --git a/src/libs/data/proposal.js b/src/libs/data/proposal.js index 6efe3cfc..056007a7 100644 --- a/src/libs/data/proposal.js +++ b/src/libs/data/proposal.js @@ -16,6 +16,7 @@ export default class Proposal { this.voting_start_time = '0000-00-00' this.total_deposit = '-' this.contents = null + this.metadata = {} } init(element, total) { @@ -29,15 +30,12 @@ export default class Proposal { this.voting_start_time = element.voting_start_time // eslint-disable-next-line prefer-destructuring this.total_deposit = element.total_deposit[0] - this.contents = element.content.value || element.content + if (element.content) this.contents = element.content.value || element.content if (this.contents) { this.title = this.contents.title this.description = this.contents.description - this.type = element.content.type - if (element.content['@type']) { - this.type = element.content['@type'] - } } + this.metadata = element.metadata return this } @@ -51,6 +49,11 @@ export default class Proposal { versionFixed(ver) { if (compareVersions(ver, '0.46') >= 0) { + [this.contents] = this.element.messages + if (this.contents['@type'] === '/cosmos.gov.v1.MsgExecLegacyContent') { + this.title = this.contents.content.title + this.description = this.contents.content.description + } if (this.element.metadata) { this.title = this.element.metadata.title || this.element.metadata this.description = this.element.metadata.description || this.element.metadata diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 16bc1de5..979b8fe6 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -281,19 +281,23 @@ export default class ChainFetch { } async getGovernanceParameterDeposit() { - return this.get('/cosmos/gov/v1beta1/params/deposit').then(data => commonProcess(data.deposit_params)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/params/deposit`).then(data => commonProcess(data.deposit_params)) } async getGovernanceParameterTallying() { - return this.get('/cosmos/gov/v1beta1/params/tallying').then(data => commonProcess(data.tally_params)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/params/tallying`).then(data => commonProcess(data.tally_params)) } async getGovernanceParameterVoting() { - return this.get('/cosmos/gov/v1beta1/params/voting').then(data => commonProcess(data.voting_params)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/params/voting`).then(data => commonProcess(data.voting_params)) } async getGovernanceTally(pid, total, conf) { - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/tally`, conf).then(data => new ProposalTally().init(commonProcess(data).tally, total)) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}/tally`, conf).then(data => new ProposalTally().init(commonProcess(data).tally, total)) } getGovernance(pid) { @@ -303,7 +307,9 @@ export default class ChainFetch { return p }) } - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}`).then(data => { + + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}`).then(data => { const p = new Proposal().init(commonProcess(data).proposal, 0) p.versionFixed(this.config.sdk_version) return p @@ -324,7 +330,9 @@ export default class ChainFetch { return Array.isArray(result) ? result.reverse().map(d => new Deposit().init(d)) : result }) } - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/deposits`).then(data => { + + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}/deposits`).then(data => { const result = commonProcess(data) return Array.isArray(result) ? result.reverse().map(d => new Deposit().init(d)) : result }) @@ -340,12 +348,15 @@ export default class ChainFetch { if (this.config.chain_name === 'shentu') { return this.get(`/shentu/gov/v1alpha1/proposals/${pid}/votes?pagination.key=${encodeURIComponent(next)}&pagination.limit=${limit}&pagination.reverse=true`) } - return this.get(`/cosmos/gov/v1beta1/proposals/${pid}/votes?pagination.key=${encodeURIComponent(next)}&pagination.limit=${limit}&pagination.reverse=true`) + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + return this.get(`/cosmos/gov/${ver}/proposals/${pid}/votes?pagination.key=${encodeURIComponent(next)}&pagination.limit=${limit}&pagination.reverse=true`) } async getGovernanceListByStatus(status, chain = null) { const conf = chain || this.config - const url = conf.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals?pagination.limit=100&proposal_status=${status}` : `/cosmos/gov/v1beta1/proposals?pagination.limit=100&proposal_status=${status}` + + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' + const url = conf.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals?pagination.limit=100&proposal_status=${status}` : `/cosmos/gov/${ver}/proposals?pagination.limit=100&proposal_status=${status}` return this.get(url, conf).then(data => { let proposals = commonProcess(data) if (Array.isArray(proposals.proposals)) { @@ -367,9 +378,10 @@ export default class ChainFetch { } async getGovernanceProposalVote(pid, voter, chain) { + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' const url = this.config.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals/${pid}/votes/${voter}` - : `/cosmos/gov/v1beta1/proposals/${pid}/votes/${voter}` + : `/cosmos/gov/${ver}/proposals/${pid}/votes/${voter}` return this.get(url, chain).then(data => { if (data.code === 3) { throw new Error('not found') @@ -385,9 +397,10 @@ export default class ChainFetch { async getGovernanceList(next = '', chain = null) { const key = next || '' + const ver = compareVersions(this.config.sdk_version, '0.46.5') < 0 ? 'v1beta1' : 'v1' const url = this.config.chain_name === 'shentu' ? `/shentu/gov/v1alpha1/proposals?pagination.limit=20&pagination.reverse=true&pagination.key=${key}` - : `/cosmos/gov/v1beta1/proposals?pagination.limit=20&pagination.reverse=true&pagination.key=${key}` + : `/cosmos/gov/${ver}/proposals?pagination.limit=20&pagination.reverse=true&pagination.key=${key}` return this.get(url, chain).then(data => { let proposals = commonProcess(data) if (Array.isArray(proposals.proposals)) { diff --git a/src/views/GovernanceProposalView.vue b/src/views/GovernanceProposalView.vue index ead05968..d0807b78 100644 --- a/src/views/GovernanceProposalView.vue +++ b/src/views/GovernanceProposalView.vue @@ -42,6 +42,11 @@ +
+
- {{ $t('proposal_proposer') }} - - {{ formatAddress(proposer.proposer) }} - - - - {{ $t('proposal_total_deposit') }} {{ formatToken(proposal.total_deposit) }} @@ -70,13 +68,13 @@ {{ $t('voting_time') }} {{ formatDate(proposal.voting_start_time) }} - {{ formatDate(proposal.voting_end_time) }} + + + Metadata + {{ proposal.metadata }} + -
-
@@ -395,10 +393,9 @@ export default { if (!getCachedValidators()) { this.$http.getValidatorList() } - - this.$http.getGovernanceProposer(pid).then(res => { - this.proposer = res - }) + // this.$http.getGovernanceProposer(pid).then(res => { + // this.proposer = res + // }) this.$http.getGovernanceDeposits(pid).then(res => { this.deposits = res }).catch(() => {}) From 072efbb5a6eaddf165b8f2361608e6c3ed37d2f5 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 25 Nov 2022 17:12:31 +0800 Subject: [PATCH 3/8] compatible to v0.46.6 --- src/libs/fetch.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 979b8fe6..4ea24d81 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -145,6 +145,9 @@ export default class ChainFetch { } async getBankTotal(denom) { + if (compareVersions(this.config.sdk_version, '0.46.5') > 0) { + return this.get(`/cosmos/bank/v1beta1/supply/by_denom?denom=${denom}`).then(data => commonProcess(data).amount) + } if (compareVersions(this.config.sdk_version, '0.40') < 0) { return this.get(`/supply/total/${denom}`).then(data => ({ amount: commonProcess(data), denom })) } From c337a4519ec3005048a6d23a275127add95bea24 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 25 Nov 2022 18:54:07 +0800 Subject: [PATCH 4/8] estimate with custom block time --- src/libs/data/proposal.js | 5 +++++ src/views/GovernanceProposalView.vue | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/libs/data/proposal.js b/src/libs/data/proposal.js index 056007a7..5b62cfcf 100644 --- a/src/libs/data/proposal.js +++ b/src/libs/data/proposal.js @@ -34,6 +34,10 @@ export default class Proposal { if (this.contents) { this.title = this.contents.title this.description = this.contents.description + this.type = element.content.type + if (element.content['@type']) { + this.type = element.content['@type'] + } } this.metadata = element.metadata return this @@ -50,6 +54,7 @@ export default class Proposal { versionFixed(ver) { if (compareVersions(ver, '0.46') >= 0) { [this.contents] = this.element.messages + if (this.contents) this.type = this.contents['@type'] if (this.contents['@type'] === '/cosmos.gov.v1.MsgExecLegacyContent') { this.title = this.contents.content.title this.description = this.contents.content.description diff --git a/src/views/GovernanceProposalView.vue b/src/views/GovernanceProposalView.vue index d0807b78..16e28dbd 100644 --- a/src/views/GovernanceProposalView.vue +++ b/src/views/GovernanceProposalView.vue @@ -68,7 +68,7 @@ {{ $t('voting_time') }} {{ formatDate(proposal.voting_start_time) }} - {{ formatDate(proposal.voting_end_time) }} - + Metadata {{ proposal.metadata }} @@ -80,6 +80,21 @@ {{ $t('upgrade_time') }} {{ upgradeTime }} + + + + 7s + + + 6s + + + 2s + + + 1s + + @@ -263,7 +278,7 @@