Commit b4f26242 authored by Kirill Fomichev's avatar Kirill Fomichev
Browse files

update example in readme

parent 1876f146
......@@ -18,10 +18,9 @@ npm install bitcoind-rpc
## Examples
```javascript
var run = function() {
var bitcore = require('bitcore');
var RpcClient = require('bitcoind-rpc');
var hash = '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4';
var config = {
protocol: 'http',
......@@ -33,14 +32,41 @@ var run = function() {
var rpc = new RpcClient(config);
rpc.getBlock(hash, function(err, ret) {
if (err) {
console.error('An error occured fetching block', hash);
console.error(err);
return;
}
console.log(ret);
});
var txids = [];
function showNewTransactions() {
rpc.getRawMemPool(function (err, ret) {
if (err) {
console.error(err);
return setTimeout(showNewTransactions, 10000);
}
function batchCall() {
ret.result.forEach(function (txid) {
if (txids.indexOf(txid) === -1) {
rpc.getRawTransaction(txid);
}
});
}
rpc.batch(batchCall, function(err, rawtxs) {
if (err) {
console.error(err);
return setTimeout(showNewTransactions, 10000);
}
rawtxs.map(function (rawtx) {
var tx = new bitcore.Transaction(rawtx.result);
console.log('\n\n\n' + tx.id + ':', tx.toObject());
});
txids = ret.result;
setTimeout(showNewTransactions, 2500);
});
});
}
showNewTransactions();
};
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment