txb/tests: test solo SIGHASH_ALL, support existing SIGHASH_NONE
This commit is contained in:
parent
ed1c1a5661
commit
2223e6170e
2 changed files with 22 additions and 3 deletions
|
@ -709,9 +709,19 @@ TransactionBuilder.prototype.__canModifyInputs = function () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle incomplete SIGHASH_NONE flow
|
|
||||||
TransactionBuilder.prototype.__needsOutputs = function () {
|
TransactionBuilder.prototype.__needsOutputs = function () {
|
||||||
return this.__tx.outs.length === 0
|
// if inputs are being signed with SIGHASH_NONE, we don't strictly need outputs
|
||||||
|
// .build() will fail, but .buildIncomplete() is OK
|
||||||
|
return (this.__tx.outs.length === 0) && this.__inputs.some((input) => {
|
||||||
|
if (!input.signatures) return false
|
||||||
|
|
||||||
|
return input.signatures.some((signature) => {
|
||||||
|
if (!signature) return false // no signature, no issue
|
||||||
|
const hashType = signatureHashType(signature)
|
||||||
|
if (hashType & Transaction.SIGHASH_NONE) return false // SIGHASH_NONE doesn't care about outputs
|
||||||
|
return true // SIGHASH_* does care
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionBuilder.prototype.__canModifyOutputs = function () {
|
TransactionBuilder.prototype.__canModifyOutputs = function () {
|
||||||
|
|
11
test/fixtures/transaction_builder.json
vendored
11
test/fixtures/transaction_builder.json
vendored
|
@ -2359,12 +2359,21 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Transaction w/ no outputs",
|
"description": "Transaction w/ no outputs (but 1 SIGHASH_ALL)",
|
||||||
"exception": "Transaction needs outputs",
|
"exception": "Transaction needs outputs",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||||
"vout": 0,
|
"vout": 0,
|
||||||
|
"signs": [
|
||||||
|
{
|
||||||
|
"keyPair": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||||
|
"vout": 1,
|
||||||
"signs": [
|
"signs": [
|
||||||
{
|
{
|
||||||
"keyPair": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn",
|
"keyPair": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn",
|
||||||
|
|
Loading…
Add table
Reference in a new issue