client.generate(blocks, function(err, response) { if (err) { throw err; } blockHashes = response.result; log.info('Preparing test data...'); // Get all of the unspent outputs client.listUnspent(0, blocks, function(err, response) { var utxos = response.result; async.mapSeries(utxos, function(utxo, next) { async.series([ function(finished) { // Load all of the transactions for later testing client.getTransaction(utxo.txid, function(err, txresponse) { if (err) { throw err; } // add to the list of transactions for testing later transactionData.push(txresponse.result.hex); finished(); }); }, function(finished) { // Get the private key for each utxo client.dumpPrivKey(utxo.address, function(err, privresponse) { if (err) { throw err; } utxo.privateKeyWIF = privresponse.result; var tx = bitcore.Transaction(); tx.from(utxo); tx.change(privateKey.toAddress()); tx.to(destKey.toAddress(), utxo.amount * 1e8 - 1000); tx.sign(bitcore.PrivateKey.fromWIF(utxo.privateKeyWIF)); txs.push(tx); finished(); }); } ], next); }, function(err) { if (err) { throw err; } peer.on('ready', function() { log.info('Peer ready'); done(); }); log.info('Connecting to peer'); peer.connect(); }); }); });
var getFirstIncomingFunds = function(callback) { initialTx = new Transaction(); rpc.listUnspent(function(err, res) { if (err) { return callback(err); } var unspent = res.result[0]; rpc.dumpPrivKey(unspent.address, function(err, res) { if (err) { return callback(err); } startingPk = new PrivateKey(res.result); var utxo = { txId: unspent.txid, outputIndex: unspent.vout, script: unspent.scriptPubKey, satoshis: unspent.amount * 1e8, address: unspent.address }; initialTx.from(utxo).to(pks[0].toAddress(), 20*1e8).change(startingPk.toAddress()).fee(50000).sign(startingPk); var body = '{"rawtx":"' + initialTx.serialize() + '"}'; var httpOpts = { hostname: 'localhost', port: 53001, path: 'http://localhost:53001/api/tx/send', method: 'POST', body: body, headers: { 'Content-Type': 'application/json', 'Content-Length': body.length }, }; request(httpOpts, function(err, data) { if (err) { return callback(err); } console.log('Sent initial tx: ', initialTx.hash); txids.push(data.txid); callback(); }); }); }); };
client.generate(150, function(err, response) { if (err) { throw err; } blockHashes = response.result; log.info('Preparing test data...'); // Get all of the unspent outputs client.listUnspent(0, 150, function(err, response) { utxos = response.result; async.mapSeries(utxos, function(utxo, next) { async.series([ function(finished) { // Load all of the transactions for later testing client.getTransaction(utxo.txid, function(err, txresponse) { if (err) { throw err; } // add to the list of transactions for testing later transactionData.push(txresponse.result.hex); finished(); }); }, function(finished) { // Get the private key for each utxo client.dumpPrivKey(utxo.address, function(err, privresponse) { if (err) { throw err; } utxo.privateKeyWIF = privresponse.result; finished(); }); } ], next); }, function(err) { if (err) { throw err; } done(); }); }); });