segwit things
This commit is contained in:
parent
77c9348824
commit
bd868cda7a
@ -49,6 +49,9 @@ Block.prototype.render = function render() {
|
|||||||
return bcoin.protocol.framer.block(this);
|
return bcoin.protocol.framer.block(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.hasWitness())
|
||||||
|
return bcoin.protocol.framer.block(this);
|
||||||
|
|
||||||
this._raw = bcoin.protocol.framer.block(this);
|
this._raw = bcoin.protocol.framer.block(this);
|
||||||
this._size = this._raw.length;
|
this._size = this._raw.length;
|
||||||
this._witness = false;
|
this._witness = false;
|
||||||
@ -63,6 +66,9 @@ Block.prototype.renderWitness = function renderWitness() {
|
|||||||
return bcoin.protocol.framer.witnessBlock(this);
|
return bcoin.protocol.framer.witnessBlock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.hasWitness())
|
||||||
|
return bcoin.protocol.framer.witnessBlock(this);
|
||||||
|
|
||||||
this._raw = bcoin.protocol.framer.witnessBlock(this);
|
this._raw = bcoin.protocol.framer.witnessBlock(this);
|
||||||
this._size = this._raw.length;
|
this._size = this._raw.length;
|
||||||
this._witness = true;
|
this._witness = true;
|
||||||
@ -80,6 +86,14 @@ Block.prototype.getCost = function getCost() {
|
|||||||
return this._cost;
|
return this._cost;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Block.prototype.hasWitness = function hasWitness() {
|
||||||
|
for (var i = 0; i < this.txs.length; i++) {
|
||||||
|
if (this.txs[i].hasWitness())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
Block.prototype.getSigopsCost = function getSigopCost(scriptHash) {
|
Block.prototype.getSigopsCost = function getSigopCost(scriptHash) {
|
||||||
var cost = 0;
|
var cost = 0;
|
||||||
var i;
|
var i;
|
||||||
@ -128,7 +142,7 @@ Block.prototype.getCommitmentHash = function getCommitmentHash() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Block.prototype.__defineGetter__('commitmentHash', function() {
|
Block.prototype.__defineGetter__('commitmentHash', function() {
|
||||||
var coinbase, i, commitment, witnessNonce, commitmentHash;
|
var coinbase, i, commitment, commitmentHash;
|
||||||
|
|
||||||
if (this._commitmentHash)
|
if (this._commitmentHash)
|
||||||
return this._commitmentHash;
|
return this._commitmentHash;
|
||||||
|
|||||||
@ -348,7 +348,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
|
|
||||||
blocks.forEach(function(data) {
|
blocks.forEach(function(data) {
|
||||||
var entry = bcoin.chainblock.fromRaw(self, height, data);
|
var entry = bcoin.chainblock.fromRaw(self, height, data);
|
||||||
var block = bcoin.block(entry, 'headers');
|
var block = bcoin.headers(entry);
|
||||||
var start;
|
var start;
|
||||||
|
|
||||||
// Do some paranoid checks.
|
// Do some paranoid checks.
|
||||||
@ -364,7 +364,7 @@ Chain.prototype._preload = function _preload(callback) {
|
|||||||
|
|
||||||
// Verify the block headers. We don't want to
|
// Verify the block headers. We don't want to
|
||||||
// trust an external centralized source completely.
|
// trust an external centralized source completely.
|
||||||
if (!block.verify()) {
|
if (!block.verifyHeaders()) {
|
||||||
start = Math.max(0, height - 2);
|
start = Math.max(0, height - 2);
|
||||||
stream.destroy();
|
stream.destroy();
|
||||||
self.resetHeightAsync(start, function(e) {
|
self.resetHeightAsync(start, function(e) {
|
||||||
@ -655,6 +655,12 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac
|
|||||||
var i, j, input, hash;
|
var i, j, input, hash;
|
||||||
var sigops = 0;
|
var sigops = 0;
|
||||||
|
|
||||||
|
utils.print(height);
|
||||||
|
utils.print(block.commitmentHash ? utils.revHex(block.commitmentHash) : null);
|
||||||
|
utils.print(utils.revHex(block.getCommitmentHash() || '00'));
|
||||||
|
utils.print(block.txs[0]);
|
||||||
|
utils.print(block.txs[1]);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
|
|||||||
@ -586,7 +586,7 @@ Framer._block = function _block(block, witness) {
|
|||||||
var i, tx, p;
|
var i, tx, p;
|
||||||
|
|
||||||
for (i = 0; i < block.txs.length; i++) {
|
for (i = 0; i < block.txs.length; i++) {
|
||||||
tx = witness
|
tx = witness && block.txs[i].hasWitness()
|
||||||
? Framer.witnessTX(block.txs[i])
|
? Framer.witnessTX(block.txs[i])
|
||||||
: Framer.tx(block.txs[i]);
|
: Framer.tx(block.txs[i]);
|
||||||
txs.push(tx);
|
txs.push(tx);
|
||||||
|
|||||||
@ -461,8 +461,12 @@ script.verifyProgram = function verifyProgram(witness, output, tx, i, flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.print(script.format(stack));
|
||||||
|
|
||||||
res = script.execute(redeem, stack, tx, i, flags);
|
res = script.execute(redeem, stack, tx, i, flags);
|
||||||
|
|
||||||
|
utils.print(script.format(redeem));
|
||||||
|
utils.print(script.format(stack));
|
||||||
// Verify the script did not fail as well as the stack values
|
// Verify the script did not fail as well as the stack values
|
||||||
if (!res || stack.length === 0 || !script.bool(stack.pop())) {
|
if (!res || stack.length === 0 || !script.bool(stack.pop())) {
|
||||||
throw new Error('script failed');
|
throw new Error('script failed');
|
||||||
|
|||||||
@ -120,6 +120,10 @@ TX.prototype.witnessHash = function witnessHash(enc) {
|
|||||||
: new Buffer(constants.zeroHash);
|
: new Buffer(constants.zeroHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (!this._witness)
|
||||||
|
if (!this.hasWitness())
|
||||||
|
return this.hash(enc);
|
||||||
|
|
||||||
if (!this._whash)
|
if (!this._whash)
|
||||||
this._whash = utils.dsha256(this.renderWitness());
|
this._whash = utils.dsha256(this.renderWitness());
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ function Wallet(options) {
|
|||||||
options.master = bcoin.hd.fromSeed();
|
options.master = bcoin.hd.fromSeed();
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.db = options.db || new bcoin.walletdb({ type: 'file' });
|
this.db = options.db || new bcoin.walletdb();
|
||||||
this.addresses = [];
|
this.addresses = [];
|
||||||
this.master = options.master || null;
|
this.master = options.master || null;
|
||||||
this.addressMap = options.addressMap || {};
|
this.addressMap = options.addressMap || {};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user