Skip to content

Commit 254b27e

Browse files
authored
Merge branch 'master' into more_push_notifications
2 parents 1e33be8 + 89187db commit 254b27e

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

api/lnd/index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cachedFetcher } from '@/lib/fetch'
22
import { toPositiveNumber } from '@/lib/format'
33
import { authenticatedLndGrpc } from '@/lib/lnd'
4-
import { getIdentity, getHeight, getWalletInfo, getNode, getPayment } from 'ln-service'
4+
import { getIdentity, getHeight, getWalletInfo, getNode, getPayment, parsePaymentRequest } from 'ln-service'
55
import { datePivot } from '@/lib/time'
66
import { LND_PATHFINDING_TIMEOUT_MS } from '@/lib/constants'
77

@@ -23,11 +23,34 @@ getWalletInfo({ lnd }, (err, result) => {
2323
})
2424

2525
export async function estimateRouteFee ({ lnd, destination, tokens, mtokens, request, timeout }) {
26+
// if the payment request includes us as route hint, we needd to use the destination and amount
27+
// otherwise, this will fail with a self-payment error
28+
if (request) {
29+
const inv = parsePaymentRequest({ request })
30+
const ourPubkey = await getOurPubkey({ lnd })
31+
if (Array.isArray(inv.routes)) {
32+
for (const route of inv.routes) {
33+
if (Array.isArray(route)) {
34+
for (const hop of route) {
35+
if (hop.public_key === ourPubkey) {
36+
console.log('estimateRouteFee ignoring self-payment route')
37+
request = false
38+
break
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
2646
return await new Promise((resolve, reject) => {
2747
const params = {}
48+
2849
if (request) {
50+
console.log('estimateRouteFee using payment request')
2951
params.payment_request = request
3052
} else {
53+
console.log('estimateRouteFee using destination and amount')
3154
params.dest = Buffer.from(destination, 'hex')
3255
params.amt_sat = tokens ? toPositiveNumber(tokens) : toPositiveNumber(BigInt(mtokens) / BigInt(1e3))
3356
}

worker/search.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export async function indexItem ({ data: { id, updatedAt }, apollo, models }) {
117117
}`
118118
})
119119

120+
if (!item) {
121+
console.log('item not found', id)
122+
return
123+
}
124+
120125
// 2. index it with external version based on updatedAt
121126
await _indexItem(item, { models, updatedAt })
122127
}

worker/weeklyPosts.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export async function payWeeklyPostBounty ({ data: { id }, models, apollo, lnd }
3131
bounty
3232
bountyPaidTo
3333
comments(sort: "top") {
34-
id
34+
comments {
35+
id
36+
}
3537
}
3638
}
3739
}`,
@@ -44,7 +46,7 @@ export async function payWeeklyPostBounty ({ data: { id }, models, apollo, lnd }
4446
throw new Error('Bounty already paid')
4547
}
4648

47-
const winner = item.comments[0]
49+
const winner = item.comments.comments[0]
4850

4951
if (!winner) {
5052
throw new Error('No winner')

0 commit comments

Comments
 (0)