commit
d3083a8503
4 changed files with 91 additions and 87 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bitcoinjs-lib",
|
"name": "bitcoinjs-lib",
|
||||||
"version": "2.1.2",
|
"version": "2.1.3",
|
||||||
"description": "Client-side Bitcoin JavaScript library",
|
"description": "Client-side Bitcoin JavaScript library",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -68,11 +68,11 @@
|
||||||
"create-hmac": "^1.1.3",
|
"create-hmac": "^1.1.3",
|
||||||
"ecurve": "^1.0.0",
|
"ecurve": "^1.0.0",
|
||||||
"randombytes": "^2.0.1",
|
"randombytes": "^2.0.1",
|
||||||
"typeforce": "^1.3.0",
|
"typeforce": "^1.5.5",
|
||||||
"wif": "^1.1.0"
|
"wif": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^0.9.0",
|
"async": "^1.5.0",
|
||||||
"blanket": "^1.1.0",
|
"blanket": "^1.1.0",
|
||||||
"browserify": "^10.0.0",
|
"browserify": "^10.0.0",
|
||||||
"bs58": "^2.0.1",
|
"bs58": "^2.0.1",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
var async = require('async')
|
||||||
var Blockchain = require('cb-http-client')
|
var Blockchain = require('cb-http-client')
|
||||||
var httpify = require('httpify')
|
var httpify = require('httpify')
|
||||||
|
|
||||||
|
@ -5,7 +6,13 @@ var BLOCKTRAIL_API_KEY = process.env.BLOCKTRAIL_API_KEY || 'c0bd8155c66e3fb148bb
|
||||||
|
|
||||||
var mainnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/BTC', { api_key: BLOCKTRAIL_API_KEY })
|
var mainnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/BTC', { api_key: BLOCKTRAIL_API_KEY })
|
||||||
var testnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/tBTC', { api_key: BLOCKTRAIL_API_KEY })
|
var testnet = new Blockchain('https://api.blocktrail.com/cb/v0.2.1/tBTC', { api_key: BLOCKTRAIL_API_KEY })
|
||||||
testnet.faucet = function faucet (address, amount, callback) {
|
|
||||||
|
testnet.faucet = function faucet (address, amount, done) {
|
||||||
|
var unspents = []
|
||||||
|
|
||||||
|
async.whilst(
|
||||||
|
function condition () { return unspents.length === 0 },
|
||||||
|
function f (callback) {
|
||||||
httpify({
|
httpify({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY,
|
url: 'https://api.blocktrail.com/v1/tBTC/faucet/withdrawl?api_key=' + BLOCKTRAIL_API_KEY,
|
||||||
|
@ -14,7 +21,27 @@ testnet.faucet = function faucet (address, amount, callback) {
|
||||||
address: address,
|
address: address,
|
||||||
amount: amount
|
amount: amount
|
||||||
})
|
})
|
||||||
}, callback)
|
}, function (err) {
|
||||||
|
if (err) return callback(err)
|
||||||
|
|
||||||
|
testnet.addresses.unspents(address, function (err, result) {
|
||||||
|
if (err) return callback(err)
|
||||||
|
|
||||||
|
// filter small unspents
|
||||||
|
unspents = result.filter(function (unspent) {
|
||||||
|
return unspent.value > 1e3
|
||||||
|
})
|
||||||
|
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
function (err) {
|
||||||
|
if (err) return done(err)
|
||||||
|
|
||||||
|
done(null, unspents)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -22,27 +22,17 @@ describe('bitcoinjs-lib (advanced)', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can create an OP_RETURN transaction', function (done) {
|
it('can create an OP_RETURN transaction', function (done) {
|
||||||
this.timeout(20000)
|
this.timeout(30000)
|
||||||
|
|
||||||
var network = bitcoin.networks.testnet
|
var network = bitcoin.networks.testnet
|
||||||
var keyPair = bitcoin.ECPair.makeRandom({ network: network })
|
var keyPair = bitcoin.ECPair.makeRandom({ network: network })
|
||||||
var address = keyPair.getAddress()
|
var address = keyPair.getAddress()
|
||||||
|
|
||||||
blockchain.t.faucet(address, 2e4, function (err) {
|
blockchain.t.faucet(address, 2e4, function (err, unspents) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
blockchain.t.addresses.unspents(address, function (err, unspents) {
|
|
||||||
if (err) return done(err)
|
|
||||||
|
|
||||||
// filter small unspents
|
|
||||||
unspents = unspents.filter(function (unspent) {
|
|
||||||
return unspent.value > 1e4
|
|
||||||
})
|
|
||||||
|
|
||||||
// use the oldest unspent
|
// use the oldest unspent
|
||||||
var unspent = unspents.pop()
|
var unspent = unspents.pop()
|
||||||
if (!unspent) throw new Error('Faucet didn\'t provide an unspent')
|
|
||||||
|
|
||||||
var tx = new bitcoin.TransactionBuilder(network)
|
var tx = new bitcoin.TransactionBuilder(network)
|
||||||
var data = new Buffer('bitcoinjs-lib')
|
var data = new Buffer('bitcoinjs-lib')
|
||||||
var dataScript = bitcoin.script.nullDataOutput(data)
|
var dataScript = bitcoin.script.nullDataOutput(data)
|
||||||
|
@ -72,5 +62,4 @@ describe('bitcoinjs-lib (advanced)', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -37,23 +37,12 @@ describe('bitcoinjs-lib (multisig)', function () {
|
||||||
var address = bitcoin.address.fromOutputScript(scriptPubKey, bitcoin.networks.testnet)
|
var address = bitcoin.address.fromOutputScript(scriptPubKey, bitcoin.networks.testnet)
|
||||||
|
|
||||||
// attempt to send funds to the source address
|
// attempt to send funds to the source address
|
||||||
blockchain.t.faucet(address, 2e4, function (err) {
|
blockchain.t.faucet(address, 2e4, function (err, unspents) {
|
||||||
if (err) return done(err)
|
if (err) return done(err)
|
||||||
|
|
||||||
// get latest unspents from the address
|
|
||||||
blockchain.t.addresses.unspents(address, function (err, unspents) {
|
|
||||||
if (err) return done(err)
|
|
||||||
|
|
||||||
// filter small unspents
|
|
||||||
unspents = unspents.filter(function (unspent) {
|
|
||||||
return unspent.value > 1e4
|
|
||||||
})
|
|
||||||
|
|
||||||
// use the oldest unspent
|
// use the oldest unspent
|
||||||
var unspent = unspents.pop()
|
var unspent = unspents.pop()
|
||||||
|
|
||||||
if (!unspent) throw new Error('Faucet didn\'t provide an unspent')
|
|
||||||
|
|
||||||
// make a random destination address
|
// make a random destination address
|
||||||
var targetAddress = bitcoin.ECPair.makeRandom({
|
var targetAddress = bitcoin.ECPair.makeRandom({
|
||||||
network: bitcoin.networks.testnet
|
network: bitcoin.networks.testnet
|
||||||
|
@ -87,5 +76,4 @@ describe('bitcoinjs-lib (multisig)', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue