FIX: redis balance is only a cashe; tx list is a source of truth for user's balance
This commit is contained in:
@@ -57,7 +57,7 @@ router.post('/create', async function(req, res) {
|
||||
logger.log('/create', [req.id]);
|
||||
if (!(req.body.partnerid && req.body.partnerid === 'bluewallet' && req.body.accounttype)) return errorBadArguments(res);
|
||||
|
||||
let u = new User(redis);
|
||||
let u = new User(redis, bitcoinclient, lightning);
|
||||
await u.create();
|
||||
await u.saveMetadata({ partnerid: req.body.partnerid, accounttype: req.body.accounttype, created_at: new Date().toISOString() });
|
||||
res.send({ login: u.getLogin(), password: u.getPassword() });
|
||||
@@ -67,7 +67,7 @@ router.post('/auth', async function(req, res) {
|
||||
logger.log('/auth', [req.id]);
|
||||
if (!((req.body.login && req.body.password) || req.body.refresh_token)) return errorBadArguments(res);
|
||||
|
||||
let u = new User(redis);
|
||||
let u = new User(redis, bitcoinclient, lightning);
|
||||
|
||||
if (req.body.refresh_token) {
|
||||
// need to refresh token
|
||||
@@ -86,7 +86,7 @@ router.post('/auth', async function(req, res) {
|
||||
|
||||
router.post('/addinvoice', async function(req, res) {
|
||||
logger.log('/addinvoice', [req.id]);
|
||||
let u = new User(redis);
|
||||
let u = new User(redis, bitcoinclient, lightning);
|
||||
if (!(await u.loadByAuthorization(req.headers.authorization))) {
|
||||
return errorBadAuth(res);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ router.post('/addinvoice', async function(req, res) {
|
||||
|
||||
router.post('/payinvoice', async function(req, res) {
|
||||
logger.log('/payinvoice', [req.id]);
|
||||
let u = new User(redis);
|
||||
let u = new User(redis, bitcoinclient, lightning);
|
||||
if (!(await u.loadByAuthorization(req.headers.authorization))) {
|
||||
return errorBadAuth(res);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ router.post('/payinvoice', async function(req, res) {
|
||||
return errorLnd(res);
|
||||
}
|
||||
|
||||
let UserPayee = new User(redis);
|
||||
let UserPayee = new User(redis, bitcoinclient, lightning);
|
||||
UserPayee._userid = userid_payee; // hacky, fixme
|
||||
let payee_balance = await UserPayee.getBalance();
|
||||
payee_balance += info.num_satoshis * 1;
|
||||
@@ -247,7 +247,7 @@ router.get('/balance', async function(req, res) {
|
||||
|
||||
router.get('/getinfo', async function(req, res) {
|
||||
logger.log('/getinfo', [req.id]);
|
||||
let u = new User(redis);
|
||||
let u = new User(redis, bitcoinclient, lightning);
|
||||
if (!(await u.loadByAuthorization(req.headers.authorization))) {
|
||||
return errorBadAuth(res);
|
||||
}
|
||||
@@ -311,7 +311,7 @@ router.get('/getpending', async function(req, res) {
|
||||
|
||||
router.get('/decodeinvoice', async function(req, res) {
|
||||
logger.log('/decodeinvoice', [req.id]);
|
||||
let u = new User(redis, bitcoinclient);
|
||||
let u = new User(redis, bitcoinclient, lightning);
|
||||
if (!(await u.loadByAuthorization(req.headers.authorization))) {
|
||||
return errorBadAuth(res);
|
||||
}
|
||||
@@ -326,7 +326,7 @@ router.get('/decodeinvoice', async function(req, res) {
|
||||
|
||||
router.get('/checkrouteinvoice', async function(req, res) {
|
||||
logger.log('/checkrouteinvoice', [req.id]);
|
||||
let u = new User(redis, bitcoinclient);
|
||||
let u = new User(redis, bitcoinclient, lightning);
|
||||
if (!(await u.loadByAuthorization(req.headers.authorization))) {
|
||||
return errorBadAuth(res);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user