From e93e3d83f4883b7661eacee2fdcb731780117a94 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 18 Aug 2014 13:39:57 -0700 Subject: [PATCH] paypro: example - add --address and --pubkey options. document in readme. --- examples/PayPro/README.md | 7 +++- examples/PayPro/server.js | 69 +++++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/examples/PayPro/README.md b/examples/PayPro/README.md index f73e66c..3c38f8c 100644 --- a/examples/PayPro/README.md +++ b/examples/PayPro/README.md @@ -45,7 +45,12 @@ Customer: Message from Merchant: Thank you for your payment! Customer: Payment sent successfully. ``` -## Changing the server address in outputs +## Changing the server address contained in outputs + +If you want to alter the address or public key the testnet coins get sent to by +the payment server, you can pass in the `--pubkey` or `--address` options. +`address` has to be a testnet address, whereas `pubkey` is a hex encoded public +key. ## Other Options diff --git a/examples/PayPro/server.js b/examples/PayPro/server.js index befdeb3..52aa658 100755 --- a/examples/PayPro/server.js +++ b/examples/PayPro/server.js @@ -141,34 +141,47 @@ app.get('/-/request', function(req, res, next) { // number of satoshis to be paid po.set('amount', value); // a TxOut script where the payment should be sent. similar to OP_CHECKSIG - po.set('script', new Buffer([ - 118, // OP_DUP - 169, // OP_HASH160 - 76, // OP_PUSHDATA1 - 20, // number of bytes - 55, - 48, - 254, - 188, - 186, - 4, - 186, - 208, - 205, - 71, - 108, - 251, - 130, - 15, - 156, - 55, - 215, - 70, - 111, - 217, - 136, // OP_EQUALVERIFY - 172 // OP_CHECKSIG - ])); + if (argv.pubkey || argv.address) { + var pubKey; + if (argv.address) { + pubKey = bitcore.Base58Check.decode(new Buffer(argv.address)); + } else { + pubKey = new Buffer(argv.pubkey, 'hex'); + } + var pubKeyHash = bitcore.util.sha256ripe160(pubKey); + var address = new bitcore.Address(pubKeyHash, 'testnet'); + var scriptPubKey = addr.getScriptPubKey(); + po.set('script', scriptPubKey.getBuffer()); + } else { + po.set('script', new Buffer([ + 118, // OP_DUP + 169, // OP_HASH160 + 76, // OP_PUSHDATA1 + 20, // number of bytes + 55, + 48, + 254, + 188, + 186, + 4, + 186, + 208, + 205, + 71, + 108, + 251, + 130, + 15, + 156, + 55, + 215, + 70, + 111, + 217, + 136, // OP_EQUALVERIFY + 172 // OP_CHECKSIG + ])); + } outputs.push(po.message); });