@@ -42,7 +42,8 @@ var networks = {
42
42
"167.114.29.53:4002" ,
43
43
"167.114.29.54:4002" ,
44
44
"167.114.29.55:4002"
45
- ]
45
+ ] ,
46
+ ledgerpath : "44'/1'/"
46
47
} ,
47
48
mainnet : {
48
49
nethash : "6e84d08bd299ed97c212c886c98a57e36545c8f5d645ca7eeae63a8bd62d8988" ,
@@ -93,7 +94,8 @@ var networks = {
93
94
"193.70.72.88:4001" ,
94
95
"193.70.72.89:4001" ,
95
96
"193.70.72.90:4001"
96
- ]
97
+ ] ,
98
+ ledgerpath : "44'/111'/"
97
99
}
98
100
} ;
99
101
@@ -179,7 +181,7 @@ function postTransaction(container, transaction, cb){
179
181
}
180
182
181
183
function getFromNode ( url , cb ) {
182
- nethash = network ?network . nethash :"" ;
184
+ let nethash = network ?network . nethash :"" ;
183
185
request (
184
186
{
185
187
url : url ,
@@ -247,14 +249,23 @@ function getAccount(container, seriesCb) {
247
249
}
248
250
}
249
251
252
+ function resetLedger ( ) {
253
+ ledgerAccounts = [ ] ;
254
+ ledgerBridge = null ;
255
+ if ( ledgerComm !== null ) {
256
+ ledgerComm . close_async ( ) ;
257
+ ledgerComm = null ;
258
+ }
259
+ }
260
+
250
261
async function populateLedgerAccounts ( ) {
251
262
if ( ! ledgerBridge ) {
252
263
return ;
253
264
}
254
265
ledgerAccounts = [ ] ;
255
266
var accounts = [ ] ;
256
267
var account_index = 0 ;
257
- var path = "44'/111'/" ;
268
+ var path = network . hasOwnProperty ( 'ledgerpath' ) ? network . ledgerpath : "44'/111'/" ;
258
269
var empty = false ;
259
270
260
271
while ( ! empty ) {
@@ -282,11 +293,22 @@ async function populateLedgerAccounts() {
282
293
( body ) => { accountData = body }
283
294
) ;
284
295
if ( ! accountData || accountData . success === false ) {
296
+ // Add an empty available account when 0 transactions have been made.
285
297
empty = true ;
286
- result = null ;
298
+ result . accountData = {
299
+ address : result . address ,
300
+ unconfirmedBalance : "0" ,
301
+ balance : "0" ,
302
+ publicKey : result . publicKey ,
303
+ unconfirmedSignature : 0 ,
304
+ secondSignature : 0 ,
305
+ secondPublicKey : null ,
306
+ multisignatures : [ ] ,
307
+ u_multisignatures : [ ]
308
+ } ;
287
309
} else {
288
310
result . accountData = accountData . account ;
289
- }
311
+ }
290
312
}
291
313
} catch ( e ) {
292
314
console . log ( 'no request:' , e ) ;
@@ -345,20 +367,24 @@ ledgerWorker.on('message', function (message) {
345
367
ledgerBridge = new LedgerArk ( ledgerComm ) ;
346
368
populateLedgerAccounts ( ) ;
347
369
} ) . fail ( ( error ) => {
348
- //console .log('ledger error: ', error);
370
+ //vorpal .log(colors.red( 'ledger error: ' + error) );
349
371
} ) ;
350
372
} else if ( ! message . connected && ledgerComm ) {
351
373
vorpal . log ( 'Ledger App Disconnected' ) ;
352
- ledgerComm . close_async ( ) ;
353
- ledgerComm = null ;
354
- ledgerBridge = null ;
355
- ledgerAccounts = [ ] ;
374
+ resetLedger ( ) ;
356
375
} ;
357
376
} ) ;
358
377
359
378
vorpal
360
379
. command ( 'connect <network>' , 'Connect to network. Network is devnet or mainnet' )
361
380
. action ( function ( args , callback ) {
381
+ // reset an existing connection first
382
+ if ( server ) {
383
+ server = null ;
384
+ network = null ;
385
+ resetLedger ( ) ;
386
+ }
387
+
362
388
var self = this ;
363
389
network = networks [ args . network ] ;
364
390
@@ -400,6 +426,13 @@ function connect2network(n, callback){
400
426
vorpal
401
427
. command ( 'connect node <url>' , 'Connect to a server. For example "connect node 5.39.9.251:4000"' )
402
428
. action ( function ( args , callback ) {
429
+ // reset an existing connection first
430
+ if ( server ) {
431
+ server = null ;
432
+ network = null ;
433
+ resetLedger ( ) ;
434
+ }
435
+
403
436
var self = this ;
404
437
server = args . url ;
405
438
getFromNode ( 'http://' + server + '/api/blocks/getNethash' , function ( err , response , body ) {
@@ -450,6 +483,7 @@ vorpal
450
483
self . delimiter ( 'ark>' ) ;
451
484
server = null ;
452
485
network = null ;
486
+ resetLedger ( ) ;
453
487
callback ( ) ;
454
488
} ) ;
455
489
0 commit comments