-
Notifications
You must be signed in to change notification settings - Fork 0
/
readinfo.js
71 lines (60 loc) · 2.21 KB
/
readinfo.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
"use strict";
const fs = require('fs');
const util = require('util');
const db = require('intervaluecore/db.js');
const conf = require('intervaluecore/conf.js');
const desktopApp = require('intervaluecore/desktop_app.js');
var readline = require('readline');
var appDataDir = desktopApp.getAppDataDir();
var KEYS_FILENAME = appDataDir + '/' + (conf.KEYS_FILENAME || 'keys.json');
var item = {};
// READ mnemonic
var readmem = function readKeys(){
console.log("\n Read mnemonic...........\n");
fs.readFile(KEYS_FILENAME, 'utf8', function(err, data){
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
//terminal: true
});
if (err){
console.log('failed to read keys.conf, you should generate a headless-wallet first!');
throw Error('failed to read key.conf: '+err);
}
else{
rl.question("Passphrase: ", function(passphrase){
rl.close();
if (process.stdout.moveCursor) process.stdout.moveCursor(0, -1);
if (process.stdout.clearLine) process.stdout.clearLine();
var keys = JSON.parse(data);
item.passphrase = passphrase; // add passphrase attrbuite
item.mnemonic_phrase = keys.mnemonic_phrase;
item.temp_priv_key = keys.temp_priv_key;
item.prev_temp_priv_key = keys.prev_temp_priv_key;
readkeys();
});
}
});
};
// READ definition first!!!
var readkeys = function(){
db.query("SELECT * FROM my_addresses", function(rows){
console.log("\n Read definition...........\n");
if (rows.length < 1 ) {
console.log('my_addresses has no entry, you should creat a headless-wallet first!!! ');
process.exit(0);
}
// console.log(JSON.stringify(rows[0], null,2));
var row = rows[0];
item.address = row.address;
item.wallet = row.wallet;
item.is_change = row.is_change;
item.address_index = row.address_index;
item.definition = JSON.parse(row.definition);
item.creation_date = row.creation_date;
console.log("\nShow Local wallet info........... >>\n\n"
+ JSON.stringify(item, null, 2));
process.exit(0);
});
};
readmem();