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