Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ AddressController.prototype.checkAddr = function(req, res, next) {
AddressController.prototype.checkAddrs = function(req, res, next) {
if(req.body.addrs) {
req.addrs = req.body.addrs.split(',');
} else {
} else if (req.params.addrs) {
req.addrs = req.params.addrs.split(',');
}

this.check(req, res, next, req.addrs);
}
};

AddressController.prototype.check = function(req, res, next, addresses) {
if(!addresses.length || !addresses[0]) {
if(!addresses || !addresses.length || !addresses[0]) {
return common.handleErrors({
message: 'Must include address',
code: 1
}, res);
}

for(var i = 0; i < addresses.length; i++) {
var address;
try {
var a = new bitcore.Address(addresses[i]);
address = new bitcore.Address(addresses[i], this.node.network);
} catch(e) {
return common.handleErrors({
message: 'Invalid address: ' + e.message,
Expand Down
22 changes: 22 additions & 0 deletions test/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ var utxos = [
}
];

describe('Addresses Methods', function() {
it('#checkAddrs', function(done) {
var addresses = new AddressController({});
var req = {
body: {},
params: {}
};
var status = sinon.stub().returns({
send: function(data) {
status.args[0][0].should.equal(400);
data.should.match(/^Must include address/);
done();
}
})
var res = {
send: sinon.stub(),
status: status
};
addresses.checkAddr(req, res, function() {});
});
});

describe('Addresses', function() {
var summary = {
balance: 0,
Expand Down