forked from yeasy/docker-hyperledger
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fabric-rest.js
executable file
·43 lines (38 loc) · 981 Bytes
/
fabric-rest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/node
// fabric-rest.js method args
var fs = require('fs')
var async = require('async')
var jsonfile = require('jsonfile')
var argv = require('minimist')(process.argv.slice(2))
var Client = require('node-rest-client').Client;
var client = new Client();
var local = "http://localhost:5000";
var filename = argv["_"][0]
var args = {
};
function run_data(method, data) {
client.registerMethod("method", local + method.method, method.action);
client.methods.method({data: data,
headers:
{"Content-Type": "application/json"}},
function(data, response) {
console.log(data);
});
}
jsonfile.readFile(argv["_"][0], function(err, method) {
if (err != null) {
console.log(err);
} else {
if (argv["_"][1] != undefined) {
jsonfile.readFile(argv['_'][1], function(err, data) {
if (err != null) {
console.log(err);
} else {
run_data(method, data);
}
});
} else {
run_data(method, {});
}
}
});