sighashing.
This commit is contained in:
parent
54d3b350e9
commit
32e26446b1
@ -86,6 +86,7 @@ function MTX(options) {
|
|||||||
this._hashPrevouts = null;
|
this._hashPrevouts = null;
|
||||||
this._hashSequence = null;
|
this._hashSequence = null;
|
||||||
this._hashOutputs = null;
|
this._hashOutputs = null;
|
||||||
|
this._lastWitnessSize = 0;
|
||||||
|
|
||||||
if (options.inputs) {
|
if (options.inputs) {
|
||||||
for (i = 0; i < options.inputs.length; i++)
|
for (i = 0; i < options.inputs.length; i++)
|
||||||
@ -100,6 +101,10 @@ function MTX(options) {
|
|||||||
|
|
||||||
utils.inherits(MTX, bcoin.tx);
|
utils.inherits(MTX, bcoin.tx);
|
||||||
|
|
||||||
|
MTX.fromOptions = function fromOptions(options) {
|
||||||
|
return new MTX(options);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone the transaction.
|
* Clone the transaction.
|
||||||
* @returns {MTX}
|
* @returns {MTX}
|
||||||
|
|||||||
@ -124,41 +124,39 @@ TX.fromOptions = function fromOptions(data) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
TX.prototype.clone = function clone() {
|
TX.prototype.clone = function clone() {
|
||||||
var copy, i;
|
var copy = new TX();
|
||||||
|
var i, input, output;
|
||||||
|
|
||||||
copy = {
|
copy.ts = this.ts;
|
||||||
version: this.version,
|
copy.block = this.block;
|
||||||
flag: this.flag,
|
copy.index = this.index;
|
||||||
inputs: [],
|
copy.height = this.height;
|
||||||
outputs: [],
|
|
||||||
locktime: this.locktime,
|
copy.version = this.version;
|
||||||
ts: this.ts,
|
copy.flag = this.flag;
|
||||||
block: this.block,
|
|
||||||
index: this.index,
|
|
||||||
height: this.height
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
copy.inputs.push({
|
input = new bcoin.input();
|
||||||
prevout: {
|
input.prevout = new bcoin.outpoint();
|
||||||
hash: this.inputs[i].prevout.hash,
|
input.prevout.hash = this.inputs[i].prevout.hash;
|
||||||
index: this.inputs[i].prevout.index
|
input.prevout.index = this.inputs[i].prevout.index;
|
||||||
},
|
input.coin = this.inputs[i].coin;
|
||||||
coin: this.inputs[i].coin,
|
input.script = this.inputs[i].script;
|
||||||
script: this.inputs[i].script,
|
input.witness = this.inputs[i].witness;
|
||||||
witness: this.inputs[i].witness,
|
input.sequence = this.inputs[i].sequence;
|
||||||
sequence: this.inputs[i].sequence
|
copy.inputs.push(input);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < this.outputs.length; i++) {
|
for (i = 0; i < this.outputs.length; i++) {
|
||||||
copy.outputs.push({
|
output = new bcoin.output();
|
||||||
value: this.outputs[i].value,
|
output.value = this.outputs[i].value;
|
||||||
script: this.outputs[i].script
|
output.script = this.outputs[i].script;
|
||||||
});
|
copy.outputs.push(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TX(copy);
|
copy.locktime = this.locktime;
|
||||||
|
|
||||||
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -437,7 +435,9 @@ TX.prototype.signatureHash = function signatureHash(index, prev, type, version)
|
|||||||
|
|
||||||
TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
||||||
var p = new BufferWriter();
|
var p = new BufferWriter();
|
||||||
var i, copy;
|
var empty = new Script();
|
||||||
|
var witness = new bcoin.witness();
|
||||||
|
var i, copy, input, output;
|
||||||
|
|
||||||
if (typeof index !== 'number')
|
if (typeof index !== 'number')
|
||||||
index = this.inputs.indexOf(index);
|
index = this.inputs.indexOf(index);
|
||||||
@ -449,32 +449,31 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
|||||||
assert(prev instanceof Script);
|
assert(prev instanceof Script);
|
||||||
|
|
||||||
// Clone the transaction.
|
// Clone the transaction.
|
||||||
copy = {
|
copy = new TX();
|
||||||
version: this.version,
|
|
||||||
flag: 1,
|
copy.version = this.version;
|
||||||
inputs: [],
|
|
||||||
outputs: [],
|
|
||||||
locktime: this.locktime
|
|
||||||
};
|
|
||||||
|
|
||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
copy.inputs.push({
|
input = new bcoin.input();
|
||||||
prevout: this.inputs[i].prevout,
|
input.prevout = this.inputs[i].prevout;
|
||||||
script: this.inputs[i].script,
|
input.script = this.inputs[i].script;
|
||||||
sequence: this.inputs[i].sequence
|
input.sequence = this.inputs[i].sequence;
|
||||||
});
|
input.witness = witness;
|
||||||
|
copy.inputs.push(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < this.outputs.length; i++) {
|
for (i = 0; i < this.outputs.length; i++) {
|
||||||
copy.outputs.push({
|
output = new bcoin.output();
|
||||||
value: this.outputs[i].value,
|
output.value = this.outputs[i].value;
|
||||||
script: this.outputs[i].script
|
output.script = this.outputs[i].script;
|
||||||
});
|
copy.outputs.push(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
copy.locktime = this.locktime;
|
||||||
|
|
||||||
// Remove all signatures.
|
// Remove all signatures.
|
||||||
for (i = 0; i < copy.inputs.length; i++)
|
for (i = 0; i < copy.inputs.length; i++)
|
||||||
copy.inputs[i].script = new Script();
|
copy.inputs[i].script = empty;
|
||||||
|
|
||||||
// Remove all code separators.
|
// Remove all code separators.
|
||||||
prev = prev.removeSeparators();
|
prev = prev.removeSeparators();
|
||||||
@ -503,7 +502,7 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
|||||||
// Null outputs that are not the at current input index.
|
// Null outputs that are not the at current input index.
|
||||||
for (i = 0; i < copy.outputs.length; i++) {
|
for (i = 0; i < copy.outputs.length; i++) {
|
||||||
if (i !== index) {
|
if (i !== index) {
|
||||||
copy.outputs[i].script = new Script();
|
copy.outputs[i].script = empty;
|
||||||
copy.outputs[i].value = -1;
|
copy.outputs[i].value = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -522,7 +521,7 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render the copy and append the hashtype.
|
// Render the copy and append the hashtype.
|
||||||
TX(copy).toRaw(p);
|
copy.toRaw(p);
|
||||||
p.writeU32(type);
|
p.writeU32(type);
|
||||||
|
|
||||||
return utils.dsha256(p.render());
|
return utils.dsha256(p.render());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user