diff --git a/src/rpc/index.js b/src/rpc/index.js index 34fe499..925a3d6 100644 --- a/src/rpc/index.js +++ b/src/rpc/index.js @@ -2,23 +2,29 @@ This is the parent class library for the RPC controller. */ +// Public npm libraries const jsonrpc = require('jsonrpc-lite') +// Local support libraries +const UserController = require('./users') + let _this class JSONRPC { constructor (localConfig) { // Encapsulate dependencies this.jsonrpc = jsonrpc + this.userController = new UserController() _this = this } // This method takes a raw string of data from IPFS, parses it, and determins // which controller to route the instruction to. - router (str) { + router (str, from) { try { console.log('router str: ', str) + console.log('router from: ', from) const parsedData = _this.jsonrpc.parse(str) console.log('parsedData: ', parsedData) @@ -28,6 +34,14 @@ class JSONRPC { if (parsedData.type === 'invalid') { return } + + switch (parsedData.payload.id) { + case 'users': + _this.userController.userRouter(parsedData) + break + // case default: + // TODO: Return an error + } } catch (err) { console.error('Error in rpc router(): ', err) // Do not throw error. This is a top-level function. diff --git a/src/rpc/users/index.js b/src/rpc/users/index.js index 37b34f2..9d73cd6 100644 --- a/src/rpc/users/index.js +++ b/src/rpc/users/index.js @@ -6,6 +6,26 @@ class UsersRPC { constructor (localConfig) { console.log('instantiating UsersRPC') } + + userRouter (rpcData) { + try { + console.log('userRouter rpcData: ', rpcData) + + if (rpcData.payload.method === 'getAll') this.getAll() + } catch (err) { + console.error('Error in UsersRPC/rpcRouter()') + throw err + } + } + + async getAll () { + try { + console.log('Executing get all') + } catch (err) { + console.error('Error in getAll()') + throw err + } + } } module.exports = UsersRPC