|
@ -211,12 +211,26 @@ helpers.toSatoshi = function(btc) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
helpers.stubUtxos = function(server, wallet, amounts, cb) { |
|
|
helpers.stubUtxos = function(server, wallet, amounts, opts, cb) { |
|
|
|
|
|
if (_.isFunction(opts)) { |
|
|
|
|
|
cb = opts; |
|
|
|
|
|
opts = {}; |
|
|
|
|
|
} |
|
|
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
|
|
|
|
if (!helpers._utxos) helpers._utxos = {}; |
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([ |
|
|
|
|
|
|
|
|
|
|
|
function(next) { |
|
|
|
|
|
if (opts.addresses) return next(null, [].concat(opts.addresses)); |
|
|
async.mapSeries(_.range(0, amounts.length > 2 ? 2 : 1), function(i, next) { |
|
|
async.mapSeries(_.range(0, amounts.length > 2 ? 2 : 1), function(i, next) { |
|
|
server.createAddress({}, next); |
|
|
server.createAddress({}, next); |
|
|
}, function(err, addresses) { |
|
|
}, next); |
|
|
should.not.exist(err); |
|
|
}, |
|
|
|
|
|
function(addresses, next) { |
|
|
addresses.should.not.be.empty; |
|
|
addresses.should.not.be.empty; |
|
|
|
|
|
|
|
|
var utxos = _.compact(_.map([].concat(amounts), function(amount, i) { |
|
|
var utxos = _.compact(_.map([].concat(amounts), function(amount, i) { |
|
|
var confirmations; |
|
|
var confirmations; |
|
|
if (_.isString(amount) && _.startsWith(amount, 'u')) { |
|
|
if (_.isString(amount) && _.startsWith(amount, 'u')) { |
|
@ -249,14 +263,25 @@ helpers.stubUtxos = function(server, wallet, amounts, cb) { |
|
|
confirmations: confirmations |
|
|
confirmations: confirmations |
|
|
}; |
|
|
}; |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
if (opts.keepUtxos) { |
|
|
|
|
|
helpers._utxos = helpers._utxos.concat(utxos); |
|
|
|
|
|
} else { |
|
|
|
|
|
helpers._utxos = utxos; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
blockchainExplorer.getUnspentUtxos = function(addresses, cb) { |
|
|
blockchainExplorer.getUnspentUtxos = function(addresses, cb) { |
|
|
var selected = _.filter(utxos, function(utxo) { |
|
|
var selected = _.filter(helpers._utxos, function(utxo) { |
|
|
return _.contains(addresses, utxo.address); |
|
|
return _.contains(addresses, utxo.address); |
|
|
}); |
|
|
}); |
|
|
return cb(null, selected); |
|
|
return cb(null, selected); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
return cb(utxos); |
|
|
return next(); |
|
|
|
|
|
}, |
|
|
|
|
|
], function(err) { |
|
|
|
|
|
should.not.exist(err); |
|
|
|
|
|
return cb(helpers._utxos); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -451,14 +476,14 @@ helpers.createProposalOpts = function(type, outputs, signingKey, moreOpts, input |
|
|
}; |
|
|
}; |
|
|
helpers.createAddresses = function(server, wallet, main, change, cb) { |
|
|
helpers.createAddresses = function(server, wallet, main, change, cb) { |
|
|
var clock = sinon.useFakeTimers(Date.now(), 'Date'); |
|
|
var clock = sinon.useFakeTimers(Date.now(), 'Date'); |
|
|
async.map(_.range(main + change), function(i, next) { |
|
|
async.mapSeries(_.range(main + change), function(i, next) { |
|
|
clock.tick(1000); |
|
|
clock.tick(1000); |
|
|
var address = wallet.createAddress(i >= main); |
|
|
var address = wallet.createAddress(i >= main); |
|
|
server.storage.storeAddressAndWallet(wallet, address, function(err) { |
|
|
server.storage.storeAddressAndWallet(wallet, address, function(err) { |
|
|
next(err, address); |
|
|
next(err, address); |
|
|
}); |
|
|
}); |
|
|
}, function(err, addresses) { |
|
|
}, function(err, addresses) { |
|
|
if (err) throw new Error('Could not generate addresses'); |
|
|
should.not.exist(err); |
|
|
clock.restore(); |
|
|
clock.restore(); |
|
|
return cb(_.take(addresses, main), _.takeRight(addresses, change)); |
|
|
return cb(_.take(addresses, main), _.takeRight(addresses, change)); |
|
|
}); |
|
|
}); |
|
|