Merge branch 'master' into local-dev-lnbits-recv

This commit is contained in:
Keyan 2024-10-20 17:38:57 -05:00 committed by GitHub
commit 6049baf742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 44 additions and 29 deletions

View File

@ -21,19 +21,24 @@ getWalletInfo({ lnd }, (err, result) => {
export async function estimateRouteFee ({ lnd, destination, tokens, mtokens, request, timeout }) { export async function estimateRouteFee ({ lnd, destination, tokens, mtokens, request, timeout }) {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
const params = {}
if (request) {
params.payment_request = request
} else {
params.dest = Buffer.from(destination, 'hex')
params.amt_sat = tokens ? toPositiveNumber(tokens) : toPositiveNumber(BigInt(mtokens) / BigInt(1e3))
}
lnd.router.estimateRouteFee({ lnd.router.estimateRouteFee({
dest: Buffer.from(destination, 'hex'), ...params,
amt_sat: tokens ? toPositiveNumber(tokens) : toPositiveNumber(BigInt(mtokens) / BigInt(1e3)),
payment_request: request,
timeout timeout
}, (err, res) => { }, (err, res) => {
if (err) { if (err) {
reject(err) if (res?.failure_reason) {
return reject(new Error(`Unable to estimate route: ${res.failure_reason}`))
} } else {
reject(err)
if (res?.failure_reason) { }
reject(new Error(`Unable to estimate route: ${res.failure_reason}`))
return return
} }
@ -126,7 +131,7 @@ export const getBlockHeight = cachedFetcher(async function fetchBlockHeight ({ l
export const getOurPubkey = cachedFetcher(async function fetchOurPubkey ({ lnd, ...args }) { export const getOurPubkey = cachedFetcher(async function fetchOurPubkey ({ lnd, ...args }) {
try { try {
const { identity } = await getIdentity({ lnd, ...args }) const identity = await getIdentity({ lnd, ...args })
return identity.public_key return identity.public_key
} catch (err) { } catch (err) {
throw new Error(`Unable to fetch identity: ${err.message}`) throw new Error(`Unable to fetch identity: ${err.message}`)

View File

@ -260,7 +260,7 @@ export default {
const { name } = data const { name } = data
await ssValidate(territorySchema, data, { models, me, sub: { name } }) await ssValidate(territorySchema, data, { models, me })
const oldSub = await models.sub.findUnique({ where: { name } }) const oldSub = await models.sub.findUnique({ where: { name } })
if (!oldSub) { if (!oldSub) {

View File

@ -482,12 +482,12 @@ const resolvers = {
FROM "Withdrawl" FROM "Withdrawl"
WHERE "userId" = ${me.id} WHERE "userId" = ${me.id}
AND id = ${Number(id)} AND id = ${Number(id)}
AND now() > created_at + interval '${retention}' AND now() > created_at + ${retention}::INTERVAL
AND hash IS NOT NULL AND hash IS NOT NULL
AND status IS NOT NULL AND status IS NOT NULL
), updated_rows AS ( ), updated_rows AS (
UPDATE "Withdrawl" UPDATE "Withdrawl"
SET hash = NULL, bolt11 = NULL SET hash = NULL, bolt11 = NULL, preimage = NULL
FROM to_be_updated FROM to_be_updated
WHERE "Withdrawl".id = to_be_updated.id) WHERE "Withdrawl".id = to_be_updated.id)
SELECT * FROM to_be_updated;` SELECT * FROM to_be_updated;`
@ -499,7 +499,7 @@ const resolvers = {
console.error(error) console.error(error)
await models.withdrawl.update({ await models.withdrawl.update({
where: { id: invoice.id }, where: { id: invoice.id },
data: { hash: invoice.hash, bolt11: invoice.bolt11 } data: { hash: invoice.hash, bolt11: invoice.bolt11, preimage: invoice.preimage }
}) })
throw new GqlInputError('failed to drop bolt11 from lnd') throw new GqlInputError('failed to drop bolt11 from lnd')
} }

View File

@ -12,10 +12,7 @@ import useIndexedDB from './use-indexeddb'
import { SSR } from '@/lib/constants' import { SSR } from '@/lib/constants'
export function WalletLogs ({ wallet, embedded }) { export function WalletLogs ({ wallet, embedded }) {
const { logs, setLogs, hasMore, loadMore, loadLogs, loading } = useWalletLogs(wallet) const { logs, setLogs, hasMore, loadMore, loading } = useWalletLogs(wallet)
useEffect(() => {
loadLogs()
}, [loadLogs])
const showModal = useShowModal() const showModal = useShowModal()
@ -46,7 +43,7 @@ export function WalletLogs ({ wallet, embedded }) {
? <div className='w-100 text-center'>loading...</div> ? <div className='w-100 text-center'>loading...</div>
: logs.length === 0 && <div className='w-100 text-center'>empty</div>} : logs.length === 0 && <div className='w-100 text-center'>empty</div>}
{hasMore {hasMore
? <Button onClick={loadMore} size='sm' className='mt-3'>Load More</Button> ? <div className='w-100 text-center'><Button onClick={loadMore} size='sm' className='mt-3'>more</Button></div>
: <div className='w-100 text-center'>------ start of logs ------</div>} : <div className='w-100 text-center'>------ start of logs ------</div>}
</div> </div>
</> </>
@ -228,7 +225,7 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
const loadMore = useCallback(async () => { const loadMore = useCallback(async () => {
if (hasMore) { if (hasMore) {
setLoading(true) setLoading(true)
const result = await loadLogsPage(page, logsPerPage, wallet) const result = await loadLogsPage(page + 1, logsPerPage, wallet)
setLogs(prevLogs => [...prevLogs, ...result.data]) setLogs(prevLogs => [...prevLogs, ...result.data])
setHasMore(result.hasMore) setHasMore(result.hasMore)
setTotal(result.total) setTotal(result.total)
@ -247,5 +244,9 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
setLoading(false) setLoading(false)
}, [wallet, loadLogsPage]) }, [wallet, loadLogsPage])
useEffect(() => {
loadLogs()
}, [wallet])
return { logs, hasMore, total, loadMore, loadLogs, setLogs, loading } return { logs, hasMore, total, loadMore, loadLogs, setLogs, loading }
} }

View File

@ -1,4 +1,4 @@
FROM polarlightning/lnd:0.17.5-beta FROM polarlightning/lnd:0.18.0-beta
ARG LN_NODE_FOR ARG LN_NODE_FOR
ENV LN_NODE_FOR=$LN_NODE_FOR ENV LN_NODE_FOR=$LN_NODE_FOR

View File

@ -726,7 +726,8 @@ export const lnbitsSchema = object().shape({
test: invoiceKey => adminKey !== invoiceKey, test: invoiceKey => adminKey !== invoiceKey,
message: 'invoice key cannot be the same as admin key' message: 'invoice key cannot be the same as admin key'
}) })
}) }),
...autowithdrawSchemaMembers
// need to set order to avoid cyclic dependencies in Yup schema // need to set order to avoid cyclic dependencies in Yup schema
// see https://github.com/jquense/yup/issues/176#issuecomment-367352042 // see https://github.com/jquense/yup/issues/176#issuecomment-367352042
}, ['adminKey', 'invoiceKey']) }, ['adminKey', 'invoiceKey'])
@ -745,7 +746,8 @@ export const nwcSchema = object().shape({
test: nwcUrlRecv => nwcUrlRecv !== nwcUrl, test: nwcUrlRecv => nwcUrlRecv !== nwcUrl,
message: 'connection for receiving cannot be the same as for sending' message: 'connection for receiving cannot be the same as for sending'
}) })
}) }),
...autowithdrawSchemaMembers
}, ['nwcUrl', 'nwcUrlRecv']) }, ['nwcUrl', 'nwcUrlRecv'])
export const blinkSchema = object({ export const blinkSchema = object({
@ -796,7 +798,8 @@ export const phoenixdSchema = object().shape({
test: secondary => primary !== secondary, test: secondary => primary !== secondary,
message: 'secondary password cannot be the same as primary password' message: 'secondary password cannot be the same as primary password'
}) })
}) }),
...autowithdrawSchemaMembers
}, ['primaryPassword', 'secondaryPassword']) }, ['primaryPassword', 'secondaryPassword'])
export const bioSchema = object({ export const bioSchema = object({

View File

@ -125,7 +125,8 @@ function extractConfig (fields, config, client) {
const field = fields.find(({ name }) => name === key) const field = fields.find(({ name }) => name === key)
// filter server config which isn't specified as wallet fields // filter server config which isn't specified as wallet fields
if (client && (key.startsWith('autoWithdraw') || key === 'id')) return acc // (we allow autowithdraw members to pass validation)
if (client && key === 'id') return acc
// field might not exist because config.enabled doesn't map to a wallet field // field might not exist because config.enabled doesn't map to a wallet field
if (!field || (client ? isClientField(field) : isServerField(field))) { if (!field || (client ? isClientField(field) : isServerField(field))) {
@ -198,6 +199,9 @@ function useConfig (wallet) {
if (transformedConfig) { if (transformedConfig) {
newClientConfig = Object.assign(newClientConfig, transformedConfig) newClientConfig = Object.assign(newClientConfig, transformedConfig)
} }
// these are stored on the server
delete newClientConfig.autoWithdrawMaxFeePercent
delete newClientConfig.autoWithdrawMaxFeeTotal
} catch { } catch {
valid = false valid = false
} }

View File

@ -36,7 +36,7 @@ export default async function wrapInvoice (bolt11, { msats, description, descrip
throw new Error('Unable to decode invoice') throw new Error('Unable to decode invoice')
} }
console.log('invoice', inv.mtokens, inv.expires_at, inv.cltv_delta) console.log('invoice', inv.id, inv.mtokens, inv.expires_at, inv.cltv_delta, inv.destination)
// validate outgoing amount // validate outgoing amount
if (inv.mtokens) { if (inv.mtokens) {
@ -77,6 +77,8 @@ export default async function wrapInvoice (bolt11, { msats, description, descrip
case 49: case 49:
case 149: // trampoline routing case 149: // trampoline routing
case 151: // electrum trampoline routing case 151: // electrum trampoline routing
case 262:
case 263: // blinded paths
break break
default: default:
throw new Error(`Unsupported feature bit: ${f.bit}`) throw new Error(`Unsupported feature bit: ${f.bit}`)

View File

@ -346,12 +346,12 @@ export async function autoDropBolt11s ({ models, lnd }) {
SELECT id, hash, bolt11 SELECT id, hash, bolt11
FROM "Withdrawl" FROM "Withdrawl"
WHERE "userId" IN (SELECT id FROM users WHERE "autoDropBolt11s") WHERE "userId" IN (SELECT id FROM users WHERE "autoDropBolt11s")
AND now() > created_at + interval '${retention}' AND now() > created_at + ${retention}::INTERVAL
AND hash IS NOT NULL AND hash IS NOT NULL
AND status IS NOT NULL AND status IS NOT NULL
), updated_rows AS ( ), updated_rows AS (
UPDATE "Withdrawl" UPDATE "Withdrawl"
SET hash = NULL, bolt11 = NULL SET hash = NULL, bolt11 = NULL, preimage = NULL
FROM to_be_updated FROM to_be_updated
WHERE "Withdrawl".id = to_be_updated.id) WHERE "Withdrawl".id = to_be_updated.id)
SELECT * FROM to_be_updated;` SELECT * FROM to_be_updated;`
@ -364,7 +364,7 @@ export async function autoDropBolt11s ({ models, lnd }) {
console.error(`Error removing invoice with hash ${invoice.hash}:`, error) console.error(`Error removing invoice with hash ${invoice.hash}:`, error)
await models.withdrawl.update({ await models.withdrawl.update({
where: { id: invoice.id }, where: { id: invoice.id },
data: { hash: invoice.hash, bolt11: invoice.bolt11 } data: { hash: invoice.hash, bolt11: invoice.bolt11, preimage: invoice.preimage }
}) })
} }
} }