rpc: importwallet.

This commit is contained in:
Christopher Jeffrey 2016-08-19 20:46:52 -07:00
parent d6e4978baf
commit 0873f7abe8
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 46 additions and 2 deletions

View File

@ -3110,7 +3110,9 @@ RPC.prototype.importprivkey = function importprivkey(args, callback) {
};
RPC.prototype.importwallet = function importwallet(args, callback) {
var file, data;
var self = this;
var file, keys, lines, line, parts;
var i, secret, time, label, addr;
if (args.help || args.length !== 1)
return callback(new RPCError('importwallet "filename"'));
@ -3121,6 +3123,48 @@ RPC.prototype.importwallet = function importwallet(args, callback) {
if (err)
return callback(err);
lines = data.split(/\n+/);
keys = [];
for (i = 0; i < lines.length; i++) {
line = lines[i].trim();
if (line.length === 0)
continue;
if (/^\s*#/.test(line))
continue;
parts = line.split(/\s+/);
if (parts.length < 4)
return callback(new RPCError('Malformed wallet.'));
try {
secret = bcoin.keyring.fromSecret(parts[0]);
} catch (e) {
return callback(e);
}
time = +parts[1];
label = parts[2];
addr = parts[3];
keys.push(secret);
}
utils.forEachSerial(keys, function(key, next) {
self.wallet.importKey(0, key, null, next);
}, function(err) {
if (err)
return callback(err)
self.walletdb.rescan(self.chain.db, 0, function(err) {
if (err)
return callback(err);
callback(null, null);
});
});
});
};

View File

@ -815,7 +815,7 @@ Wallet.prototype.importKey = function importKey(account, ring, passphrase, callb
account = 0;
}
callback = this._lockWrite(importKey, [account, ring, callback]);
callback = this._lockWrite(importKey, [account, ring, passphrase, callback]);
if (!callback)
return;