diff --git a/app/src/main/index.js b/app/src/main/index.js index 5e58a6200e..e89004a095 100644 --- a/app/src/main/index.js +++ b/app/src/main/index.js @@ -1,4 +1,4 @@ -'use strict' + 'use strict' let { app, BrowserWindow, Menu } = require('electron') let fs = require('fs-extra') @@ -11,6 +11,7 @@ let event = require('event-to-promise') let toml = require('toml') let pkg = require('../../../package.json') let rmdir = require('../helpers/rmdir.js') +let mockServer = require('./mockServer.js') let shuttingDown = false let mainWindow @@ -404,9 +405,12 @@ async function main () { await initBaseserver(chainId, baseserverHome, nodeIP) } - log('starting baseserver') + log('starting gaia server') baseserverProcess = await startBaseserver(baseserverHome) - log('baseserver ready') + log('gaia server ready') + + // start mock API server on port 8999 + mockServer(8999) } module.exports = Object.assign( main() diff --git a/app/src/main/mockServer.js b/app/src/main/mockServer.js new file mode 100644 index 0000000000..16c878ec8b --- /dev/null +++ b/app/src/main/mockServer.js @@ -0,0 +1,42 @@ +let express = require('express') +let proxy = require('express-http-proxy') +let randomBytes = require('crypto').pseudoRandomBytes + +let randomPubkey = () => ({ + type: 'ed25519', + data: randomBytes(32).toString('hex') +}) + +module.exports = function (port = 8999) { + let app = express() + + // delegation mock API + let candidates = new Array(205).fill(0).map(randomPubkey) + app.get('/query/stake/candidate', (req, res) => { + res.json({ + height: 10000, + data: candidates + }) + }) + app.get('/query/stake/candidate/:pubkey', (req, res) => { + res.json({ + height: 10000, + data: { + pubkey: randomPubkey(), + owner: { + chain: 'gaia-1', + app: 'sig', + address: randomBytes(20).toString('hex') + }, + shares: Math.floor(Math.random() * 1e7), + voting_power: Math.floor(Math.random() * 1e5), + description: 'This is a fake candidate description.' + } + }) + }) + + // proxy everything else to light client + app.use(proxy('http://localhost:8998')) + + app.listen(port) +} diff --git a/app/src/renderer/node.js b/app/src/renderer/node.js index c52694712e..5ea6db26c7 100644 --- a/app/src/renderer/node.js +++ b/app/src/renderer/node.js @@ -6,7 +6,8 @@ const RpcClient = require('tendermint') let sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) module.exports = async function (nodeIP) { - let rest = RestClient() + // TODO: once we're done with the mock API server, switch this from port 8999 to 8998 + let rest = RestClient('http://localhost:8999') let rpc = RpcClient(`ws://${nodeIP}`) // TODO: handle disconnect, try to reconnect // TODO: eventually, get all data from light-client connection instead of RPC diff --git a/package.json b/package.json index 168cfdc7ea..769cafc516 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,8 @@ "eslint-plugin-html": "^2.0.0", "eslint-plugin-promise": "^3.4.0", "eslint-plugin-standard": "^2.0.1", + "express": "^4.16.2", + "express-http-proxy": "^1.1.0", "extract-text-webpack-plugin": "^2.0.0-beta.4", "fast-future": "^1.0.2", "file-loader": "^0.9.0", diff --git a/yarn.lock b/yarn.lock index 0b5b7bd13a..6eb7d8cbb8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2045,7 +2045,7 @@ de-indent@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d" -debug@*, debug@^3.1.0: +debug@*, debug@^3.0.1, debug@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" dependencies: @@ -2585,7 +2585,7 @@ es6-map@^0.1.3: es6-symbol "~3.1.1" event-emitter "~0.3.5" -es6-promise@^4.0.5: +es6-promise@^4.0.5, es6-promise@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.1.1.tgz#8811e90915d9a0dba36274f0b242dbda78f9c92a" @@ -2874,7 +2874,15 @@ expect@^21.2.1: jest-message-util "^21.2.1" jest-regex-util "^21.2.0" -express@^4.13.3: +express-http-proxy@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/express-http-proxy/-/express-http-proxy-1.1.0.tgz#b533842add15b7021d78d248c80b53578a7b6ba0" + dependencies: + debug "^3.0.1" + es6-promise "^4.1.1" + raw-body "^2.3.0" + +express@^4.13.3, express@^4.16.2: version "4.16.2" resolved "https://registry.yarnpkg.com/express/-/express-4.16.2.tgz#e35c6dfe2d64b7dca0a5cd4f21781be3299e076c" dependencies: @@ -6546,7 +6554,7 @@ range-parser@^1.0.3, range-parser@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" -raw-body@2.3.2: +raw-body@2.3.2, raw-body@^2.3.0: version "2.3.2" resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89" dependencies: