-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
231 lines (214 loc) · 7.81 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
var axios = require('axios'),
util = require("util");
const address = "1HE4ShfmuG7AdVr5RpaCtXfsJYYQQFCj1T";
const addresses = [ "2N68EF7dYiUGVUHAGoWtYFXo7NfRvNraGjn",
"2N6tZe936iWaWVKwQ6TN2uHE9uVSh1SfsBR",
"2MsSBqgqWFF5ovaYTWHa3vZwFsGzKR6wbgX",
"2N1YzttARiNVhdkGp2h1XBEsqQDwLHWjrH8",
"2N5HTfb8UyqdFo2v6A83JeT9hiHaEfRXUxv",
"2N8fcrnV1HttHcexih26QYLU5rfTS3Yddis",
"2N96SZhn4mZvEcYGEMjpaB5haYDDXrZvBky",
"2Mt5rnziEwX6h3cjQajTu6dNKMTXYTGRERp",
"2NARDqFg9Lv9afpahJurRpdeXJCHnDsMEXW",
"2N5a6DbXyaYeTgcDyf6wQGERs8qGfijjobJ",
"2N4mSidD6yCcZg1vN1i4mGptaqQuQPq2vDH",
"2N4U2ntSXan3avkjdj7KBFFDqpMdjrTpUs4",
"2NGCeqXe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N9wjafmzVhFAp5iVBnwNyhK15e4oHw9TJB",
"2NBunDFwGZCRckGqpqTYsAhSpEtdWhbdSMY",
"2N7Jou8jaRQEywEPRBaLsFURBzcij1qUvhi",
"2N2vqx1xK2dspNK5ivmFxJrcHgJrPGJFH1L",
"2N6yduEYT1yFGoEvKFSSQCii116wGA5KBAo",
"2NDJa9M8FyR2V8ERReunhC6dogArYquaSyk",
"2MxWUH73djkdVfB7evBZeBX5nWSBYtDndX9",
"2N63UddJ181bPzqBWKpVHyc28MAN56u9TWA",
"2N3WntYSmk1E3jj8fJfEobVbp3sKAm5d5cF",
"2NBRV23x4L8aogCpb11k9r2gm2xQJLg2USA"];
//lazy loading
var binding = null;
function loadBinding(){
if(!binding){
binding = require('bindings')('ledgerapp_nodejs');
}
}
/*
Http request to initialize NJSHttpModule
callback: NJSCallbackModule to recursively request token + txs
*/
const axiosRequest = (url,headers,callback) => {
const header = {
method: 'get',
url: url
}
//Headers may be a string 'No headers'
if(typeof headers === 'object'){
var tokenHeader ={}
tokenHeader[headers['0']] = headers['1'];
header['headers'] = tokenHeader;
}
axios(header).then(function(response) {
//console.log(JSON.stringify(response.data))
callback.onSuccess(JSON.stringify(response.data));
}).catch(reject => {
console.log("Reject: ",reject.message)
});
}
/*
NJSHttpModule
Test Module with a simple http call to Ledger Api
*/
function NJSHttpModule(req) {
loadBinding();
//inherit from binding.ledgerapp_nodejs
//try binding.ledgerapp_nodejsapply(this,argument)
var thisPlusArgs = new Array(arguments.length + 1);
thisPlusArgs[0] = null;
for(var i = 0; i < arguments.length; i++)
thisPlusArgs[i + 1] = arguments[i];
this._raw = new (Function.prototype.bind.apply(binding.NJSHttpModule,
thisPlusArgs))(req);
//inherit from this._raw
for(var j in binding.NJSHttpModule.prototype){
this[j] = binding.NJSHttpModule.prototype[j].bind(this._raw);
}
}
/*
NJSCallbackModule
*/
function NJSCallbackModule() {
loadBinding();
//inherit from binding.ledgerapp_nodejs
//try binding.ledgerapp_nodejsapply(this,argument)
var thisPlusArgs = new Array(arguments.length + 1);
thisPlusArgs[0] = null;
for(var i = 0; i < arguments.length; i++)
thisPlusArgs[i + 1] = arguments[i];
this._raw = new (Function.prototype.bind.apply(binding.NJSCallbackModule,
thisPlusArgs))();
//inherit from this._raw
for(var j in binding.NJSCallbackModule.prototype){
this[j] = binding.NJSCallbackModule.prototype[j].bind(this._raw);
}
}
/*
NJSThreadDispatcher
Test Module to provide contexts and dispatch tasks into them
*/
function NJSThreadDispatcher() {
loadBinding();
var thisPlusArgs = new Array(arguments.length + 1);
thisPlusArgs[0] = null;
for(var i = 0; i < arguments.length; i++)
thisPlusArgs[i + 1] = arguments[i];
this._raw = new (Function.prototype.bind.apply(binding.NJSThreadDispatcher,
thisPlusArgs))();
//inherit from this._raw
for(var i in binding.NJSThreadDispatcher.prototype)
this[i] = binding.NJSThreadDispatcher.prototype[i].bind(this._raw);
}
/*
Main Api
*/
function NJSApi() {
loadBinding();
var thisPlusArgs = new Array(arguments.length + 1);
thisPlusArgs[0] = null;
for(var i = 0; i < arguments.length; i++)
thisPlusArgs[i + 1] = arguments[i];
this._raw = new (Function.prototype.bind.apply(binding.NJSApi,
thisPlusArgs))();
//inherit from this._raw
for(var i in binding.NJSApi.prototype)
this[i] = binding.NJSApi.prototype[i].bind(this._raw);
}
/*
Observer to listen on Api updates
*/
function NJSTransactionListVmObserver() {
loadBinding();
var thisPlusArgs = new Array(arguments.length + 1);
thisPlusArgs[0] = null;
for(var i = 0; i < arguments.length; i++)
thisPlusArgs[i + 1] = arguments[i];
this._raw = new (Function.prototype.bind.apply(binding.NJSTransactionListVmObserver,
thisPlusArgs))();
//inherit from this._raw
for(var i in binding.NJSTransactionListVmObserver.prototype)
this[i] = binding.NJSTransactionListVmObserver.prototype[i].bind(this._raw);
}
/*
Test
*/
function getTransactions(addresses, testnetMode) {
return new Promise(resolve => {
const LGHttp = new NJSHttpModule(axiosRequest);
const LGThreadDispatcher = new NJSThreadDispatcher();
const LGApi = new NJSApi(LGHttp._raw, LGThreadDispatcher._raw);
const LGObserver = new NJSTransactionListVmObserver(LGApi._raw);
LGObserver._raw.start(addresses, testnetMode, txs => {
resolve(txs.map(JSON.parse));
LGObserver._raw.stop();
});
});
}
exports.getTransactions = getTransactions;
exports.axiosRequest = axiosRequest;
exports.NJSHttpModule = NJSHttpModule;
exports.NJSApi = NJSApi;
exports.NJSThreadDispatcher = NJSThreadDispatcher;
exports.NJSTransactionListVmObserver = NJSTransactionListVmObserver;