Last active
July 1, 2016 09:22
-
-
Save runeksvendsen/d395a687d5f7da47b5df065a932e1e11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bitcoin = require('bitcoinjs-lib'); | |
var keyPair = bitcoin.ECPair.makeRandom( { compressed: true } ); // create new key pair to be used for signing payment channel payments | |
var chanState = new PaymentChannel("https://paychan.runeks.me", keyPair, expTime); | |
chanState.getFundingInfo(function (fundingAddress, openPrice, fundingTxMinConf) { | |
// pay to 'fundingAddress' here | |
// wait for 'fundingTxMinConf' confirmations before proceeding to open step | |
}); | |
var fi = blockchain_GetTxInfoFromAddress(fundingAddress) // get information about the transaction paying to the funding address | |
chanState.setFundingSource( fi.txid, fi.vout, fi.value ); // register this information with the state object | |
var refundAddress = "1MmWtRnvdayQqVaRdpnsGNesCch7eptZnP"; | |
var txHexStr = chanState.getRefundTx(refundAddress, fee).toHex(); //create a refund transaction, if desired | |
chanState.openChannel(refundAddress, function (payConn, payInfo) { | |
var amount = 10; // satoshi | |
function paymentLoop (numPaymentsLeft, res) { | |
if ((res.channel_status === "open") && (numPaymentsLeft > 0)) { | |
payConn.makePayment(amount, paymentLoop.bind(null, numPaymentsLeft - 1)); | |
} | |
} | |
// make first payment, then go into loop | |
payConn.makePayment(amount, paymentLoop.bind(null, 1000)); | |
payConn.deleteChannel(callback); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment