2016-08-13 03:42:16 +02:00
|
|
|
/* global describe, it */
|
2015-02-23 00:36:57 +01:00
|
|
|
|
2014-11-24 11:15:28 +01:00
|
|
|
var bitcoin = require('../../')
|
2015-08-07 06:47:07 +02:00
|
|
|
var blockchain = require('./_blockchain')
|
2014-11-24 11:15:28 +01:00
|
|
|
|
2015-02-23 00:36:57 +01:00
|
|
|
describe('bitcoinjs-lib (advanced)', function () {
|
2015-09-08 08:17:34 +02:00
|
|
|
it('can create an OP_RETURN transaction', function (done) {
|
2016-10-07 02:37:44 +02:00
|
|
|
this.timeout(30000)
|
2014-11-25 04:21:48 +01:00
|
|
|
|
2015-08-07 12:39:58 +02:00
|
|
|
var network = bitcoin.networks.testnet
|
|
|
|
var keyPair = bitcoin.ECPair.makeRandom({ network: network })
|
2015-07-08 07:56:21 +02:00
|
|
|
var address = keyPair.getAddress()
|
2014-11-25 04:21:48 +01:00
|
|
|
|
2016-01-06 02:46:02 +01:00
|
|
|
blockchain.t.faucet(address, 2e4, function (err, unspent) {
|
2014-11-25 04:21:48 +01:00
|
|
|
if (err) return done(err)
|
|
|
|
|
2015-11-06 00:49:06 +01:00
|
|
|
var tx = new bitcoin.TransactionBuilder(network)
|
|
|
|
var data = new Buffer('bitcoinjs-lib')
|
|
|
|
var dataScript = bitcoin.script.nullDataOutput(data)
|
2015-08-25 06:11:49 +02:00
|
|
|
|
2015-11-06 00:49:06 +01:00
|
|
|
tx.addInput(unspent.txId, unspent.vout)
|
|
|
|
tx.addOutput(dataScript, 1000)
|
|
|
|
tx.sign(0, keyPair)
|
2016-01-05 04:40:51 +01:00
|
|
|
var txRaw = tx.build()
|
2015-08-25 06:11:49 +02:00
|
|
|
|
2016-01-05 04:40:51 +01:00
|
|
|
blockchain.t.transactions.propagate(txRaw.toHex(), done)
|
|
|
|
})
|
|
|
|
})
|
2014-11-24 11:15:28 +01:00
|
|
|
})
|