add express endpoint
This commit is contained in:
parent
dffdebfb47
commit
f418009ebf
|
@ -350,6 +350,19 @@ ExpressApp.prototype.start = function(opts, cb) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/v1/sendmaxinfo/', function(req, res) {
|
||||||
|
getServerWithAuth(req, res, function(server) {
|
||||||
|
var opts = {};
|
||||||
|
opts.feePerKb = +req.query.feePerKb;
|
||||||
|
if (req.query.excludeUnconfirmedUtxos == '1') opts.excludeUnconfirmedUtxos = true;
|
||||||
|
if (req.query.returnInputs == '1') opts.returnInputs = true;
|
||||||
|
server.getSendMaxInfo(opts, function(err, info) {
|
||||||
|
if (err) return returnError(err, res, req);
|
||||||
|
res.json(info);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
router.get('/v1/utxos/', function(req, res) {
|
router.get('/v1/utxos/', function(req, res) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
var addresses = req.query.addresses;
|
var addresses = req.query.addresses;
|
||||||
|
|
|
@ -1207,11 +1207,13 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) {
|
||||||
|
|
||||||
lastFee = fee;
|
lastFee = fee;
|
||||||
});
|
});
|
||||||
|
|
||||||
info.size = txp.getEstimatedSize();
|
info.size = txp.getEstimatedSize();
|
||||||
info.fee = txp.getEstimatedFee();
|
info.fee = txp.getEstimatedFee();
|
||||||
info.amount = _.sum(txp.inputs, 'satoshis') - info.fee;
|
info.amount = _.sum(txp.inputs, 'satoshis') - info.fee;
|
||||||
if (opts.returnInputs) info.inputs = txp.inputs;
|
if (opts.returnInputs) {
|
||||||
|
// TODO: Shuffle inputs
|
||||||
|
info.inputs = txp.inputs;
|
||||||
|
}
|
||||||
|
|
||||||
return cb(null, info);
|
return cb(null, info);
|
||||||
});
|
});
|
||||||
|
|
|
@ -113,6 +113,38 @@ describe('ExpressApp', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('/v1/sendmaxinfo', function(done) {
|
||||||
|
var server = {
|
||||||
|
getSendMaxInfo: sinon.stub().callsArgWith(1, null, {
|
||||||
|
amount: 123
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
var TestExpressApp = proxyquire('../lib/expressapp', {
|
||||||
|
'./server': {
|
||||||
|
initialize: sinon.stub().callsArg(1),
|
||||||
|
getInstanceWithAuth: sinon.stub().callsArgWith(1, null, server),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
start(TestExpressApp, function() {
|
||||||
|
var requestOptions = {
|
||||||
|
url: testHost + ':' + testPort + config.basePath + '/v1/sendmaxinfo?feePerKb=10000&returnInputs=1',
|
||||||
|
headers: {
|
||||||
|
'x-identity': 'identity',
|
||||||
|
'x-signature': 'signature'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
request(requestOptions, function(err, res, body) {
|
||||||
|
should.not.exist(err);
|
||||||
|
res.statusCode.should.equal(200);
|
||||||
|
var args = server.getSendMaxInfo.getCalls()[0].args[0];
|
||||||
|
args.feePerKb.should.equal(10000);
|
||||||
|
args.returnInputs.should.be.true;
|
||||||
|
JSON.parse(body).amount.should.equal(123);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Balance', function() {
|
describe('Balance', function() {
|
||||||
it('should handle cache argument', function(done) {
|
it('should handle cache argument', function(done) {
|
||||||
var server = {
|
var server = {
|
||||||
|
|
Loading…
Reference in New Issue