Skip to content

Commit

Permalink
Fabo/fix failed txs parsing (#486)
Browse files Browse the repository at this point in the history
* publish v2 txs and fix failed txs parsing

* linted
  • Loading branch information
faboweb authored Mar 20, 2020
1 parent e964912 commit 5a21530
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
20 changes: 2 additions & 18 deletions lib/block-listeners/cosmos-node-subscription.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const _ = require('lodash')
const {
publishBlockAdded,
publishUserTransactionAdded,
publishUserTransactionAddedV2,
publishEvent: publishEvent
} = require('../subscriptions')
Expand All @@ -27,9 +26,6 @@ class CosmosNodeSubscription {
this.db = new database(config)(networkSchemaName)
this.chainHangup = undefined
this.height = undefined
this.cosmosAPI
.getStakingDenom()
.then(stakingDenom => (this.stakingDenom = stakingDenom))

this.pollForNewBlock()
}
Expand All @@ -38,7 +34,7 @@ class CosmosNodeSubscription {
this.pollingTimeout = setTimeout(async () => {
let block
try {
block = await this.cosmosAPI.getBlockByHeight()
block = await this.cosmosAPI.getBlockByHeightV2()
} catch (error) {
console.error('Failed to fetch block', error)
Sentry.captureException(error)
Expand Down Expand Up @@ -94,14 +90,6 @@ class CosmosNodeSubscription {
// transaction to each subscribed user.
// TODO doesn't handle failing txs as it doesn't extract addresses from those txs (they are not tagged)
block.transactions.forEach(tx => {
// update tx to v2
let txV2 = this.cosmosAPI.reducers.transactionReducerV2(
{
...tx.raw
},
this.cosmosAPI.reducers,
this.stakingDenom
)
let addresses = []
try {
this.cosmosAPI.extractInvolvedAddresses(tx.raw).forEach(address => {
Expand All @@ -115,11 +103,7 @@ class CosmosNodeSubscription {
}
addresses = _.uniq(addresses)
addresses.forEach(address => {
publishUserTransactionAdded(this.network.id, address, tx)
// txv2 returns array, so its zero element could not be set for some reasons
txV2.map(txMsg =>
publishUserTransactionAddedV2(this.network.id, address, txMsg)
)
publishUserTransactionAddedV2(this.network.id, address, tx)
publishEvent(this.network.id, 'transaction', address, tx)
})
})
Expand Down
5 changes: 4 additions & 1 deletion lib/reducers/cosmosV0-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,10 @@ function transactionReducerV2(transaction, reducers, stakingDenom) {
timestamp: transaction.timestamp,
memo: transaction.tx.value.memo,
fees,
success: transaction.logs ? transaction.logs[index].success || false : false
success:
transaction.logs && transaction.logs[index]
? transaction.logs[index].success || false
: false
}))
return returnedMessages
}
Expand Down

0 comments on commit 5a21530

Please sign in to comment.