From 9eb45540a5cab5b8d9e2f557a2941decd11f8945 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 23 Oct 2015 11:46:29 -0400 Subject: [PATCH 1/2] Update readme --- README.md | 14 ++++++++++++-- docs/index.md | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 30581c4..d311b34 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,25 @@ -bitcore payment channels # Payment Channels for Bitcore [![NPM Package](https://img.shields.io/npm/v/bitcore-channel.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-channel) [![Build Status](https://img.shields.io/travis/bitpay/bitcore-channel.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-channel) [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-channel.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-channel) - A module for [bitcore][bitcore] that implements [Payment Channels][channel]. Payment channels (sometimes referred as micropayment channels) are a type of smart contracts that allow rapidly adjusting bitcoin transactions. This can be used to do trustless simultaneous payments with a service provider without the need of an intermediary, and some other applications. See [the main bitcore repo][bitcore] or the [bitcore guide on Payment Channels](http://bitcore.io/guide/module/channel/index.html) for more information. +## Getting Started + +```sh +npm install bitcore-lib +npm install bitcore-channel +``` + +```sh +bower install bitcore-lib +bower install bitcore-channel +``` + ## Contributing See [CONTRIBUTING.md](https://github.com/bitpay/bitcore/blob/master/CONTRIBUTING.md) on the main bitcore repo for information about how to contribute. diff --git a/docs/index.md b/docs/index.md index 2118d28..5edf655 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,12 +7,14 @@ Payment channels are implemented as a separate module and you must add it to you For node projects: ``` +npm install bitcore-lib --save npm install bitcore-channel --save ``` For client-side projects: ``` +bower install bitcore-lib --save bower install bitcore-channel --save ``` @@ -24,12 +26,18 @@ Let's start with an overview of how to use the Consumer side. Let's assume that We also have a final address that we'll use as a "change" address (sending here any funds that we didn't transact with the Provider). We'll call this the "refund" address, as it will also be the address where the refund will get to in case the contract is cancelled. ```javascript +var bitcore = require('bitcore-lib'); var Consumer = require('bitcore-channel').Consumer; var providerPublicKey = '027f10e67bea70f847b3ab92c18776c6a97a78f84def158afc31fd98513d42912e'; var refundAddress = 'mzCXqcsLBerwyoRZzBFQELHaJ1ZtBSxxe6'; var providerAddress = 'mrCHmWgn54hJNty2srFF4XLmkey5GnCv5m'; +// Make sure to save this, a good way is to use the bitcore-mnemonic library or +// export a WIF format with fundingKey.toWIF() +var fundingKey = new bitcore.PrivateKey(); + var consumer = new Consumer({ + fundingKey: fundingKey, network: 'testnet', providerPublicKey: providerPublicKey, providerAddress: providerAddress, From 89f5a0468ae52c7d0d5c96a8bd62fd17d914bfb1 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 23 Oct 2015 12:44:51 -0400 Subject: [PATCH 2/2] Update examples with updated toJSON api. --- examples/01.createChannel.js | 4 ++-- examples/02.signRefund.js | 2 +- examples/04.firstPayment.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/01.createChannel.js b/examples/01.createChannel.js index be59577..c0db08f 100644 --- a/examples/01.createChannel.js +++ b/examples/01.createChannel.js @@ -24,7 +24,7 @@ var insight = new bitcore.transport.explorers.Insight(); insight.getUnspentUtxos(consumer.fundingAddress, function(err, utxos) { consumer.processFunding(utxos); consumer.commitmentTx._updateChangeOutput(); - fs.writeFileSync('unsigned.refund.log', consumer.setupRefund().toJSON()); + fs.writeFileSync('unsigned.refund.log', JSON.stringify(consumer.setupRefund())); console.log(consumer.commitmentTx.toString()); - fs.writeFileSync('commitment.log', consumer.commitmentTx.toJSON()); + fs.writeFileSync('commitment.log', JSON.stringify(consumer.commitmentTx)); }); diff --git a/examples/02.signRefund.js b/examples/02.signRefund.js index 49ea60e..29a4b9b 100644 --- a/examples/02.signRefund.js +++ b/examples/02.signRefund.js @@ -12,5 +12,5 @@ var provider = new Provider({ var refund = JSON.parse(fs.readFileSync('unsigned.refund.log')); -fs.writeFileSync('signed.refund.log', provider.signRefund(refund).refund.toJSON()); +fs.writeFileSync('signed.refund.log', JSON.stringify(provider.signRefund(refund).refund)); diff --git a/examples/04.firstPayment.js b/examples/04.firstPayment.js index fb0b470..b347d22 100644 --- a/examples/04.firstPayment.js +++ b/examples/04.firstPayment.js @@ -31,5 +31,5 @@ var refund = JSON.parse(fs.readFileSync('signed.refund.log')); if (consumer.validateRefund(refund)) { consumer.incrementPaymentBy(10400); console.log(consumer.paymentTx.toString()); - fs.writeFileSync('firstpayment.log', consumer.paymentTx.toJSON()); + fs.writeFileSync('firstpayment.log', JSON.stringify(consumer.paymentTx)); }