Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Nov 24, 2015
1 parent 4bc113c commit 68d8101
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 85 deletions.
10 changes: 6 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
The MIT License (MIT)

Copyright (c) 2015 Chromaway AB

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
112 changes: 32 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,54 @@
# blockchainjs <sup>[![version](http://vb.teelaun.ch/chromaway/blockchainjs.svg)](https://www.npmjs.org/package/blockchainjs/)</sup>
# blockchainjs

[![build status](https://img.shields.io/travis/chromaway/blockchainjs.svg?branch=master&style=flat-square)](http://travis-ci.org/chromaway/blockchainjs)
[![NPM Package](https://img.shields.io/npm/v/blockchainjs.svg?style=flat-square)](https://www.npmjs.org/package/blockchainjs)
[![Build Status](https://img.shields.io/travis/chromaway/blockchainjs.svg?branch=master&style=flat-square)](https://travis-ci.org/chromaway/blockchainjs)
[![Coverage Status](https://img.shields.io/coveralls/chromaway/blockchainjs.svg?style=flat-square)](https://coveralls.io/r/chromaway/blockchainjs)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![Dependency status](https://img.shields.io/david/chromaway/blockchainjs.svg?style=flat-square)](https://david-dm.org/chromaway/blockchainjs#info=dependencies)
[![Dev Dependency status](https://img.shields.io/david/chromaway/blockchainjs.svg?style=flat-square)](https://david-dm.org/chromaway/blockchainjs#info=devDependencies)

[![NPM](https://nodei.co/npm/blockchainjs.png)](https://www.npmjs.com/package/blockchainjs)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

A pure JavaScript library for node.js and browsers for easy data exchange between wallets and bitcoin network.

## What is include blockchainjs?

blockchainjs have two abstraction level: Connector and Blockchain

Connector implements a common interface for remote service. For now available only one provider: [chromanode](https://github.com/chromaway/chromanode).

Blockchain implements a common interface between connector and your wallet. You can use Naive (trust all data from remove service) or Verified (SPV implementation).

In addition to Verified blockchainjs has Storage interface for store headers. Memory and LocalStorage available for now.

## API

* [Connector](docs/connector.md)
* [Chromanode](docs/connector.md#chromanode)
* [Blockchain](docs/blockchainapi.md)
* [Naive](docs/blockchainapi.md#naive)
* [Verified](docs/blockchainapi.md#verified)
* [Storage](docs/storageapi.md)
* [Memory](docs/storageapi.md#memory)
* [LocalStorage](docs/storageapi.md#localstorage)
Bitcoin Blockchain on JavaScript.

## Examples

### Show UTXO on address touched
### Show new transactions for address
```js
var blockchainjs = require('blockchainjs')
var connector = new blockchainjs.connector.Chromanode({networkName: 'testnet'})
var address = 'mp8XoMWnJzQwovninMdChQutPuhyHokJNc'
import blockchainjs from 'blockchainjs'

function showUTXO(address) {
connector.addressesQuery([address], {status: 'unspent'})
.then(function (result) {
console.log('UTXO for ' + address + ':')
result.transactions.forEach(function (unspent) {
// var txOut = unspent.txid + ':' + unspent.outIndex
// console.log(txOut + ' has ' + unspent.value + ' satoshi')
// sorry, only txid and height available now
console.log('Unspent in txid: ' + unspent.txid)
})
if (result.transactions.length === 0) {
console.log('nothing...')
}
console.log('')
})
}
let address = '...'

connector.on(address, showUTXO)
connector.connect()
connector.subscribe({event: 'touchAddress', address: address})
showUTXO(address)
let network = new blockchainjs.network.Chromanode({
url: blockchainjs.network.Chromanode.getSources('testnet')
})

network.on('connect', () => console.log('connected'))
network.on('newTx', (payload) => {
console.log(`${payload.address}: ${payload.txId}`)
})

network.subscribe('newTx', {address: address})
network.connect()
```

### Show last header upon completion of sync process
### Blockchain syncing progress
```js
var blockchainjs = require('blockchainjs')

var connector = new blockchainjs.connector.Chromanode({networkName: 'testnet'})
connector.connect()
import blockchainjs from 'blockchainjs'

var storage = new blockchainjs.storage.Memory({
networkName: 'testnet',
compactMode: true
let network = new blockchainjs.network.Chromanode({
url: blockchainjs.network.Chromanode.getSources('testnet')
})
let blockchain = new blockchain.blockchain.Verified(network, {
storage: new blockchainjs.storage.Memory(),
testnet: true
})

var blockchain = new blockchainjs.blockchain.Verified(connector, {
storage: storage,
networkName: 'testnet',
testnet: true,
compactMode: true,
chunkHashes: blockchainjs.chunkHashes.testnet
network.on('connect', () => console.log('connected'))
blockchain.on('newBlock', (payload) => {
console.log(`New height ${payload.height} (${payload.hash})`)
})

blockchain.on('syncStop', blockchainjs.util.makeSerial(function () {
return blockchain.getHeader(blockchain.latest.hash)
.then(function (header) {
console.log('Current header: ', header)
})
}))
network.connect()
```

## License

Code released under [the MIT license](LICENSE).

Copyright 2015 Chromaway AB

## Todo

* migrate to bitcore (in tests)
* add https://github.com/visionmedia/debug
This software is licensed under the MIT License.
2 changes: 1 addition & 1 deletion src/network/chromanode.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export default class Chromanode extends Network {
/**
* @param {Object} opts
* @param {string} opts.event newBlock or newTx
* @param {string[]} [opts.addresses]
* @param {string} [opts.address]
* @return {Promise}
*/
@makeConcurrent({concurrency: 1})
Expand Down

0 comments on commit 68d8101

Please sign in to comment.