feat(JSON RPC): Added initial router for JSON RPC

This commit is contained in:
Chris Troutner
2021-03-30 18:05:48 -07:00
parent 7fdd7be52a
commit 3e5a42329f
3 changed files with 23 additions and 2 deletions
+5 -1
View File
@@ -15,6 +15,8 @@ const config = require('../config') // this first.
const IPFSLib = require('../src/lib/ipfs')
const AdminLib = require('../src/lib/admin')
const adminLib = new AdminLib()
const JSONRPC = require('../src/rpc')
const rpc = new JSONRPC()
const errorMiddleware = require('../src/middleware')
const wlogger = require('../src/lib/wlogger')
@@ -71,7 +73,9 @@ async function startServer () {
if (success) console.log('System admin user created.')
// Start the IPFS node.
const ipfsLib = new IPFSLib()
const ipfsLib = new IPFSLib({
rpc
})
await ipfsLib.start()
return app
+7 -1
View File
@@ -14,6 +14,11 @@ class IPFSLib {
this.IPFS = IPFS
this.IpfsCoord = IpfsCoord
this.bchjs = new BCHJS()
this.rpc = {}
if (localConfig.rpc) {
this.rpc = localConfig.rpc
}
}
// This is a 'macro' start method. It kicks off several smaller methods that
@@ -57,7 +62,8 @@ class IPFSLib {
this.ipfsCoord = new this.IpfsCoord({
ipfs: this.ipfs,
type: 'node.js',
bchjs: this.bchjs
bchjs: this.bchjs,
privateLog: this.rpc.router
})
await this.ipfsCoord.isReady()
+11
View File
@@ -6,6 +6,17 @@ class JSONRPC {
constructor (localConfig) {
console.log('instantiating JSONRPC')
}
// This method takes a raw string of data from IPFS, parses it, and determins
// which controller to route the instruction to.
router (str) {
try {
console.log('router str: ', str)
} catch (err) {
console.error('Error in rpc router()')
throw err
}
}
}
module.exports = JSONRPC