Skip to content

Commit 8666309

Browse files
committed
feat: added withdrawStatus in response lightning
TICKET: BTC-2234
1 parent 90289c5 commit 8666309

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

modules/abstract-lightning/src/codecs/api/withdraw.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { LightningOnchainRecipient } from '@bitgo/public-types';
33
import { PendingApprovalData, TxRequestState } from '@bitgo/sdk-core';
44
import { BigIntFromString } from 'io-ts-types';
55

6-
// todo:(current) which to keep here which to take to common types
6+
export const WithdrawStatusDelivered = 'delivered';
7+
export const WithdrawStatusFailed = 'failed';
8+
9+
export const WithdrawStatus = t.union([t.literal(WithdrawStatusDelivered), t.literal(WithdrawStatusFailed)]);
10+
711
export const LightningOnchainWithdrawParams = t.type({
812
recipients: t.array(LightningOnchainRecipient),
913
satsPerVbyte: BigIntFromString,
@@ -13,6 +17,20 @@ export const LightningOnchainWithdrawParams = t.type({
1317

1418
export type LightningOnchainWithdrawParams = t.TypeOf<typeof LightningOnchainWithdrawParams>;
1519

20+
export const LndCreateWithdrawResponse = t.intersection(
21+
[
22+
t.type({
23+
status: WithdrawStatus,
24+
}),
25+
t.partial({
26+
txid: t.string,
27+
failureReason: t.string,
28+
}),
29+
],
30+
'LndCreateWithdrawResponse'
31+
);
32+
export type LndCreateWithdrawResponse = t.TypeOf<typeof LndCreateWithdrawResponse>;
33+
1634
export type LightningOnchainWithdrawResponse = {
1735
/**
1836
* Unique identifier for withdraw request submitted to BitGo.
@@ -32,6 +50,14 @@ export type LightningOnchainWithdrawResponse = {
3250
*/
3351
pendingApproval?: PendingApprovalData;
3452

53+
/**
54+
* Current snapshot of withdraw status (if available).
55+
* - **`'delivered'`**: Withdraw request is delivered to the blockchain.
56+
* - **`'failed'`**: Withdraw failed.
57+
* This field is absent if approval is required before processing.
58+
*/
59+
withdrawStatus?: LndCreateWithdrawResponse;
60+
3561
/**
3662
* Latest transfer details for this withdraw request (if available).
3763
* - Provides the current state of the transfer.
@@ -77,10 +103,16 @@ export const SendPsbtRequest = t.type(
77103
);
78104
export type SendPsbtRequest = t.TypeOf<typeof SendPsbtRequest>;
79105

80-
export const SendPsbtResponse = t.type(
81-
{
82-
label: t.string,
83-
},
106+
export const SendPsbtResponse = t.intersection(
107+
[
108+
t.type({
109+
label: t.string,
110+
}),
111+
t.partial({
112+
status: WithdrawStatus,
113+
failureReason: t.string,
114+
}),
115+
],
84116
'SendPsbtResponse'
85117
);
86118
export type SendPsbtResponse = t.TypeOf<typeof SendPsbtResponse>;

modules/abstract-lightning/src/wallet/lightning.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
LightningOnchainWithdrawResponse,
2828
ListInvoicesResponse,
2929
ListPaymentsResponse,
30+
LndCreateWithdrawResponse,
3031
} from '../codecs';
3132
import { LightningPaymentIntent, LightningPaymentRequest } from '@bitgo/public-types';
3233

@@ -377,6 +378,7 @@ export class LightningWallet implements ILightningWallet {
377378
reqId
378379
);
379380

381+
const coinSpecific = transactionRequestSend.transactions?.[0]?.unsignedTx?.coinSpecific;
380382
let updatedTransfer: any = undefined;
381383
try {
382384
updatedTransfer = await this.wallet.getTransfer({ id: transfer.id });
@@ -390,6 +392,10 @@ export class LightningWallet implements ILightningWallet {
390392
txRequestId: transactionRequestCreate.txRequestId,
391393
txRequestState: transactionRequestSend.state,
392394
transfer: updatedTransfer,
395+
withdrawStatus:
396+
coinSpecific && 'status' in coinSpecific
397+
? t.exact(LndCreateWithdrawResponse).encode(coinSpecific as LndCreateWithdrawResponse)
398+
: undefined,
393399
};
394400
}
395401

modules/bitgo/test/v2/unit/lightning/lightningWallets.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,19 @@ describe('Lightning wallets', function () {
828828
state: 'pendingDelivery',
829829
};
830830

831-
const finalPaymentResponse = {
831+
const finalWithdrawResponse = {
832832
txRequestId: 'txReq123',
833833
state: 'delivered',
834+
transactions: [
835+
{
836+
unsignedTx: {
837+
coinSpecific: {
838+
status: 'delivered',
839+
txid: 'tx123',
840+
},
841+
},
842+
},
843+
],
834844
};
835845

836846
const transferResponse = {
@@ -931,7 +941,7 @@ describe('Lightning wallets', function () {
931941

932942
const sendTxRequestNock = nock(bgUrl)
933943
.post(`/api/v2/wallet/${wallet.wallet.id()}/txrequests/${txRequestResponse.txRequestId}/transactions/0/send`)
934-
.reply(200, finalPaymentResponse);
944+
.reply(200, finalWithdrawResponse);
935945

936946
const getTransferNock = nock(bgUrl)
937947
.get(`/api/v2/${coinName}/wallet/${wallet.wallet.id()}/transfer/${transferResponse.id}`)
@@ -940,6 +950,8 @@ describe('Lightning wallets', function () {
940950
const response = await wallet.withdrawOnchain(params);
941951
assert.strictEqual(response.txRequestId, 'txReq123');
942952
assert.strictEqual(response.txRequestState, 'delivered');
953+
assert.strictEqual(response.withdrawStatus?.status, 'delivered');
954+
assert.strictEqual(response.withdrawStatus?.txid, 'tx123');
943955
assert.deepStrictEqual(response.transfer, updatedTransferResponse);
944956

945957
createTxRequestNock.done();

modules/express/test/unit/lightning/lightningWithdrawRoutes.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as sinon from 'sinon';
22
import * as should from 'should';
33
import * as express from 'express';
4-
import { PayInvoiceResponse } from '@bitgo/abstract-lightning';
4+
import { LightningOnchainWithdrawResponse } from '@bitgo/abstract-lightning';
55
import { BitGo } from 'bitgo';
66
import { handleLightningWithdraw } from '../../../src/lightning/lightningWithdrawRoutes';
77

@@ -34,9 +34,13 @@ describe('Lightning Withdraw Routes', () => {
3434
satsPerVbyte: '15',
3535
};
3636

37-
const expectedResponse: PayInvoiceResponse = {
37+
const expectedResponse: LightningOnchainWithdrawResponse = {
3838
txRequestState: 'delivered',
3939
txRequestId: '123',
40+
withdrawStatus: {
41+
status: 'delivered',
42+
txid: 'tx123',
43+
},
4044
};
4145

4246
const onchainWithdrawStub = sinon.stub().resolves(expectedResponse);

0 commit comments

Comments
 (0)