From b27b72d775dd988ea8841207815c385a3428bef7 Mon Sep 17 00:00:00 2001 From: Thomas Kerin Date: Sat, 12 Nov 2016 19:26:26 +0100 Subject: [PATCH] examples --- latest/spend_p2sh_p2wpkh.js | 10 ++++++++-- latest/spend_p2sh_p2wsh.js | 9 +++++++-- latest/spend_p2sh_p2wsh_multisig.js | 10 +++++++--- latest/spend_p2wpkh.js | 9 +++++++-- latest/spend_p2wsh.js | 9 +++++++-- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/latest/spend_p2sh_p2wpkh.js b/latest/spend_p2sh_p2wpkh.js index 572e5e0..68ba1b1 100644 --- a/latest/spend_p2sh_p2wpkh.js +++ b/latest/spend_p2sh_p2wpkh.js @@ -38,10 +38,16 @@ txb.addOutput(myaddress, txOut.value - 5000) var unsigned = txb.buildIncomplete() var signer = new TxSigner(unsigned) -signer.sign(0, root.keyPair, { +var opts = { scriptPubKey: txOut.script, redeemScript: toSegwitPubkey, value: txOut.value -}) +} +signer.sign(0, root.keyPair, opts) var txd = signer.done() console.log(txd.toBuffer().toString('hex')) + +var testSigner = new TxSigner(txd) + +console.log(testSigner.signer(0, opts).isFullySigned()); +console.log(testSigner.done().toBuffer().equals(txd.toBuffer())) \ No newline at end of file diff --git a/latest/spend_p2sh_p2wsh.js b/latest/spend_p2sh_p2wsh.js index 0b3c8af..875a8b4 100644 --- a/latest/spend_p2sh_p2wsh.js +++ b/latest/spend_p2sh_p2wsh.js @@ -28,12 +28,17 @@ builder.addOutput('2N6stcWuMpLgt4nkiaEFXP6p9J9VKRHCwDJ', 10000) var unsigned = builder.buildIncomplete() var signer = new TxSigner(unsigned) -signer.sign(0, root.keyPair, { +var opts = { scriptPubKey: txOut.script, redeemScript: p2shScript, witnessScript: witnessScript, value: txOut.value -}) +} +signer.sign(0, root.keyPair, opts) var txd = signer.done() console.log(txd.toBuffer().toString('hex')) +var testSigner = new TxSigner(txd) + +console.log(testSigner.signer(0, opts).isFullySigned()); +console.log(testSigner.done().toBuffer().equals(txd.toBuffer())) \ No newline at end of file diff --git a/latest/spend_p2sh_p2wsh_multisig.js b/latest/spend_p2sh_p2wsh_multisig.js index 1e6de0e..9030b2c 100644 --- a/latest/spend_p2sh_p2wsh_multisig.js +++ b/latest/spend_p2sh_p2wsh_multisig.js @@ -33,15 +33,19 @@ builder.addOutput('2N6stcWuMpLgt4nkiaEFXP6p9J9VKRHCwDJ', 10000) var unsigned = builder.buildIncomplete() var signer = new TxSigner(unsigned) -var data = { +var opts = { scriptPubKey: txOut.script, value: txOut.value, redeemScript: p2shScript, witnessScript: multisig } -signer.sign(0, root.keyPair, data) -signer.sign(0, root2.keyPair, data) +signer.sign(0, root.keyPair, opts) +signer.sign(0, root2.keyPair, opts) var txd = signer.done() console.log(txd.toBuffer().toString('hex')) +var testSigner = new TxSigner(txd) + +console.log(testSigner.signer(0, opts).isFullySigned()) +console.log(testSigner.done().toBuffer().equals(txd.toBuffer())) \ No newline at end of file diff --git a/latest/spend_p2wpkh.js b/latest/spend_p2wpkh.js index 16d4f58..5a448fc 100644 --- a/latest/spend_p2wpkh.js +++ b/latest/spend_p2wpkh.js @@ -28,11 +28,16 @@ builder.addOutput('2N6stcWuMpLgt4nkiaEFXP6p9J9VKRHCwDJ', txOut.value - 5000) var unsigned = builder.buildIncomplete() var signer = new TxSigner(unsigned) -signer.sign(0, root.keyPair, { +var opts = { scriptPubKey: txOut.script, value: txOut.value -}) +} +signer.sign(0, root.keyPair, opts) var txd = signer.done() console.log(txd.toBuffer().toString('hex')) +var testSigner = new TxSigner(txd) + +console.log(testSigner.signer(0, opts).isFullySigned()); +console.log(testSigner.done().toBuffer().equals(txd.toBuffer())) \ No newline at end of file diff --git a/latest/spend_p2wsh.js b/latest/spend_p2wsh.js index d9c2afd..db5eaeb 100644 --- a/latest/spend_p2wsh.js +++ b/latest/spend_p2wsh.js @@ -31,12 +31,17 @@ builder.addOutput('2N6stcWuMpLgt4nkiaEFXP6p9J9VKRHCwDJ', 10000) var unsigned = builder.buildIncomplete() var signer = new TxSigner(unsigned) -signer.sign(0, root.keyPair, { +var opts = { scriptPubKey: scriptPubKey, witnessScript: witnessScript, value: txOut.value -}) +} +signer.sign(0, root.keyPair, opts) var txd = signer.done() console.log(txd.toBuffer().toString('hex')) +var testSigner = new TxSigner(txd) + +console.log(testSigner.signer(0, opts).isFullySigned()) +console.log(testSigner.done().toBuffer().equals(txd.toBuffer())) \ No newline at end of file