This commit is contained in:
Christopher Jeffrey 2016-08-21 12:03:15 -07:00
parent d26db89a21
commit 8ed5016108
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 33 additions and 15 deletions

View File

@ -11,6 +11,13 @@ var utils = require('../utils');
var IP = require('../ip');
var assert = utils.assert;
var constants = bcoin.protocol.constants;
var fs;
try {
fs = require('f' + 's');
} catch (e) {
;
}
function RPC(node) {
if (!(this instanceof RPC))
@ -2509,7 +2516,6 @@ RPC.prototype.setmocktime = function setmocktime(args, callback) {
*/
RPC.prototype.resendwallettransactions = function resendwallettransactions(args, callback) {
var self = this;
var hashes = [];
var i, tx;
@ -2588,7 +2594,7 @@ RPC.prototype.dumpwallet = function dumpwallet(args, callback) {
if (!args[0] || typeof args[0] !== 'string')
return callback(new RPCError('Invalid parameter.'));
file = utils.normalize(args[0]);
file = toString(args[0]);
time = utils.date();
out = [
utils.fmt('# Wallet Dump created by BCoin %s', constants.USER_VERSION),
@ -2637,7 +2643,14 @@ RPC.prototype.dumpwallet = function dumpwallet(args, callback) {
out = out.join('\n');
callback(null, out);
if (!fs)
return callback(null, out);
fs.writeFile(file, out, function(err) {
if (err)
return callback(err);
callback(null, out);
});
});
});
};
@ -3112,7 +3125,10 @@ RPC.prototype.importwallet = function importwallet(args, callback) {
if (args.help || args.length !== 1)
return callback(new RPCError('importwallet "filename"'));
file = toString(args[0]),
file = toString(args[0]);
if (!fs)
return callback(new RPCError('FS not available.'));
fs.readFile(file, 'utf8', function(err, data) {
if (err)
@ -3152,7 +3168,7 @@ RPC.prototype.importwallet = function importwallet(args, callback) {
self.wallet.importKey(0, key, null, next);
}, function(err) {
if (err)
return callback(err)
return callback(err);
self.walletdb.rescan(self.chain.db, 0, function(err) {
if (err)

View File

@ -784,7 +784,6 @@ KeyRing.fromJSON = function fromJSON(json) {
KeyRing.prototype.toRaw = function toRaw(writer) {
var p = new BufferWriter(writer);
var i;
p.writeU8(this.witness ? 1 : 0);
@ -812,7 +811,7 @@ KeyRing.prototype.toRaw = function toRaw(writer) {
KeyRing.prototype.fromRaw = function fromRaw(data, network) {
var p = new BufferReader(data);
var i, count, key;
var key;
this.network = bcoin.network.get(network);
this.witness = p.readU8() === 1;

View File

@ -704,6 +704,7 @@ MTX.prototype.isSigned = function isSigned() {
if (!this.isInputSigned(i))
return false;
}
return true;
};
/**
@ -714,7 +715,7 @@ MTX.prototype.isSigned = function isSigned() {
MTX.prototype.isInputSigned = function isInputSigned(index) {
var input = this.inputs[index];
var prev, vector, m, redeem, j, result;
var prev, vector, redeem, result;
assert(input, 'Input does not exist.');
@ -756,7 +757,7 @@ MTX.prototype.isInputSigned = function isInputSigned(index) {
if (redeem) {
redeem = vector.pop();
result = this.isVectorSigned(prev);
result = this.isVectorSigned(prev, vector);
vector.push(redeem);
return result;
}
@ -772,7 +773,7 @@ MTX.prototype.isInputSigned = function isInputSigned(index) {
*/
MTX.prototype.isVectorSigned = function isVectorSigned(prev, vector) {
var m;
var i, m;
if (prev.isPubkey()) {
if (!Script.isSignature(vector.get(0)))
@ -791,8 +792,8 @@ MTX.prototype.isVectorSigned = function isVectorSigned(prev, vector) {
m = prev.getSmall(0);
// Ensure all members are signatures.
for (j = 1; j < vector.length; j++) {
if (!Script.isSignature(vector.get(j)))
for (i = 1; i < vector.length; i++) {
if (!Script.isSignature(vector.get(i)))
return false;
}
@ -955,7 +956,7 @@ MTX.prototype.isInputScripted = function isInputScripted(index) {
MTX.prototype.maxSize = function maxSize(options) {
var scale = constants.WITNESS_SCALE_FACTOR;
var i, j, input, total, size, prev, m, n, sz;
var witness, hadWitness, redeem, wallet;
var witness, hadWitness, redeem;
if (!options && this.isScripted())
return this.getVirtualSize();

View File

@ -403,8 +403,10 @@ utils.hrtime = function hrtime(time) {
return [sec, ms * 1e6];
}
return Array.isArray(time) && time.length == 2 ?
process.hrtime(time) : process.hrtime();
if (time)
return process.hrtime(time);
return process.hrtime();
};
/**