Skip to content

Commit

Permalink
release (#173)
Browse files Browse the repository at this point in the history
* 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 <colw@users.noreply.github.com>

* 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
  • Loading branch information
faboweb authored Dec 6, 2019
1 parent c3029cf commit b2683ab
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Installation
## Installation

Clone the repository:

Expand Down
2 changes: 1 addition & 1 deletion data/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"api_url": "https://gaia-13006.lunie.io",
"bech32_prefix": "cosmos",
"testnet": true,
"feature_session": false,
"feature_session": true,
"feature_portfolio": true,
"feature_validators": true,
"feature_proposals": true,
Expand Down
38 changes: 28 additions & 10 deletions lib/cosmosV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const BigNumber = require('bignumber.js')
const _ = require('lodash')
const { uniqWith, sortBy, reverse } = require('lodash')
const { encodeB32, decodeB32, pubkeyToAddress } = require('./tools')
const { UserInputError } = require('apollo-server')

class CosmosV0API extends PerBlockCacheDataSource {
constructor(network) {
Expand Down Expand Up @@ -44,7 +45,6 @@ class CosmosV0API extends PerBlockCacheDataSource {
const involvedAddresses = transaction.tags.reduce((addresses, tag) => {
// temporary in here to identify why this fails
if (!tag.value) {
console.log(JSON.stringify(transaction))
return addresses
}
if (tag.value.startsWith(`cosmos`)) {
Expand All @@ -58,7 +58,9 @@ class CosmosV0API extends PerBlockCacheDataSource {
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)
)
: []
}

Expand Down Expand Up @@ -195,13 +197,18 @@ class CosmosV0API extends PerBlockCacheDataSource {
}

async getProposalById({ proposalId }) {
const proposal = await this.query(`gov/proposals/${proposalId}`).catch(
() => {
throw new UserInputError(
`There is no proposal in the network with ID '${proposalId}'`
)
}
)
const [
proposal,
tally,
proposer,
{ bonded_tokens: totalBondedTokens }
] = await Promise.all([
this.query(`gov/proposals/${proposalId}`),
this.query(`/gov/proposals/${proposalId}/tally`),
this.query(`gov/proposals/${proposalId}/proposer`).catch(() => {
return { proposer: `unknown` }
Expand Down Expand Up @@ -270,12 +277,21 @@ class CosmosV0API extends PerBlockCacheDataSource {
let delegations =
(await this.query(`staking/delegators/${address}/delegations`)) || []

return delegations.map(delegation =>
this.reducers.delegationReducer(
delegation,
validatorsDictionary[delegation.validator_address]
return delegations
.filter(delegation =>
BigNumber(
this.reducers.calculateTokens(
validatorsDictionary[delegation.validator_address],
delegation.shares
)
).isGreaterThanOrEqualTo(1e-6)
)
.map(delegation =>
this.reducers.delegationReducer(
delegation,
validatorsDictionary[delegation.validator_address]
)
)
)
}

async getUndelegationsForDelegatorAddress(address, validatorsDictionary) {
Expand Down Expand Up @@ -399,7 +415,9 @@ class CosmosV0API extends PerBlockCacheDataSource {
const duplicateFreeTxs = uniqWith(txs, (a, b) => a.txhash === b.txhash)
const sortedTxs = sortBy(duplicateFreeTxs, ['timestamp'])
const reversedTxs = reverse(sortedTxs)
return reversedTxs.map(this.reducers.transactionReducer)
return reversedTxs.map(tx =>
this.reducers.transactionReducer(tx, this.reducers)
)
}

async awaitUp() {
Expand Down
10 changes: 6 additions & 4 deletions lib/cosmosV2-source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const CosmosV0API = require('./cosmosV0-source')

const { transactionReducer } = require('./reducers/cosmosV0-reducers')
const { uniqWith, sortBy, reverse } = require('lodash')

class CosmosV2API extends CosmosV0API {
Expand Down Expand Up @@ -33,7 +31,9 @@ class CosmosV2API 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(tx =>
this.reducers.transactionReducer(tx, this.reducers)
)
}

extractInvolvedAddresses(transaction) {
Expand Down Expand Up @@ -67,7 +67,9 @@ class CosmosV2API 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)
)
: []
}

Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/tendermint.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function tendermintConnect() {

const subscription = this.subscriptions.find(({ id }) => eventId === id)
if (subscription) {
if (isSubscriptionEvent) {
if (isSubscriptionEvent && result) {
subscription.callback(result.data.value)
return
}
Expand Down
24 changes: 19 additions & 5 deletions lib/reducers/cosmosV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function getTotalVotePercentage(proposal, totalBondedTokens, totalVoted) {
if (proposalFinalized(proposal)) return -1
if (BigNumber(totalVoted).eq(0)) return 0
if (!totalBondedTokens) return -1
return BigNumber(totalBondedTokens)
.div(atoms(totalVoted))
return BigNumber(totalVoted)
.div(atoms(totalBondedTokens))
.toNumber()
}

Expand Down Expand Up @@ -346,7 +346,17 @@ function getGroupByType(transactionType) {
return transactionGroup[transactionType] || 'unknown'
}

function transactionReducer(transaction) {
function undelegationEndTimeReducer(transaction) {
if (transaction.tags) {
if (transaction.tags.find(tx => tx.key === `end-time`)) {
return transaction.tags.filter(tx => tx.key === `end-time`)[0].value
}
} else {
return null
}
}

function transactionReducer(transaction, reducers) {
try {
let fee = coinReducer(false)
if (Array.isArray(transaction.tx.value.fee.amount)) {
Expand All @@ -371,7 +381,8 @@ function transactionReducer(transaction) {
fee,
signature: transaction.tx.value.signatures[0].signature,
value: JSON.stringify(transaction.tx.value.msg[0].value),
raw: transaction
raw: transaction,
undelegationEndTime: reducers.undelegationEndTimeReducer(transaction)
}

return result
Expand Down Expand Up @@ -399,12 +410,15 @@ module.exports = {
rewardReducer,
overviewReducer,
accountInfoReducer,
calculateTokens,
undelegationEndTimeReducer,

atoms,
proposalBeginTime,
proposalEndTime,
getDeposit,
getTotalVotePercentage,
getValidatorStatus,
expectedRewardsPerToken
expectedRewardsPerToken,
getGroupByType
}
15 changes: 14 additions & 1 deletion lib/reducers/cosmosV2-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,22 @@ 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
} else {
return null
}
}

module.exports = {
...cosmosV0Reducers,
proposalReducer,
delegationReducer,
validatorReducer
validatorReducer,
undelegationEndTimeReducer
}
23 changes: 21 additions & 2 deletions lib/reducers/terraV3-reducers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
const cosmosV0Reducers = require('./cosmosV0-reducers')
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
}
}

module.exports = {
...cosmosV0Reducers
...cosmosV2Reducers,
undelegationEndTimeReducer
}
1 change: 1 addition & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const typeDefs = gql`
signature: String!
value: String!
amount: String
undelegationEndTime: String
}
type GovernanceParameters {
Expand Down
32 changes: 0 additions & 32 deletions lib/terraV3-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,6 @@ class TerraV3API extends CosmosV2API {
)
)
}

// async getTransactions(address) {
// const pagination = `&limit=${1000000000}`

// const txs = await Promise.all([
// this.get(`/txs?sender=${address}${pagination}`),
// this.get(`/txs?recipient=${address}${pagination}`),
// this.get(`/txs?action=submit_proposal&proposer=${address}${pagination}`),
// this.get(`/txs?action=deposit&depositor=${address}${pagination}`),
// this.get(`/txs?action=vote&voter=${address}${pagination}`),
// // this.get(`/txs?action=create_validator&destination-validator=${valAddress}`), // TODO
// // this.get(`/txs?action=edit_validator&destination-validator=${valAddress}`), // TODO
// this.get(`/txs?action=delegate&delegator=${address}${pagination}`),
// this.get(
// `/txs?action=begin_redelegate&delegator=${address}${pagination}`
// ),
// this.get(`/txs?action=begin_unbonding&delegator=${address}${pagination}`),
// // this.get(`/txs?action=unjail&source-validator=${address}`), // TODO
// // this.get(`/txs?action=set_withdraw_address&delegator=${address}`), // other
// this.get(
// `/txs?action=withdraw_delegator_reward&delegator=${address}${pagination}`
// ),
// this.get(
// `/txs?action=withdraw_validator_rewards_all&source-validator=${address}${pagination}`
// )
// ]).then(transactionGroups => [].concat(...transactionGroups))

// const duplicateFreeTxs = uniqWith(txs, (a, b) => a.txhash === b.txhash)
// const sortedTxs = sortBy(duplicateFreeTxs, ['timestamp'])
// const reversedTxs = reverse(sortedTxs)
// return reversedTxs.map(this.reducers.transactionReducer)
// }
}

module.exports = TerraV3API

0 comments on commit b2683ab

Please sign in to comment.