Skip to content

Commit

Permalink
feat: get paystatus from mpay plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Aug 24, 2024
1 parent b283e37 commit 5bc07c7
Show file tree
Hide file tree
Showing 14 changed files with 2,342 additions and 16 deletions.
21 changes: 20 additions & 1 deletion lib/lightning/cln/ClnClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ListfundsOutputs, ListpaysPays } from '../../proto/cln/node_pb';
import * as primitivesrpc from '../../proto/cln/primitives_pb';
import { HoldClient } from '../../proto/hold/hold_grpc_pb';
import * as holdrpc from '../../proto/hold/hold_pb';
import * as mpayrpc from '../../proto/mpay/mpay_pb';
import { WalletBalance } from '../../wallet/providers/WalletProviderInterface';
import { msatToSat, satToMsat, scidClnToLnd } from '../ChannelUtils';
import Errors from '../Errors';
Expand Down Expand Up @@ -720,7 +721,25 @@ class ClnClient
};
}

// TODO: find a way to check "paystatus"
// ... has failed...
if (this.mpay !== undefined) {
for (const payStatus of (await this.mpay.payStatus(invoice)).statusList) {
for (const attempt of payStatus.attemptsList) {
if (
attempt.state ===
mpayrpc.PayStatusResponse.PayStatus.Attempt.AttemptState
.ATTEMPT_PENDING ||
attempt.failure === undefined
) {
continue;
}

if (ClnClient.errIsIncorrectPaymentDetails(attempt.failure.message)) {
throw attempt.failure.message;
}
}
}
}

// ... or is still pending
const hasPendingPayments = pays.some(
Expand Down
10 changes: 10 additions & 0 deletions lib/lightning/cln/MpayClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ class Mpay extends BaseClient {
public getInfo = (): Promise<mpayrpc.GetInfoResponse.AsObject> =>
this.unaryNodeCall('getInfo', new mpayrpc.GetInfoRequest());

public payStatus = (invoice: string) => {
const req = new mpayrpc.PayStatusRequest();
req.setBolt11(invoice);

return this.unaryNodeCall<
mpayrpc.PayStatusRequest,
mpayrpc.PayStatusResponse.AsObject
>('payStatus', req);
};

public sendPayment = async (
invoice: string,
maxFeeMsat: number,
Expand Down
17 changes: 17 additions & 0 deletions lib/proto/mpay/mpay_grpc_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions lib/proto/mpay/mpay_grpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

224 changes: 224 additions & 0 deletions lib/proto/mpay/mpay_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5bc07c7

Please sign in to comment.