Browse Source

Merge pull request #30 from stakwork/ten

Ten
feature/dockerfile-arm v0.8.16
Evan Feenstra 5 years ago
committed by GitHub
parent
commit
9a8d0effe3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      api/controllers/payment.ts
  2. 10
      api/grpc/index.ts
  3. 18
      api/utils/lightning.ts
  4. 7
      dist/api/controllers/payment.js
  5. 2
      dist/api/controllers/payment.js.map
  6. 4
      dist/api/grpc/index.js
  7. 2
      dist/api/grpc/index.js.map
  8. 20
      dist/api/utils/lightning.js
  9. 2
      dist/api/utils/lightning.js.map
  10. 2555
      rpc.proto

8
api/controllers/payment.ts

@ -160,11 +160,13 @@ const listPayments = async (req, res) => {
const payments: any[] = []
const MIN_VAL=3
const invs:any = await lightning.listAllInvoices()
if(invs && invs.length){
invs.forEach(inv=>{
const val = inv.value && parseInt(inv.value)
if(val && val>1) {
if(val && val>MIN_VAL) {
let payment_hash=''
if(inv.r_hash){
payment_hash = Buffer.from(inv.r_hash).toString('hex')
@ -184,12 +186,12 @@ const listPayments = async (req, res) => {
if(pays && pays.length){
pays.forEach(pay=>{
const val = pay.value && parseInt(pay.value)
if(val && val>1) {
if(val && val>MIN_VAL) {
payments.push({
type:'payment',
amount:parseInt(pay.value),
date:parseInt(pay.creation_date),
pubkey:pay.path[pay.path.length-1],
// pubkey:pay.path[pay.path.length-1],
payment_hash: pay.payment_hash,
})
}

10
api/grpc/index.ts

@ -101,10 +101,10 @@ function subscribeInvoices(actions) {
return new Promise(async(resolve,reject)=>{
const lightning = await loadLightning()
var call = lightning.subscribeInvoices();
var call = lightning.subscribeInvoices()
call.on('data', async function(response) {
// console.log('subscribed invoices', { response })
console.log('[GRPC] subscribeInvoices response', response)
console.log('[GRPC] subscribeInvoices received')
if (response['state'] !== 'SETTLED') {
return
}
@ -172,9 +172,9 @@ function subscribeInvoices(actions) {
call.on('status', function(status) {
console.log("Status", status);
resolve(status)
});
})
call.on('error', function(err){
// console.log(err)
console.error(err)
reject(err)
})
call.on('end', function() {
@ -182,7 +182,7 @@ function subscribeInvoices(actions) {
console.log(`Closed stream ${now}`);
// The server has closed the stream.
reconnectToLND()
});
})
setTimeout(()=>{
resolve(null)
},100)

18
api/utils/lightning.ts

@ -254,18 +254,20 @@ function listInvoicesPaginated(limit, offset) {
}
// need to upgrade to .10 for this
async function listAllPaymentsPaginated(){
const invs = await paginatePayments(40) // max num
return invs
async function listAllPayments(){
console.log("=> list all payments")
const pays = await paginatePayments(40) // max num
console.log('pays', pays && pays.length)
return pays
}
async function paginatePayments(limit,i=0){
try{
const r:any = await listPaymentsPaginated(limit,i)
const lastOffset = parseInt(r.first_index_offset) // this is "first" cuz its in reverse (lowest index)
if(lastOffset>0) {
return r.invoices.concat(await paginatePayments(limit,lastOffset))
return r.payments.concat(await paginatePayments(limit,lastOffset))
}
return r.invoices
return r.payments
}catch(e){
return []
}
@ -274,7 +276,7 @@ function listPaymentsPaginated(limit, offset) {
return new Promise(async(resolve, reject)=> {
const lightning = await loadLightning()
lightning.listPayments({
num_max_payments: limit,
max_payments: limit,
index_offset: offset,
reversed: true,
}, (err, response) => {
@ -284,7 +286,7 @@ function listPaymentsPaginated(limit, offset) {
})
}
function listAllPayments() {
function listAllPaymentsFull() {
console.log('=> list all payments')
return new Promise(async(resolve, reject)=> {
const lightning = await loadLightning()
@ -397,5 +399,5 @@ export {
listAllPayments,
checkConnection,
listAllInvoices,
listAllPaymentsPaginated,
listAllPaymentsFull,
}

7
dist/api/controllers/payment.js

@ -146,11 +146,12 @@ const listPayments = (req, res) => __awaiter(void 0, void 0, void 0, function* (
const limit = (req.query.limit && parseInt(req.query.limit)) || 100;
const offset = (req.query.offset && parseInt(req.query.offset)) || 0;
const payments = [];
const MIN_VAL = 3;
const invs = yield lightning.listAllInvoices();
if (invs && invs.length) {
invs.forEach(inv => {
const val = inv.value && parseInt(inv.value);
if (val && val > 1) {
if (val && val > MIN_VAL) {
let payment_hash = '';
if (inv.r_hash) {
payment_hash = Buffer.from(inv.r_hash).toString('hex');
@ -169,12 +170,12 @@ const listPayments = (req, res) => __awaiter(void 0, void 0, void 0, function* (
if (pays && pays.length) {
pays.forEach(pay => {
const val = pay.value && parseInt(pay.value);
if (val && val > 1) {
if (val && val > MIN_VAL) {
payments.push({
type: 'payment',
amount: parseInt(pay.value),
date: parseInt(pay.creation_date),
pubkey: pay.path[pay.path.length - 1],
// pubkey:pay.path[pay.path.length-1],
payment_hash: pay.payment_hash,
});
}

2
dist/api/controllers/payment.js.map

File diff suppressed because one or more lines are too long

4
dist/api/grpc/index.js

@ -121,7 +121,7 @@ function subscribeInvoices(actions) {
call.on('data', function (response) {
return __awaiter(this, void 0, void 0, function* () {
// console.log('subscribed invoices', { response })
console.log('[GRPC] subscribeInvoices response', response);
console.log('[GRPC] subscribeInvoices received');
if (response['state'] !== 'SETTLED') {
return;
}
@ -185,7 +185,7 @@ function subscribeInvoices(actions) {
resolve(status);
});
call.on('error', function (err) {
// console.log(err)
console.error(err);
reject(err);
});
call.on('end', function () {

2
dist/api/grpc/index.js.map

File diff suppressed because one or more lines are too long

20
dist/api/utils/lightning.js

@ -284,22 +284,24 @@ function listInvoicesPaginated(limit, offset) {
}));
}
// need to upgrade to .10 for this
function listAllPaymentsPaginated() {
function listAllPayments() {
return __awaiter(this, void 0, void 0, function* () {
const invs = yield paginatePayments(40); // max num
return invs;
console.log("=> list all payments");
const pays = yield paginatePayments(40); // max num
console.log('pays', pays && pays.length);
return pays;
});
}
exports.listAllPaymentsPaginated = listAllPaymentsPaginated;
exports.listAllPayments = listAllPayments;
function paginatePayments(limit, i = 0) {
return __awaiter(this, void 0, void 0, function* () {
try {
const r = yield listPaymentsPaginated(limit, i);
const lastOffset = parseInt(r.first_index_offset); // this is "first" cuz its in reverse (lowest index)
if (lastOffset > 0) {
return r.invoices.concat(yield paginatePayments(limit, lastOffset));
return r.payments.concat(yield paginatePayments(limit, lastOffset));
}
return r.invoices;
return r.payments;
}
catch (e) {
return [];
@ -310,7 +312,7 @@ function listPaymentsPaginated(limit, offset) {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
const lightning = yield loadLightning();
lightning.listPayments({
num_max_payments: limit,
max_payments: limit,
index_offset: offset,
reversed: true,
}, (err, response) => {
@ -321,7 +323,7 @@ function listPaymentsPaginated(limit, offset) {
});
}));
}
function listAllPayments() {
function listAllPaymentsFull() {
console.log('=> list all payments');
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
const lightning = yield loadLightning();
@ -335,7 +337,7 @@ function listAllPayments() {
});
}));
}
exports.listAllPayments = listAllPayments;
exports.listAllPaymentsFull = listAllPaymentsFull;
const signMessage = (msg) => {
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
let lightning = yield loadLightning();

2
dist/api/utils/lightning.js.map

File diff suppressed because one or more lines are too long

2555
rpc.proto

File diff suppressed because it is too large
Loading…
Cancel
Save