commit
b637ae878d
20
app.js
20
app.js
|
@ -181,6 +181,26 @@ router.get('/v1/balance/', function(req, res) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post('/v1/txproposals/:id/signatures', function(req, res) {
|
||||||
|
req.body.txProposalId = req.params['id'];
|
||||||
|
getServerWithAuth(req, res, function(server) {
|
||||||
|
server.signTx(req.body, function(err, txp) {
|
||||||
|
if (err) return returnError(err, res, req);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/v1/txproposals/:id/rejections', function(req, res) {
|
||||||
|
req.body.txProposalId = req.params['id'];
|
||||||
|
getServerWithAuth(req, res, function(server) {
|
||||||
|
server.signTx(req.body, function(err, txp) {
|
||||||
|
if (err) return returnError(err, res, req);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: DEBUG only!
|
// TODO: DEBUG only!
|
||||||
router.get('/v1/dump', function(req, res) {
|
router.get('/v1/dump', function(req, res) {
|
||||||
var server = CopayServer.getInstance();
|
var server = CopayServer.getInstance();
|
||||||
|
|
|
@ -105,17 +105,6 @@ Storage.prototype.fetchCopayerLookup = function(copayerId, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Storage.prototype.fetchTx = function(walletId, txProposalId, cb) {
|
|
||||||
this.db.get(KEY.TXP(walletId, txProposalId), function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
if (err.notFound) return cb();
|
|
||||||
return cb(err);
|
|
||||||
}
|
|
||||||
return cb(null, TxProposal.fromObj(data));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Storage.prototype.fetchNotification = function(walletId, notificationId, cb) {
|
Storage.prototype.fetchNotification = function(walletId, notificationId, cb) {
|
||||||
this.db.get(KEY.NOTIFICATION(walletId, notificationId), function(err, data) {
|
this.db.get(KEY.NOTIFICATION(walletId, notificationId), function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -126,9 +115,35 @@ Storage.prototype.fetchNotification = function(walletId, notificationId, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Storage.prototype._completeTxData = function(walletId, txs, cb) {
|
||||||
|
var txList = [].concat(txs);
|
||||||
|
this.fetchWallet(walletId, function(err, wallet) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
_.each(txList, function(tx) {
|
||||||
|
tx.creatorName = wallet.getCopayer(tx.creatorId).name;
|
||||||
|
_.each(_.values(tx.actions), function(action) {
|
||||||
|
action.copayerName = wallet.getCopayer(action.copayerId).name;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return cb(null, txs);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Storage.prototype.fetchTx = function(walletId, txProposalId, cb) {
|
||||||
|
var self = this;
|
||||||
|
this.db.get(KEY.TXP(walletId, txProposalId), function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
if (err.notFound) return cb();
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
return self._completeTxData(walletId, TxProposal.fromObj(data), cb);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Storage.prototype.fetchPendingTxs = function(walletId, cb) {
|
Storage.prototype.fetchPendingTxs = function(walletId, cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
var txs = [];
|
var txs = [];
|
||||||
var key = KEY.PENDING_TXP(walletId);
|
var key = KEY.PENDING_TXP(walletId);
|
||||||
this.db.createReadStream({
|
this.db.createReadStream({
|
||||||
|
@ -143,7 +158,7 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
})
|
})
|
||||||
.on('end', function() {
|
.on('end', function() {
|
||||||
return cb(null, txs);
|
return self._completeTxData(walletId, txs, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -156,6 +171,8 @@ Storage.prototype.fetchPendingTxs = function(walletId, cb) {
|
||||||
* @param opts.limit
|
* @param opts.limit
|
||||||
*/
|
*/
|
||||||
Storage.prototype.fetchTxs = function(walletId, opts, cb) {
|
Storage.prototype.fetchTxs = function(walletId, opts, cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
var txs = [];
|
var txs = [];
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
opts.limit = _.isNumber(opts.limit) ? parseInt(opts.limit) : -1;
|
opts.limit = _.isNumber(opts.limit) ? parseInt(opts.limit) : -1;
|
||||||
|
@ -179,7 +196,7 @@ Storage.prototype.fetchTxs = function(walletId, opts, cb) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
})
|
})
|
||||||
.on('end', function() {
|
.on('end', function() {
|
||||||
return cb(null, txs);
|
return self._completeTxData(walletId, txs, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1065,7 +1065,15 @@ describe('Copay server', function() {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
txp.status.should.equal('broadcasted');
|
txp.status.should.equal('broadcasted');
|
||||||
txp.txid.should.equal('1122334455');
|
txp.txid.should.equal('1122334455');
|
||||||
done();
|
server.getTx({
|
||||||
|
id: txp.id
|
||||||
|
}, function(err, txp) {
|
||||||
|
var actions = _.values(txp.actions);
|
||||||
|
actions.length.should.equal(1);
|
||||||
|
actions[0].copayerId.should.equal(wallet.copayers[0].id);
|
||||||
|
actions[0].copayerName.should.equal(wallet.copayers[0].name);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue