Ryan X. Charles
11 years ago
9 changed files with 307 additions and 1 deletions
@ -0,0 +1,23 @@ |
|||
|
|||
|
|||
// Replace path '..' to 'bitcore' if you are using this example
|
|||
// in a different project
|
|||
var Address = require('../Address').class(); |
|||
|
|||
var addrStrings = [ |
|||
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", |
|||
"1A1zP1eP5QGefi2DMPTfTL5SLmv7Dixxxx", |
|||
"A1zP1eP5QGefi2DMPTfTL5SLmv7Dixxxx", |
|||
"1600 Pennsylvania Ave NW", |
|||
]; |
|||
|
|||
addrStrings.forEach(function(addrStr){ |
|||
var addr = new Address(addrStr); |
|||
|
|||
try { |
|||
addr.validate(); |
|||
console.log(addr.data + ": is valid"); |
|||
} catch(e) { |
|||
console.log(addr.data + ": is not a valid address. " + e); |
|||
} |
|||
}); |
@ -0,0 +1,26 @@ |
|||
|
|||
// Replace path '..' to 'bitcore' if you are using this example
|
|||
// in a different project
|
|||
var networks = require('../networks'); |
|||
var Peer = require('../Peer').class(); |
|||
var PeerManager = require('../PeerManager').createClass({ |
|||
network: networks.testnet |
|||
}); |
|||
|
|||
|
|||
var handleBlock = function(b) { |
|||
console.log('block received:', b); |
|||
}; |
|||
|
|||
var handleTx = function(b) { |
|||
console.log('block tx:', b); |
|||
}; |
|||
|
|||
var peerman = new PeerManager(); |
|||
peerman.addPeer( new Peer('127.0.0.1',18333) ); |
|||
peerman.on('connect', function(conn) { |
|||
conn.on('block', handleBlock); |
|||
conn.on('tx', handleTx); |
|||
}); |
|||
peerman.start(); |
|||
|
@ -0,0 +1,23 @@ |
|||
|
|||
var util = require('util'); |
|||
|
|||
// Replace path '..' to 'bitcore' if you are using this example
|
|||
// in a different project
|
|||
var RpcClient = require('../RpcClient').class(); |
|||
var hash = process.argv[2] |
|||
|| '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4'; |
|||
|
|||
var config = { |
|||
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} )); |
|||
}); |
@ -0,0 +1,60 @@ |
|||
// Replace path '..' to 'bitcore' if you are using this example
|
|||
// in a different project
|
|||
var networks = require('../networks'); |
|||
var Peer = require('../Peer').class(); |
|||
var Transaction = require('../Transaction').class(); |
|||
var Address = require('../Address').class(); |
|||
var Script = require('../Script').class(); |
|||
var PeerManager = require('../PeerManager').createClass({ |
|||
network: networks.testnet |
|||
}); |
|||
var coinUtil = require('../util/util'); |
|||
|
|||
|
|||
var createTx = function() { |
|||
var TXIN='d05f35e0bbc495f6dcab03e599c8f5e32a07cdb4bc76964de201d06a2a7d8265'; |
|||
var TXIN_N=0; |
|||
var ADDR='muHct3YZ9Nd5Pq7uLYYhXRAxeW4EnpcaLz'; |
|||
var VAL='1.234'; |
|||
var txobj = {}; |
|||
txobj.version = 1; |
|||
txobj.lock_time = 0; |
|||
txobj.ins = []; |
|||
txobj.outs = []; |
|||
var txin = {}; |
|||
txin.s = coinUtil.EMPTY_BUFFER; //Add signature
|
|||
txin.q = 0xffffffff; |
|||
|
|||
var hash = new Buffer(TXIN, 'hex'); |
|||
hash.reverse(); |
|||
var vout = parseInt(TXIN_N); |
|||
var voutBuf = new Buffer(4); |
|||
voutBuf.writeUInt32LE(vout, 0); |
|||
txin.o = Buffer.concat([hash, voutBuf]); |
|||
txobj.ins.push(txin); |
|||
|
|||
var addr = new Address(ADDR); |
|||
var script = Script.createPubKeyHashOut(addr.payload()); |
|||
var valueNum = coinUtil.parseValue(VAL); |
|||
var value = coinUtil.bigIntToValue(valueNum); |
|||
|
|||
var txout = { |
|||
v: value, |
|||
s: script.getBuffer(), |
|||
}; |
|||
txobj.outs.push(txout); |
|||
|
|||
return new Transaction(txobj); |
|||
}; |
|||
|
|||
var peerman = new PeerManager(); |
|||
peerman.addPeer( new Peer('127.0.0.1',18333) ); |
|||
peerman.on('connect', function(conn) { |
|||
var conn = peerman.getActiveConnection(); |
|||
if (conn) |
|||
conn.sendTx(createTx()); |
|||
conn.on('reject', function () { console.log('Transaction Rejected'); } ); |
|||
}); |
|||
peerman.start(); |
|||
|
|||
|
Loading…
Reference in new issue