From 52b9e2c341c282d42405b7e20d4d965af046fe6f Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 11 Dec 2019 16:01:09 +0100 Subject: [PATCH] release (#179) * fixed a bug where a single proposal would not load (#125) * trigger ci * fixed missing terra data source (#128) * Fabo/fix missing terra db query (#130) * fixed missing terra data source * fixed missing query * Fabo/fix failing staking query for terra (#132) * fixed missing terra data source * fixed missing query * fix bech32 prefix in selfStake resolver * linted * Fabo/hide proposals on terra (#134) * fixed missing terra data source * fixed missing query * fix bech32 prefix in selfStake resolver * linted * don't show proposals on terra * Fabo/switch to yarn (#122) * switch to yarn * Update Readme * Ana/111 regen testnet production (#118) * regen is home * fix websocket link * eslint fix * delete console logs * fixed regen source (using cosmosV0) * add feature flags for regen * fix txs in regen * fix transactions per address * fix eslint errors * disable sign in * colw/Transaction Service (#120) * Obtain transaction payload, mirror back to client * Respond with request, or error if none present * Load node friendly versions of cosmos-api for dev * Send response as JSON * Successfully retrieve a gas estimate - Use node-fetch for cosmosAPIs - * Add two sub routes: /estimate and /broadcast * Add account number and sequence to overview query * Disable cors options * Add support to broadcast messages * Ignore fetch undefined * Delete package-lock.json * Fabo/simplify queries (#108) * simplified db queries Conflicts: lib/luniedb-source.js lib/queries.js * switched to yarn * clean up * clean up * Copy cosmos libraries into container (#143) * Aleksei/terra url change (#144) * terra url changed * change soju-0010 to soju-0012 * fixed db queries (#147) * Update networks.json (#149) * Fabo/events (#123) * first steps * working notification endpoint * remove push mentions * linted * fixes * updated schema * use enum for eventtype * working subscription * linted * added push to express routes * remove newer code * linted * Update lib/routes/push.js Co-Authored-By: Col * disable session for regen (#155) * Aleksei/terra url change (#146) * terra url changed * change soju-0010 to soju-0012 * cors added to caddyfiles * cors added to caddyfiles * fix missing path * Fabo/fix vote count (#157) * fixed vote count calculation * linted * Ana/handle with message proposal id error (#159) * handle undefined proposal error * fix lint errors * Ana/add endtime to undelegation tx (#150) * add liquiddate as field for tx * fix eslint errors * change name liquidDate to undelegationEndTime * fix enddelegationtime for gaia * improve reducer my way * fix lint error * move undelegationendtime to reducer * fix lint errors * no abbreviations * implement undelegation endtime reducer in both * reenable session for gaia 13006 (#165) * Ana/fix terra undelegationendtime reducer (#162) * change reducers to cosmosV2 * prevent result undefined error * add own gettransaction and txreducer for terra * fix terra undelegationendtime reducer * fix lint errors * avoid hardcoded indexes * small fix to prevent total server error * no redundancy: add reducers to transactionreducer * fix lint * trigger CI * Don't return delegations with dust amounts (#171) * Add filter to delegations * Fix filter * Simplify * add undelegations to total stake (#174) * Terra chain_id switched to soju-0013 (#176) * terra chaind_id switched to soju-0013 * changed terra node * fix issues with undelegatio end time (#175) * Fabo/fix undelegationendtime (#177) * fix issues with undelegatio end time * catch undelegation attribute not found * Fabo/fix undelegationendtime for regen (#178) * fix issues with undelegatio end time * catch undelegation attribute not found * fix regen transaction reducers * Display Deposit Period End Date correctly for proposals in deposit period (#181) * Return proposal.voting_end_time in deposit period * Return deposit_end_time instead --- data/networks.json | 6 +++--- lib/cosmosV0-source.js | 12 +++++++++++- lib/reducers/cosmosV0-reducers.js | 16 +++++++++++++--- lib/reducers/cosmosV2-reducers.js | 17 +++++++++++------ lib/reducers/terraV3-reducers.js | 31 ++++++++++++++++++------------- lib/regenV0-source.js | 8 ++++++-- 6 files changed, 62 insertions(+), 28 deletions(-) diff --git a/data/networks.json b/data/networks.json index 7c6cf4fb62..04a0e965aa 100644 --- a/data/networks.json +++ b/data/networks.json @@ -77,9 +77,9 @@ "terra-testnet": { "id": "terra-testnet", "title": "Terra", - "chain_id": "soju-0012", - "api_url": "http://terra-soju-0012.lunie.io/", - "rpc_url": "wss://terra-soju-0012.lunie.io/websocket", + "chain_id": "soju-0013", + "api_url": "http://terra-testnet.lunie.io/", + "rpc_url": "wss://terra-testnet.lunie.io/websocket", "bech32_prefix": "terra", "testnet": true, "feature_session": false, diff --git a/lib/cosmosV0-source.js b/lib/cosmosV0-source.js index 5fd77c870f..0e02099ad0 100644 --- a/lib/cosmosV0-source.js +++ b/lib/cosmosV0-source.js @@ -365,12 +365,21 @@ class CosmosV0API extends PerBlockCacheDataSource { } async getOverview(delegatorAddress, validatorsDictionary) { - const [balances, delegations, stakingDenom] = await Promise.all([ + const [ + balances, + delegations, + undelegations, + stakingDenom + ] = await Promise.all([ this.getBalancesFromAddress(delegatorAddress), this.getDelegationsForDelegatorAddress( delegatorAddress, validatorsDictionary ), + this.getUndelegationsForDelegatorAddress( + delegatorAddress, + validatorsDictionary + ), this.getStakinDenom() ]) const rewards = await this.getRewards( @@ -381,6 +390,7 @@ class CosmosV0API extends PerBlockCacheDataSource { return this.reducers.overviewReducer( balances, delegations, + undelegations, rewards, stakingDenom ) diff --git a/lib/reducers/cosmosV0-reducers.js b/lib/reducers/cosmosV0-reducers.js index f420ac1d7c..c89ec6f18c 100644 --- a/lib/reducers/cosmosV0-reducers.js +++ b/lib/reducers/cosmosV0-reducers.js @@ -18,7 +18,7 @@ function proposalBeginTime(proposal) { function proposalEndTime(proposal) { switch (proposal.proposal_status.toLowerCase()) { case 'depositperiod': - return proposal.voting_start_time + return proposal.deposit_end_time case 'votingperiod': // the end time lives in the past already if the proposal is finalized // eslint-disable-next-line no-fallthrough @@ -299,7 +299,13 @@ function rewardReducer(reward, validator) { } } -function overviewReducer(balances, delegations, rewards, stakingDenom) { +function overviewReducer( + balances, + delegations, + undelegations, + rewards, + stakingDenom +) { stakingDenom = denomLookup(stakingDenom) const totalRewards = _.flatten(rewards) @@ -316,12 +322,16 @@ function overviewReducer(balances, delegations, rewards, stakingDenom) { (sum, { amount }) => BigNumber(sum).plus(amount), 0 ) + const undelegatingStake = undelegations.reduce( + (sum, { amount }) => BigNumber(sum).plus(amount), + 0 + ) return { // rewards, totalRewards: totalRewards, liquidStake: liquidStake, - totalStake: liquidStake.plus(delegatedStake) + totalStake: liquidStake.plus(delegatedStake).plus(undelegatingStake) } } diff --git a/lib/reducers/cosmosV2-reducers.js b/lib/reducers/cosmosV2-reducers.js index c6933bde56..5de6c28e71 100644 --- a/lib/reducers/cosmosV2-reducers.js +++ b/lib/reducers/cosmosV2-reducers.js @@ -93,12 +93,17 @@ function validatorReducer( } function undelegationEndTimeReducer(transaction) { - if ( - transaction.events[1].attributes.find(tx => tx.key === `completion_time`) - ) { - return transaction.events[1].attributes.filter( - tx => tx.key === `completion_time` - )[0].value + if (transaction.events) { + let completionTimeAttribute + transaction.events.find(({ attributes }) => { + if (attributes) { + completionTimeAttribute = attributes.find( + tx => tx.key === `completion_time` + ) + } + return !!completionTimeAttribute + }) + return completionTimeAttribute ? completionTimeAttribute.value : undefined } else { return null } diff --git a/lib/reducers/terraV3-reducers.js b/lib/reducers/terraV3-reducers.js index c34d77dddc..9095485948 100644 --- a/lib/reducers/terraV3-reducers.js +++ b/lib/reducers/terraV3-reducers.js @@ -2,19 +2,24 @@ const cosmosV2Reducers = require('./cosmosV2-reducers') // Terra has a slightly different structure and needs its own undelegationEndTimeReducer function undelegationEndTimeReducer(transaction) { - if (transaction.logs[0].events.length > 2) { - let endTime - const attributes = Object.values(transaction.logs[0].events).map( - event => event.attributes - ) - attributes.forEach(attribute => - attribute.map(tx => { - if (tx.key === `completion_time`) { - endTime = tx.value - } - }) - ) - return endTime ? endTime : null + if (transaction.logs) { + let completionTimeAttribute + transaction.logs.find(({ events }) => { + if (events) { + events.find(({ attributes }) => { + if (attributes) { + completionTimeAttribute = attributes.find( + tx => tx.key === `completion_time` + ) + } + return !!completionTimeAttribute + }) + } + return !!completionTimeAttribute + }) + return completionTimeAttribute ? completionTimeAttribute.value : undefined + } else { + return null } } diff --git a/lib/regenV0-source.js b/lib/regenV0-source.js index 3cc3813bb5..42dc5fecf7 100644 --- a/lib/regenV0-source.js +++ b/lib/regenV0-source.js @@ -16,7 +16,9 @@ class RegenV0API extends CosmosV0API { async getTransactionsByHeight(height) { const { txs } = await this.get(`txs?tx.height=${height}`) return Array.isArray(txs) - ? txs.map(transaction => this.reducers.transactionReducer(transaction)) + ? txs.map(transaction => + this.reducers.transactionReducer(transaction, this.reducers) + ) : [] } @@ -31,7 +33,9 @@ class RegenV0API extends CosmosV0API { const dupFreeTxs = uniqWith(txs, (a, b) => a.txhash === b.txhash) const sortedTxs = sortBy(dupFreeTxs, ['timestamp']) const reversedTxs = reverse(sortedTxs) - return reversedTxs.map(transactionReducer) + return reversedTxs.map(transaction => + transactionReducer(transaction, this.reducers) + ) } }