Skip to content

Commit 82e06db

Browse files
committed
feat(): send lightning payment after pending approval
Add handling to submit lightning payments after they are approved in the pending approval flow. For lightning transactions, we need to send the payment request after approval rather than recreating and signing like other TSS transactions. Ticket: BTC-1898 TICKET: BTC-1898
1 parent ba93a73 commit 82e06db

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

modules/sdk-core/src/bitgo/pendingApproval/pendingApproval.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
State,
1515
Type,
1616
} from '../pendingApproval';
17-
import { RequestTracer } from '../utils';
17+
import { RequestTracer, RequestType } from '../utils';
1818
import { IWallet } from '../wallet';
1919
import { BuildParams } from '../wallet/BuildParams';
2020
import { IRequestTracer } from '../../api';
@@ -23,6 +23,8 @@ import EddsaUtils from '../utils/tss/eddsa';
2323
import { EcdsaMPCv2Utils, EcdsaUtils } from '../utils/tss/ecdsa';
2424
import { KeyShare as EcdsaKeyShare } from '../utils/tss/ecdsa/types';
2525
import { KeyShare as EddsaKeyShare } from '../utils/tss/eddsa/types';
26+
import { sendTxRequest } from '../tss/common';
27+
import assert from 'assert';
2628

2729
type PreApproveResult = {
2830
txHex: string;
@@ -341,10 +343,17 @@ export class PendingApproval implements IPendingApproval {
341343
*
342344
* Therefore, if neither of these is true, the transaction cannot be recreated, which is reflected in the if
343345
* statement below.
346+
*
347+
* Lightning transactions cannot be recreated.
344348
*/
345349
private canRecreateTransaction(params: ApproveOptions): boolean {
346350
const isColdWallet = !!_.get(this.wallet, '_wallet.isCold');
347351
const isOFCWallet = this.baseCoin.getFamily() === 'ofc'; // Off-chain transactions don't need to be rebuilt
352+
const isLightningWallet = this.baseCoin.getFamily() === 'lnbtc';
353+
if (isLightningWallet) {
354+
return false;
355+
}
356+
348357
if (!params.xprv && !(params.walletPassphrase && !isColdWallet && !isOFCWallet)) {
349358
return false;
350359
}
@@ -420,13 +429,22 @@ export class PendingApproval implements IPendingApproval {
420429
private async postApprove(params: ApproveOptions = {}, reqId: IRequestTracer): Promise<void> {
421430
switch (this.type()) {
422431
case Type.TRANSACTION_REQUEST_FULL:
423-
// TransactionRequestFull for SMH or SMC wallets can only be signed after pending approval is approved
424-
if (
425-
this._pendingApproval.state === State.APPROVED &&
426-
this.canRecreateTransaction(params) &&
427-
this.baseCoin.supportsTss()
428-
) {
429-
await this.recreateAndSignTSSTransaction(params, reqId);
432+
if (this._pendingApproval.state === State.APPROVED) {
433+
// After we approve a lightning transaction, we should proceed with submitting the payment
434+
if (this.baseCoin.getFamily() === 'lnbtc') {
435+
assert(this._pendingApproval.txRequestId, 'Missing txRequestId');
436+
// this.populateWallet is called before this so we should be good here
437+
assert(this.wallet?.id(), 'Missing wallet id');
438+
await sendTxRequest(
439+
this.bitgo,
440+
this.wallet?.id() as string,
441+
this._pendingApproval.txRequestId,
442+
RequestType.tx,
443+
reqId
444+
);
445+
} else if (this.canRecreateTransaction(params) && this.baseCoin.supportsTss()) {
446+
await this.recreateAndSignTSSTransaction(params, reqId);
447+
}
430448
}
431449
}
432450
}

0 commit comments

Comments
 (0)