Skip to content

Commit

Permalink
Ana/111 regen testnet production (#118)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Bitcoinera authored and faboweb committed Nov 26, 2019
1 parent 30bb928 commit 5e0dcf3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
25 changes: 25 additions & 0 deletions data/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@
"default": true,
"stakingDenom": "ATOM"
},
"regen-testnet": {
"id": "regen-testnet",
"title": "Regen Testnet",
"chain_id": "congo-1",
"rpc_url": "wss://regen-congo-1.lunie.io/websocket",
"api_url": "https://regen-congo-1.lunie.io",
"bech32_prefix": "xrn:",
"testnet": true,
"feature_session": true,
"feature_portfolio": true,
"feature_validators": true,
"feature_proposals": true,
"feature_activity": true,
"feature_explorer": true,
"action_send": true,
"action_claim_rewards": true,
"action_delegate": true,
"action_redelegate": true,
"action_undelegate": true,
"action_deposit": true,
"action_vote": true,
"action_proposal": true,
"default": true,
"stakingDenom": "TREE"
},
"terra-testnet": {
"id": "terra-testnet",
"title": "Terra",
Expand Down
7 changes: 7 additions & 0 deletions lib/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const resolvers = require('./resolvers')
const CosmosNodeSubscription = require('./cosmos-node-subscription')
const CosmosV0API = require('./cosmosV0-source')
const CosmosV2API = require('./cosmosV2-source')
const RegenV0API = require('./regenV0-source')
const TerraV3API = require('./terraV3-source')
const LunieDBAPI = require('./luniedb-source')
const BlockStore = require('./block-store')
Expand Down Expand Up @@ -40,6 +41,11 @@ function startBlockHandlers() {
TerraV3API,
store['terra-testnet']
)
new CosmosNodeSubscription(
networks['regen-testnet'],
RegenV0API,
store['regen-testnet']
)

if (config.enableTestnet) {
new CosmosNodeSubscription(
Expand All @@ -56,6 +62,7 @@ function createDataSources() {
const dataSources = {
CosmosHubMainnetAPI: new CosmosV0API(networks['cosmos-hub-mainnet']),
CosmosHubTestnetAPI: new CosmosV2API(networks['cosmos-hub-testnet']),
RegenTestnetAPI: new RegenV0API(networks['regen-testnet']),
TerraTestnetAPI: new TerraV3API(networks['terra-testnet']),
LunieDBAPI: new LunieDBAPI(),
store: store
Expand Down
11 changes: 11 additions & 0 deletions lib/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ const queries = {
}
}
`,
regen_testnet_validatorprofiles: selection => `
query {
regen_testnet_validatorprofiles${selection} {
details
name
picture
operator_address
website
}
}
`,
terra_testnet_validatorprofiles: selection => `
query {
terra_testnet_validatorprofiles${selection} {
Expand Down
5 changes: 5 additions & 0 deletions lib/reducers/regenV0-reducers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const cosmosV0Reducers = require('./cosmosV0-reducers')

module.exports = {
...cosmosV0Reducers
}
38 changes: 38 additions & 0 deletions lib/regenV0-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const CosmosV0API = require('./cosmosV0-source')
const { transactionReducer } = require('./reducers/cosmosV0-reducers')
const { uniqWith, sortBy, reverse } = require('lodash')

class RegenV0API extends CosmosV0API {
constructor(network) {
super(network)

this.delegatorBech32Prefix = `xrn:`
this.validatorConsensusBech32Prefix = `xrn:valcons`
}
setReducers() {
this.reducers = require('./reducers/regenV0-reducers')
}

async getTransactionsByHeight(height) {
const { txs } = await this.get(`txs?tx.height=${height}`)
return Array.isArray(txs)
? txs.map(transaction => this.reducers.transactionReducer(transaction))
: []
}

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

const txs = await Promise.all([
this.get(`/txs?sender=${address}${pagination}`).then(({ txs }) => txs),
this.get(`/txs?recipient=${address}${pagination}`).then(({ txs }) => txs)
]).then(([senderTxs, recipientTxs]) => [].concat(senderTxs, recipientTxs))

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

module.exports = RegenV0API
2 changes: 2 additions & 0 deletions lib/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function selectFrom(dataSources, networkId) {
return dataSources.CosmosHubMainnetAPI
case 'cosmos-hub-testnet':
return dataSources.CosmosHubTestnetAPI
case 'regen-testnet':
return dataSources.RegenTestnetAPI
case 'local-cosmos-hub-testnet':
return dataSources.TestnetAPI
case 'terra-testnet':
Expand Down

0 comments on commit 5e0dcf3

Please sign in to comment.