Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
4e06e8d
chore: git move
motorina0 Apr 10, 2024
7168af8
chore: bring certs
motorina0 Apr 10, 2024
727d40d
refactor: make interface uniform
motorina0 Apr 10, 2024
4cfb9e7
feat: skip by funding source
motorina0 Apr 10, 2024
056e05a
chore: code format
motorina0 Apr 10, 2024
e9855fd
refactor: add more logs
motorina0 Apr 10, 2024
2931ba7
chore: fix `make check`
motorina0 Apr 10, 2024
d0a4c3c
chore: file renaming
motorina0 Apr 11, 2024
83a049d
chore: add `pytest_mock` test lib
motorina0 Apr 11, 2024
f103e65
refactor: extract `tests/wallets/helpers.py`
motorina0 Apr 11, 2024
6b8bd88
refactor: re-order stuff
motorina0 Apr 11, 2024
37b0622
refactor: extract more into `helpers.py`
motorina0 Apr 11, 2024
b79343d
refactor: extract `check_assertions`
motorina0 Apr 11, 2024
2e2fe16
refactor: move files
motorina0 Apr 11, 2024
5b7e1bc
refactor: move more logic to models
motorina0 Apr 11, 2024
59b0e3a
chore: add the `mock` dev dependency
motorina0 Apr 11, 2024
5d5c802
Revert "chore: add the `mock` dev dependency"
motorina0 Apr 11, 2024
a65052c
chore: add dev dependency `types-mock`
motorina0 Apr 11, 2024
618b4ef
chore: add dev dependency `mock`
motorina0 Apr 12, 2024
63b4691
test: add first `lndgrpc` test
motorina0 Apr 12, 2024
5eb85a9
test: add `create_invoice` test
motorina0 Apr 12, 2024
bb089de
test: add error for `create_invoice`
motorina0 Apr 12, 2024
7eee7d1
feat: improve mocking
motorina0 Apr 12, 2024
fef7f51
feat: handle multiple spy and nested functions (first draft)
motorina0 Apr 15, 2024
4c48666
refactor: extra logs
motorina0 Apr 15, 2024
a949a58
chore: stupid tests
motorina0 Apr 17, 2024
7385f96
chore: rebase fix
motorina0 Apr 17, 2024
3c505d4
fix: rebase errors
motorina0 Apr 17, 2024
afee2a5
chore: code format
motorina0 Apr 17, 2024
3c2eb35
fix: rebase stuff
motorina0 Apr 17, 2024
d361608
fix: format
motorina0 Apr 17, 2024
c2a5459
fix: small rebase
motorina0 Apr 17, 2024
4e733d9
fix: rebase
motorina0 Apr 17, 2024
2d2f71c
chore: remove temp files
motorina0 Apr 17, 2024
f0b62f1
chore: code formatting
motorina0 Apr 17, 2024
f689bda
fix: test name
motorina0 Apr 17, 2024
3493a02
fix: empty mock
motorina0 Apr 17, 2024
d2dd83c
fix: test description
motorina0 Apr 17, 2024
784b21c
test: add `two HTLCs` test
motorina0 Apr 17, 2024
1300efb
chore: name test
motorina0 Apr 18, 2024
2819e1f
feat: add more test error
motorina0 Apr 18, 2024
b2c1a47
test: add error test
motorina0 Apr 18, 2024
c38d2ae
test: add
motorina0 Apr 18, 2024
74cc464
test: add pending
motorina0 Apr 18, 2024
47f4b37
test: add RPC error
motorina0 Apr 18, 2024
949562a
test: add rpc error and refactor `get_invoice_status`
motorina0 Apr 18, 2024
e9097b3
test: bad checking_id
motorina0 Apr 18, 2024
cd7c494
chore: description update
motorina0 Apr 18, 2024
81aa8bb
fix: nested objects
motorina0 Apr 19, 2024
1df8c7a
test: async generator
motorina0 Apr 19, 2024
51d6035
fix: make check
motorina0 Apr 19, 2024
52f1f87
test: pending
motorina0 Apr 19, 2024
4ebb437
tests: more pending
motorina0 Apr 19, 2024
ca615a7
test: add failed
motorina0 Apr 19, 2024
acc9e73
test: add failure test
motorina0 Apr 19, 2024
4bfaa45
test: success
motorina0 Apr 19, 2024
8c4aa8b
chore: code format
motorina0 Apr 19, 2024
0e0cc44
test: incorrect checking_id
motorina0 Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions lnbits/wallets/lndgrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def status(self) -> StatusResponse:
try:
resp = await self.rpc.ChannelBalance(ln.ChannelBalanceRequest())
except Exception as exc:
return StatusResponse(str(exc), 0)
return StatusResponse(f"Unable to connect, got: '{exc}'", 0)

return StatusResponse(None, resp.balance * 1000)

Expand Down Expand Up @@ -147,6 +147,7 @@ async def create_invoice(
req = ln.Invoice(**data)
resp = await self.rpc.AddInvoice(req)
except Exception as exc:
logger.warning(exc)
error_message = str(exc)
return InvoiceResponse(False, None, None, error_message)

Expand All @@ -165,6 +166,7 @@ async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse
try:
resp = await self.routerpc.SendPaymentV2(req).read()
except Exception as exc:
logger.warning(exc)
return PaymentResponse(False, None, None, None, str(exc))

# PaymentStatus from https://github.com/lightningnetwork/lnd/blob/master/channeldb/payments.go#L178
Expand All @@ -176,12 +178,12 @@ async def pay_invoice(self, bolt11: str, fee_limit_msat: int) -> PaymentResponse
}

failure_reasons = {
0: "No error given.",
1: "Payment timed out.",
2: "No route to destination.",
3: "Error.",
4: "Incorrect payment details.",
5: "Insufficient balance.",
0: "Payment failed: No error given.",
1: "Payment failed: Payment timed out.",
2: "Payment failed: No route to destination.",
3: "Payment failed: Error.",
4: "Payment failed: Incorrect payment details.",
5: "Payment failed: Insufficient balance.",
}

fee_msat = None
Expand All @@ -204,19 +206,23 @@ async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
try:
r_hash = hex_to_bytes(checking_id)
if len(r_hash) != 32:
# this may happen if we switch between backend wallets
# that use different checking_id formats
raise ValueError
except ValueError:
# this may happen if we switch between backend wallets
# that use different checking_id formats
return PaymentPendingStatus()
try:

resp = await self.rpc.LookupInvoice(ln.PaymentHash(r_hash=r_hash))
except grpc.RpcError:
return PaymentPendingStatus()
if resp.settled:
return PaymentSuccessStatus()

return PaymentPendingStatus()
# todo: where is the FAILED status
if resp.settled:
return PaymentSuccessStatus()

return PaymentPendingStatus()
except grpc.RpcError as exc:
logger.warning(exc)
return PaymentPendingStatus()
except Exception as exc:
logger.warning(exc)
return PaymentPendingStatus()

async def get_payment_status(self, checking_id: str) -> PaymentStatus:
"""
Expand All @@ -231,10 +237,6 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
# that use different checking_id formats
return PaymentPendingStatus()

resp = self.routerpc.TrackPaymentV2(
router.TrackPaymentRequest(payment_hash=r_hash)
)

# # HTLCAttempt.HTLCStatus:
# # https://github.com/lightningnetwork/lnd/blob/master/lnrpc/lightning.proto#L3641
# htlc_statuses = {
Expand All @@ -250,6 +252,9 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
}

try:
resp = self.routerpc.TrackPaymentV2(
router.TrackPaymentRequest(payment_hash=r_hash)
)
async for payment in resp:
if len(payment.htlcs) and statuses[payment.status]:
return PaymentSuccessStatus(
Expand Down
Loading