Manuel Araoz
11 years ago
6 changed files with 187 additions and 137 deletions
@ -1,19 +1,27 @@ |
|||
'use strict'; |
|||
|
|||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
|||
|
|||
var Address = require('../Address'); |
|||
var run = function() { |
|||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
|||
var Address = require('../Address'); |
|||
|
|||
var addrs = [ |
|||
var addrs = [ |
|||
'1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', |
|||
'1A1zP1eP5QGefi2DMPTfTL5SLmv7Dixxxx', |
|||
'A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', |
|||
'1600 Pennsylvania Ave NW', |
|||
].map(function(addr) { |
|||
].map(function(addr) { |
|||
return new Address(addr); |
|||
}); |
|||
}); |
|||
|
|||
addrs.forEach(function(addr) { |
|||
addrs.forEach(function(addr) { |
|||
var valid = addr.isValid(); |
|||
console.log(addr.data + ' is ' + (valid ? '' : 'not ') + 'valid'); |
|||
}); |
|||
}); |
|||
|
|||
}; |
|||
|
|||
module.exports.run = run; |
|||
if (require.main === module) { |
|||
run(); |
|||
} |
|||
|
@ -1,47 +1,47 @@ |
|||
'use strict'; |
|||
|
|||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
|||
|
|||
var util = require('util'); |
|||
var networks = require('../networks'); |
|||
var Peer = require('../Peer'); |
|||
var PeerManager = require('soop').load('../PeerManager', |
|||
{network: networks.testnet}); |
|||
|
|||
var handleBlock = function(info) { |
|||
|
|||
var run = function() { |
|||
// Replace '..' with 'bitcore' if you plan on using this code elsewhere.
|
|||
var networks = require('../networks'); |
|||
var Peer = require('../Peer'); |
|||
var PeerManager = require('soop').load('../PeerManager', { |
|||
network: networks.testnet |
|||
}); |
|||
|
|||
var handleBlock = function(info) { |
|||
console.log('** Block Received **'); |
|||
console.log(info.message); |
|||
}; |
|||
|
|||
}; |
|||
|
|||
var handleTx = function(info) { |
|||
|
|||
var handleTx = function(info) { |
|||
var tx = info.message.tx.getStandardizedObject(); |
|||
|
|||
console.log('** Block TX **'); |
|||
console.log('** TX Received **'); |
|||
console.log(tx); |
|||
}; |
|||
|
|||
}; |
|||
|
|||
var handleInv = function(info) { |
|||
|
|||
console.log('** Block Inv **'); |
|||
var handleInv = function(info) { |
|||
console.log('** Inv **'); |
|||
console.log(info.message); |
|||
|
|||
var invs = info.message.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('block', handleBlock); |
|||
conn.on('tx', handleTx); |
|||
}); |
|||
}); |
|||
|
|||
peerman.start(); |
|||
}; |
|||
|
|||
peerman.start(); |
|||
module.exports.run = run; |
|||
if (require.main === module) { |
|||
run(); |
|||
} |
|||
|
@ -0,0 +1,14 @@ |
|||
'use strict'; |
|||
|
|||
var backup = console.log; |
|||
var nop = function() {}; |
|||
var mute = function() { |
|||
console.log = nop; |
|||
}; |
|||
|
|||
var unmute = function() { |
|||
console.log = backup; |
|||
}; |
|||
|
|||
module.exports.mute = mute; |
|||
module.exports.unmute = unmute; |
@ -0,0 +1,24 @@ |
|||
'use strict'; |
|||
|
|||
var chai = chai || require('chai'); |
|||
var should = chai.should(); |
|||
var mute = require('./mute').mute; |
|||
var unmute = require('./mute').unmute; |
|||
|
|||
var examples = [ |
|||
'Address', |
|||
'PeerManager', |
|||
'Rpc', |
|||
'SendTx', |
|||
]; |
|||
|
|||
describe('Examples run', function() { |
|||
before(mute); |
|||
after(unmute); |
|||
examples.forEach(function(example) { |
|||
it('valid '+example, function() { |
|||
var ex = require('../examples/'+example); |
|||
ex.run.should.not.throw(); |
|||
}); |
|||
}); |
|||
}); |
Loading…
Reference in new issue