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