|
|
|
@ -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,23 +102,33 @@ 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 }))
|
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
|
if (compareVersions(this.config.sdk_version, '0.40') < 0) {
|
|
|
|
@ -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() {
|
|
|
|
|