minor changes/fixes.
This commit is contained in:
parent
3158f57e0f
commit
e0ab0ab88d
@ -1247,7 +1247,7 @@ ChainBlock.fromJSON = function(chain, json) {
|
|||||||
ChainBlock.prototype.toRaw = function toRaw() {
|
ChainBlock.prototype.toRaw = function toRaw() {
|
||||||
var res = new Buffer(BLOCK_SIZE);
|
var res = new Buffer(BLOCK_SIZE);
|
||||||
|
|
||||||
utils.writeU32(res, this.version, 0);
|
utils.write32(res, this.version, 0);
|
||||||
utils.copy(utils.toArray(this.prevBlock, 'hex'), res, 4);
|
utils.copy(utils.toArray(this.prevBlock, 'hex'), res, 4);
|
||||||
utils.copy(utils.toArray(this.merkleRoot, 'hex'), res, 36);
|
utils.copy(utils.toArray(this.merkleRoot, 'hex'), res, 36);
|
||||||
utils.writeU32(res, this.ts, 68);
|
utils.writeU32(res, this.ts, 68);
|
||||||
|
|||||||
@ -45,7 +45,7 @@ function Peer(pool, createConnection, options) {
|
|||||||
this.challenge = null;
|
this.challenge = null;
|
||||||
this.lastPong = 0;
|
this.lastPong = 0;
|
||||||
|
|
||||||
this.banscore = 0;
|
this.banScore = 0;
|
||||||
this.orphans = 0;
|
this.orphans = 0;
|
||||||
this.orphanTime = 0;
|
this.orphanTime = 0;
|
||||||
|
|
||||||
|
|||||||
@ -187,7 +187,7 @@ Pool.prototype._init = function _init() {
|
|||||||
peer ? peer.host : ''
|
peer ? peer.host : ''
|
||||||
);
|
);
|
||||||
|
|
||||||
self.emit('fork', [data.expected, data.received]);
|
self.emit('fork', data.expected, data.received);
|
||||||
|
|
||||||
if (!peer)
|
if (!peer)
|
||||||
return;
|
return;
|
||||||
@ -1061,6 +1061,9 @@ Pool.prototype.addWallet = function addWallet(w, defaultTs) {
|
|||||||
if (this.loading)
|
if (this.loading)
|
||||||
return this.once('load', this.addWallet.bind(this, w, defaultTs));
|
return this.once('load', this.addWallet.bind(this, w, defaultTs));
|
||||||
|
|
||||||
|
if (w.loading)
|
||||||
|
return w.once('load', this.addWallet.bind(this, w, defaultTs));
|
||||||
|
|
||||||
if (this.wallets.indexOf(w) !== -1)
|
if (this.wallets.indexOf(w) !== -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1084,7 +1087,6 @@ Pool.prototype.addWallet = function addWallet(w, defaultTs) {
|
|||||||
if (!ts)
|
if (!ts)
|
||||||
ts = defaultTs || (utils.now() - 7 * 24 * 3600);
|
ts = defaultTs || (utils.now() - 7 * 24 * 3600);
|
||||||
|
|
||||||
// self.search(false, ts, e);
|
|
||||||
self.searchWallet(ts);
|
self.searchWallet(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1671,9 +1673,9 @@ Pool.prototype.isOrphaning = function isOrphaning(peer) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.setMisbehavior = function setMisbehavior(peer, dos) {
|
Pool.prototype.setMisbehavior = function setMisbehavior(peer, dos) {
|
||||||
peer.banscore += dos;
|
peer.banScore += dos;
|
||||||
|
|
||||||
if (peer.banscore >= constants.banScore) {
|
if (peer.banScore >= constants.banScore) {
|
||||||
this.peers.misbehaving[peer.host] = utils.now();
|
this.peers.misbehaving[peer.host] = utils.now();
|
||||||
utils.debug('Ban threshold exceeded for %s', peer.host);
|
utils.debug('Ban threshold exceeded for %s', peer.host);
|
||||||
peer.destroy();
|
peer.destroy();
|
||||||
@ -1696,7 +1698,7 @@ Pool.prototype.isMisbehaving = function isMisbehaving(host) {
|
|||||||
delete this.peers.misbehaving[host];
|
delete this.peers.misbehaving[host];
|
||||||
peer = this.getPeer(host);
|
peer = this.getPeer(host);
|
||||||
if (peer)
|
if (peer)
|
||||||
peer.banscore = 0;
|
peer.banScore = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -1587,7 +1587,7 @@ TX.prototype.isStandard = function isStandard() {
|
|||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
input = this.inputs[i];
|
input = this.inputs[i];
|
||||||
|
|
||||||
if (script.getSize(input.script) > 1650)
|
if (bcoin.script.getSize(input.script) > 1650)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!bcoin.script.isPushOnly(input.script))
|
if (!bcoin.script.isPushOnly(input.script))
|
||||||
|
|||||||
@ -38,8 +38,8 @@ function Wallet(options) {
|
|||||||
this._labelMap = {};
|
this._labelMap = {};
|
||||||
|
|
||||||
this.accountIndex = options.accountIndex || 0;
|
this.accountIndex = options.accountIndex || 0;
|
||||||
this.addressIndex = options.addressIndex || 0;
|
this.addressDepth = options.addressDepth || 0;
|
||||||
this.changeIndex = options.changeIndex || 0;
|
this.changeDepth = options.changeDepth || 0;
|
||||||
|
|
||||||
if (!options.addresses)
|
if (!options.addresses)
|
||||||
options.addresses = [];
|
options.addresses = [];
|
||||||
@ -73,7 +73,7 @@ function Wallet(options) {
|
|||||||
this.changeAddress = this.addresses[i];
|
this.changeAddress = this.addresses[i];
|
||||||
|
|
||||||
this.storage = options.storage;
|
this.storage = options.storage;
|
||||||
this.loaded = false;
|
this.loading = true;
|
||||||
this.lastTs = 0;
|
this.lastTs = 0;
|
||||||
|
|
||||||
this.prefix = 'bt/wallet/' + this.getKeyAddress() + '/';
|
this.prefix = 'bt/wallet/' + this.getKeyAddress() + '/';
|
||||||
@ -99,7 +99,7 @@ Wallet.prototype._init = function init() {
|
|||||||
var prevBalance = null;
|
var prevBalance = null;
|
||||||
|
|
||||||
if (this.tx._loaded) {
|
if (this.tx._loaded) {
|
||||||
this.loaded = true;
|
this.loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ Wallet.prototype._init = function init() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.tx.once('load', function(ts) {
|
this.tx.once('load', function(ts) {
|
||||||
self.loaded = true;
|
self.loading = false;
|
||||||
self.lastTs = ts;
|
self.lastTs = ts;
|
||||||
self.emit('load', ts);
|
self.emit('load', ts);
|
||||||
});
|
});
|
||||||
@ -179,7 +179,7 @@ Wallet.prototype.createChangeAddress = function createChangeAddress(options) {
|
|||||||
|
|
||||||
if (this.master) {
|
if (this.master) {
|
||||||
options.priv =
|
options.priv =
|
||||||
this.master.key.hd.deriveChange(this.accountIndex, this.changeIndex++);
|
this.master.key.hd.deriveChange(this.accountIndex, this.changeDepth++);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.addAddress(options);
|
return this.addAddress(options);
|
||||||
@ -191,7 +191,7 @@ Wallet.prototype.createNewAddress = function createNewAddress(options) {
|
|||||||
|
|
||||||
if (this.master) {
|
if (this.master) {
|
||||||
options.priv =
|
options.priv =
|
||||||
this.master.key.hd.deriveAddress(this.accountIndex, this.addressIndex++);
|
this.master.key.hd.deriveAddress(this.accountIndex, this.addressDepth++);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.addAddress(options);
|
return this.addAddress(options);
|
||||||
@ -546,8 +546,8 @@ Wallet.prototype.toJSON = function toJSON(encrypt) {
|
|||||||
name: 'wallet',
|
name: 'wallet',
|
||||||
network: network.type,
|
network: network.type,
|
||||||
accountIndex: this.accountIndex,
|
accountIndex: this.accountIndex,
|
||||||
addressIndex: this.addressIndex,
|
addressDepth: this.addressDepth,
|
||||||
changeIndex: this.changeIndex,
|
changeDepth: this.changeDepth,
|
||||||
master: this.master ? this.master.toJSON(encrypt) : null,
|
master: this.master ? this.master.toJSON(encrypt) : null,
|
||||||
addresses: this.addresses.filter(function(address) {
|
addresses: this.addresses.filter(function(address) {
|
||||||
if (!address.key.hd)
|
if (!address.key.hd)
|
||||||
@ -576,8 +576,8 @@ Wallet.fromJSON = function fromJSON(json, decrypt) {
|
|||||||
|
|
||||||
w = new Wallet({
|
w = new Wallet({
|
||||||
accountIndex: json.accountIndex,
|
accountIndex: json.accountIndex,
|
||||||
addressIndex: json.addressIndex,
|
addressDepth: json.addressDepth,
|
||||||
changeIndex: json.changeIndex,
|
changeDepth: json.changeDepth,
|
||||||
master: json.master
|
master: json.master
|
||||||
? bcoin.address.fromJSON(json.master, decrypt)
|
? bcoin.address.fromJSON(json.master, decrypt)
|
||||||
: null,
|
: null,
|
||||||
@ -591,7 +591,7 @@ Wallet.fromJSON = function fromJSON(json, decrypt) {
|
|||||||
// Make sure we have all the change
|
// Make sure we have all the change
|
||||||
// addresses (we don't save them).
|
// addresses (we don't save them).
|
||||||
if (w.master) {
|
if (w.master) {
|
||||||
for (i = 0; i < w.changeIndex; i++) {
|
for (i = 0; i < w.changeDepth; i++) {
|
||||||
w.addAddress({
|
w.addAddress({
|
||||||
change: true,
|
change: true,
|
||||||
priv: w.master.key.hd.deriveChange(w.accountIndex, i)
|
priv: w.master.key.hd.deriveChange(w.accountIndex, i)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user