Adam Brady
11 years ago
5 changed files with 208 additions and 122 deletions
@ -1,38 +1,48 @@ |
|||
'use strict'; |
|||
|
|||
// Replace path '..' to 'bitcore' if you are using this example
|
|||
// in a different project
|
|||
var networks = require('../networks'); |
|||
var Peer = require('../Peer').class(); |
|||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
|||
|
|||
var util = require('util'); |
|||
var networks = require('../networks'); |
|||
var Peer = require('../Peer').class(); |
|||
var PeerManager = require('../PeerManager').createClass({ |
|||
network: networks.testnet |
|||
}); |
|||
|
|||
var util= require('util'); |
|||
var handleBlock = function(info) { |
|||
|
|||
console.log('** Block Received **'); |
|||
console.log(info.message); |
|||
|
|||
var handleBlock = function(b) { |
|||
console.log('block received:', util.inspect(b.message,{depth:null})); |
|||
}; |
|||
|
|||
var handleTx = function(info) { |
|||
|
|||
var tx = info.message.tx.getStandardizedObject(); |
|||
console.log('block tx:', util.inspect(tx,{depth:null})); |
|||
|
|||
console.log('** Block TX **'); |
|||
console.log(tx); |
|||
|
|||
}; |
|||
|
|||
var handleInv = function(info) { |
|||
console.log('block inv:', util.inspect(info.message,{depth:null})); |
|||
|
|||
console.log('** Block Inv **'); |
|||
console.log(info.message); |
|||
|
|||
var invs = info.message.invs; |
|||
info.conn.sendGetData(invs); |
|||
}; |
|||
|
|||
}; |
|||
|
|||
var peerman = new PeerManager(); |
|||
peerman.addPeer( new Peer('127.0.0.1',18333) ); |
|||
|
|||
peerman.addPeer( new Peer('127.0.0.1', 18333) ); |
|||
|
|||
peerman.on('connection', function(conn) { |
|||
conn.on('inv', handleInv); |
|||
conn.on('inv', handleInv); |
|||
conn.on('block', handleBlock); |
|||
conn.on('tx', handleTx); |
|||
conn.on('tx', handleTx); |
|||
}); |
|||
peerman.start(); |
|||
|
|||
peerman.start(); |
|||
|
@ -1,23 +1,29 @@ |
|||
'use strict'; |
|||
|
|||
var util = require('util'); |
|||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
|||
|
|||
// Replace path '..' to 'bitcore' if you are using this example
|
|||
// in a different project
|
|||
var util = require('util'); |
|||
var RpcClient = require('../RpcClient').class(); |
|||
var hash = process.argv[2] |
|||
|| '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4'; |
|||
var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4'; |
|||
|
|||
var config = { |
|||
protocol: 'http', |
|||
user: 'user', |
|||
pass: 'pass', |
|||
host: '127.0.0.1', |
|||
port: '18332', |
|||
protocol: 'http', |
|||
user: 'user', |
|||
pass: 'pass', |
|||
host: '127.0.0.1', |
|||
port: '18332', |
|||
}; |
|||
|
|||
|
|||
var rpc = new RpcClient(config); |
|||
rpc.getBlock( hash, function(err, ret) { |
|||
console.log(err); |
|||
console.log(util.inspect(ret, { depth: 10} )); |
|||
|
|||
rpc.getBlock(hash, function(err, ret) { |
|||
|
|||
if(err) { |
|||
console.error("An error occured fetching block", hash); |
|||
console.error(err); |
|||
return; |
|||
} |
|||
|
|||
console.log(ret); |
|||
|
|||
}); |
|||
|
Loading…
Reference in new issue