Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const jayson = require('jayson');
// create a server
const server = jayson.server({
jsonrpcSuccess: function (args, callback) {
callback(null, args[0] + args[1]);
},
jsonrpcError: function (args, callback) {
callback({ code: 0, message: JSON.stringify(args) });
},
jsonrpcTimeoutSuccess: function (args, callback) {
setTimeout(() => {
callback(null, args[0] + args[1]);
}, 100);
},
jsonrpcTimeoutError: function (args, callback) {
setTimeout(() => {
callback(null, args[0] + args[1]);
}, 1000);
}
function init(conf) {
const {
rpcNodePort,
} = conf;
serverRPC = express();
serverRPC.use(cors({ methods: ['POST'] }));
serverRPC.use(bodyParser.urlencoded({ extended: true }));
serverRPC.use(bodyParser.json());
serverRPC.set('trust proxy', true);
serverRPC.set('trust proxy', 'loopback');
serverRPC.post('/blockchain', jayson.server(blockchainRPC()).middleware());
serverRPC.post('/contracts', jayson.server(contractsRPC()).middleware());
http.createServer(serverRPC)
.listen(rpcNodePort, () => {
console.log(`RPC Node now listening on port ${rpcNodePort}`); // eslint-disable-line
});
}
function init(conf) {
const {
rpcNodePort,
} = conf;
serverRPC = express();
serverRPC.use(cors({ methods: ['POST'] }));
serverRPC.use(bodyParser.urlencoded({ extended: true }));
serverRPC.use(bodyParser.json());
serverRPC.set('trust proxy', true);
serverRPC.set('trust proxy', 'loopback');
serverRPC.post('/blockchain', jayson.server(blockchainRPC()).middleware());
serverRPC.post('/contracts', jayson.server(contractsRPC()).middleware());
http.createServer(serverRPC)
.listen(rpcNodePort, () => {
console.log(`RPC Node now listening on port ${rpcNodePort}`); // eslint-disable-line
});
}
receivedConnections[uuid] = {};
}
return true;
}
function handleSetClipboardValueRequest({ uuid, value }) {
console.log(Date.now(), `${processUUID} has new value '${value}' from ${uuid}`);
clipboard.writeText(value);
previousClipboardValue = value; // This avoids the just-received value from being sent out
return true;
}
let jsonRpcServer = jayson.server({
getName(args, callback) {
callback(null, handleGetNameRequest());
},
connect(args, callback) {
if (!objectHas(args, ['uuid'])) {
callback(() => ({
error: 'Invalid request',
}));
}
else {
callback(null, handleConnectRequest(args));
}
},
setClipboardValue(args, callback) {
if (!objectHas(args, ['uuid', 'value'])) {
callback(() => ({
import jayson from "jayson";
import models from "./models";
import RPCInterfaces from "./RPCInterfaces";
import { SERVICE_USER_PORT, NODE_ENV } from "./config/secrets";
// create a server
const server = jayson.server(RPCInterfaces);
models.sequelize.sync().then(() => {
server
.http()
.listen(SERVICE_USER_PORT, () =>
console.log(
` User Service listenning on port ${SERVICE_USER_PORT} in "${NODE_ENV}" mode`
)
);
});
import jayson from "jayson";
import { SERVICE_MOVIE_PORT, NODE_ENV } from "./config/secrets";
import ESClient from "./config/ESClient.config";
import RPCInterface from "./RPCInterfaces";
// create a server
const server = jayson.server(RPCInterface);
ESClient.ping({ requestTimeout: 30000 }, error => {
if (error) {
console.error(`Elasticsearch connection failed: ${error}`);
} else {
console.log("Elasticsearch connection success");
}
});
server
.http()
.listen(SERVICE_MOVIE_PORT, () =>
console.log(
` Movie Service listenning on port ${SERVICE_MOVIE_PORT} in "${NODE_ENV}" mode`
)
);
async initJSONRPCServer()
{
var self = this;
console.log('listening on JSONRPC server localhost:8080')
// create a server
var server = jayson.server({
ping: function(args, callback) {
callback(null, 'pong');
},
getPoolProtocolVersion: function(args, callback) {
return "1.02";
},
getPoolEthAddress: function(args, callback) {
callback(null, self.getMintHelperAddress().toString() );
module.exports = async (bridgeState, tendermintPort, db, app) => {
const withParams = method => {
return params => method(...params);
};
const { nodeApi, methodsWithCallback } = getMethods(
bridgeState,
db,
app,
tendermintPort
);
api.use(jayson.server(methodsWithCallback).middleware());
return {
listenHttp: async ({ host, port }) => {
return new Promise(resolve => {
const server = api.listen(port || 8645, host || 'localhost', () => {
resolve(server.address());
});
});
},
listenWs: ({ host, port }) => {
const wsServer = new WsJsonRpcServer({
port: port || 8646,
host: host || 'localhost',
});
// register an RPC method
startRPC (methods, port = 3000) {
const server = jayson.server(methods)
const httpServer = server.http()
httpServer.listen(port)
return httpServer
},