You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
11 years ago
|
// 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();
|
||
|
|
||
|
|