Skip to content

Commit

Permalink
Ana/add endtime to undelegation tx (#150)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
faboweb authored Dec 2, 2019
1 parent 07cfcde commit bcc302b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/cosmosV2-source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const CosmosV0API = require('./cosmosV0-source')

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

class CosmosV2API extends CosmosV0API {
Expand Down
14 changes: 12 additions & 2 deletions lib/reducers/cosmosV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ function getGroupByType(transactionType) {
return transactionGroup[transactionType] || 'unknown'
}

function undelegationEndTimeReducer(transaction) {
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) {
try {
let fee = coinReducer(false)
Expand All @@ -371,7 +379,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: undelegationEndTimeReducer(transaction)
}

return result
Expand Down Expand Up @@ -406,5 +415,6 @@ module.exports = {
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
}
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

0 comments on commit bcc302b

Please sign in to comment.