-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
38 lines (33 loc) · 964 Bytes
/
client.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
const litecoin = require('litecoin');
function callRpc(cmd, args, rpc) {
const fn = args[args.length-1];
if (typeof fn === 'function') {
args.pop();
rpc.call(cmd, args, function() {
const args = [].slice.call(arguments);
args.unshift(null);
fn.apply(this, args);
}, fn);
} else {
return new Promise((resolve, reject) => {
rpc.call(cmd, args, function(){
const args = [].slice.call(arguments);
args.unshift(null);
resolve(args[1]);
}, reject);
});
}
}
(function() {
Object.getOwnPropertyNames(litecoin.Client.prototype)
.filter((p) => typeof litecoin.Client.prototype[p] === 'function' && p !== "cmd" && p!= "constructor")
.forEach(method =>
(function(protoFn) {
litecoin.Client.prototype[protoFn] = function() {
const args = [].slice.call(arguments);
return callRpc(protoFn.toLowerCase(), args, this.rpc);
};
})(method)
);
})();
module.exports = litecoin.Client;