From a103e484444919f8b7e7f95eb2801bb8ec764b5a Mon Sep 17 00:00:00 2001 From: junderw Date: Mon, 3 Sep 2018 15:53:09 +0900 Subject: [PATCH] Fix indents + references + lawyer changed to mediator --- README.md | 4 +-- test/integration/csv.js | 77 ++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index edcb265..c85db43 100644 --- a/README.md +++ b/README.md @@ -117,8 +117,8 @@ Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP). - [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future) (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js#L72) - [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js#L131) - [Create (and broadcast via 3PBP) a Transaction where Bob and Charles can send (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js#L177) -- [Create (and broadcast via 3PBP) a Transaction where Alice (lawyer) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js#L234) -- [Create (and broadcast via 3PBP) a Transaction where Alice (lawyer) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js#L296) +- [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js#L234) +- [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js#L296) - [Recover a private key from duplicate R values](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L14) - [Recover a BIP32 parent private key from the parent public key, and a derived, non-hardened child private key](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/crypto.js#L68) - [Generate a single-key stealth address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/stealth.js#L72) diff --git a/test/integration/csv.js b/test/integration/csv.js index 704ac60..ec29cbe 100644 --- a/test/integration/csv.js +++ b/test/integration/csv.js @@ -22,49 +22,54 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () { // IF MTP (from when confirmed) > seconds, aQ can redeem function csvCheckSigOutput (aQ, bQ, sequence) { return bitcoin.script.compile([ + /* eslint-disable indent */ bitcoin.opcodes.OP_IF, - bitcoin.script.number.encode(sequence), - bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, - bitcoin.opcodes.OP_DROP, - + bitcoin.script.number.encode(sequence), + bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, + bitcoin.opcodes.OP_DROP, bitcoin.opcodes.OP_ELSE, - bQ.publicKey, - bitcoin.opcodes.OP_CHECKSIGVERIFY, + bQ.publicKey, + bitcoin.opcodes.OP_CHECKSIGVERIFY, bitcoin.opcodes.OP_ENDIF, - aQ.publicKey, bitcoin.opcodes.OP_CHECKSIG + /* eslint-enable indent */ ]) } - // 2 of 3 multisig of bQ, cQ, dQ, but after sequence1 time, - // aQ can allow the multisig to become 1 of 3. - // But after sequence2 time, aQ can sign for the output all by themself. + // 2 of 3 multisig of bQ, cQ, dQ, + // but after sequence1 time, aQ can allow the multisig to become 1 of 3. + // but after sequence2 time, aQ can sign for the output all by themself. + // Ref: https://github.com/bitcoinbook/bitcoinbook/blob/f8b883dcd4e3d1b9adf40fed59b7e898fbd9241f/ch07.asciidoc#complex-script-example + // Note: bitcoinjs-lib will not offer specific support for problems with + // advanced script usages such as below. Use at your own risk. function complexCsvOutput (aQ, bQ, cQ, dQ, sequence1, sequence2) { return bitcoin.script.compile([ + /* eslint-disable indent */ bitcoin.opcodes.OP_IF, - bitcoin.opcodes.OP_IF, - bitcoin.opcodes.OP_2, + bitcoin.opcodes.OP_IF, + bitcoin.opcodes.OP_2, + bitcoin.opcodes.OP_ELSE, + bitcoin.script.number.encode(sequence1), + bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, + bitcoin.opcodes.OP_DROP, + aQ.publicKey, + bitcoin.opcodes.OP_CHECKSIGVERIFY, + bitcoin.opcodes.OP_1, + bitcoin.opcodes.OP_ENDIF, + bQ.publicKey, + cQ.publicKey, + dQ.publicKey, + bitcoin.opcodes.OP_3, + bitcoin.opcodes.OP_CHECKMULTISIG, bitcoin.opcodes.OP_ELSE, - bitcoin.script.number.encode(sequence1), - bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, - bitcoin.opcodes.OP_DROP, - aQ.publicKey, - bitcoin.opcodes.OP_CHECKSIGVERIFY, - bitcoin.opcodes.OP_1, - bitcoin.opcodes.OP_ENDIF, - bQ.publicKey, - cQ.publicKey, - dQ.publicKey, - bitcoin.opcodes.OP_3, - bitcoin.opcodes.OP_CHECKMULTISIG, - bitcoin.opcodes.OP_ELSE, - bitcoin.script.number.encode(sequence2), - bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, - bitcoin.opcodes.OP_DROP, - aQ.publicKey, - bitcoin.opcodes.OP_CHECKSIG, + bitcoin.script.number.encode(sequence2), + bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY, + bitcoin.opcodes.OP_DROP, + aQ.publicKey, + bitcoin.opcodes.OP_CHECKSIG, bitcoin.opcodes.OP_ENDIF + /* eslint-enable indent */ ]) } @@ -230,8 +235,8 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () { }) }) - // Check first combination of complex CSV, lawyer + 1 of 3 after 2 blocks - it('can create (and broadcast via 3PBP) a Transaction where Alice (lawyer) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)', function (done) { + // Check first combination of complex CSV, mediator + 1 of 3 after 2 blocks + it('can create (and broadcast via 3PBP) a Transaction where Alice (mediator) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)', function (done) { regtestUtils.height(function (err, height) { if (err) return done(err) @@ -254,7 +259,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () { txb.addInput(unspent.txId, unspent.vout, sequence1) // Set sequence1 for input txb.addOutput(regtestUtils.RANDOM_ADDRESS, 7e4) - // OP_0 {Bob sig} {Alice lawyer sig} OP_FALSE OP_TRUE + // OP_0 {Bob sig} {Alice mediator sig} OP_FALSE OP_TRUE const tx = txb.buildIncomplete() const signatureHash = tx.hashForSignature(0, p2sh.redeem.output, hashType) const redeemScriptSig = bitcoin.payments.p2sh({ @@ -292,8 +297,8 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () { }) }) - // Check first combination of complex CSV, lawyer after 5 blocks - it('can create (and broadcast via 3PBP) a Transaction where Alice (lawyer) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)', function (done) { + // Check first combination of complex CSV, mediator after 5 blocks + it('can create (and broadcast via 3PBP) a Transaction where Alice (mediator) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)', function (done) { regtestUtils.height(function (err, height) { if (err) return done(err) @@ -316,7 +321,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', function () { txb.addInput(unspent.txId, unspent.vout, sequence2) // Set sequence2 for input txb.addOutput(regtestUtils.RANDOM_ADDRESS, 7e4) - // {Alice lawyer sig} OP_FALSE + // {Alice mediator sig} OP_FALSE const tx = txb.buildIncomplete() const signatureHash = tx.hashForSignature(0, p2sh.redeem.output, hashType) const redeemScriptSig = bitcoin.payments.p2sh({