Skip to content

Commit

Permalink
Embedded LND: coin control endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Mar 25, 2024
1 parent 903f629 commit f712f97
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 8 deletions.
29 changes: 23 additions & 6 deletions backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ const {
closeChannel,
openChannel
} = lndMobile.channel;
const { signMessageNodePubkey, verifyMessageNodePubkey, bumpFee } =
lndMobile.wallet;
const {
signMessageNodePubkey,
verifyMessageNodePubkey,
bumpFee,
fundPsbt,
finalizePsbt,
publishTransaction
} = lndMobile.wallet;
const { walletBalance, newAddress, getTransactions, sendCoins } =
lndMobile.onchain;

Expand Down Expand Up @@ -146,10 +152,21 @@ export default class EmbeddedLND extends LND {
urlParams && (await queryRoutes(urlParams[0], urlParams[1]));
// getForwardingHistory = () => N/A
// // Coin Control
// fundPsbt = (data: any) => this.postRequest('/v2/wallet/psbt/fund', data);
// finalizePsbt = (data: any) =>
// this.postRequest('/v2/wallet/psbt/finalize', data);
// publishTransaction = (data: any) => this.postRequest('/v2/wallet/tx', data);
fundPsbt = async (data: any) =>
await fundPsbt({
raw: data.raw,
spend_unconfirmed: data.spend_unconfirmed,
sat_per_vbyte: data.sat_per_vbyte
});
finalizePsbt = async (data: any) =>
await finalizePsbt({
funded_psbt: data.funded_psbt
});
publishTransaction = async (data: any) =>
await publishTransaction({
tx_hex: data.tx_hex
});

getUTXOs = async () => await listUnspent();
bumpFee = async (data: any) => await bumpFee(data);
lookupInvoice = async (data: any) => await lookupInvoice(data.r_hash);
Expand Down
29 changes: 27 additions & 2 deletions lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ import {
verifyMessageNodePubkey,
signMessage,
signMessageNodePubkey,
bumpFee
bumpFee,
fundPsbt,
finalizePsbt,
publishTransaction
} from './wallet';
import { status, modifyStatus, queryScores, setScores } from './autopilot';
import { checkScheduledSyncWorkStatus } from './scheduled-sync'; // TODO(hsjoberg): This could be its own injection "LndMobileScheduledSync"
Expand Down Expand Up @@ -331,6 +334,25 @@ export interface ILndMobileInjections {
force?: boolean;
sat_per_vbyte?: Long;
}) => Promise<walletrpc.BumpFeeResponse>;
fundPsbt: ({
raw,
spend_unconfirmed,
sat_per_vbyte
}: {
raw: walletrpc.TxTemplate;
spend_unconfirmed?: boolean;
sat_per_vbyte?: Long;
}) => Promise<walletrpc.FundPsbtResponse>;
finalizePsbt: ({
funded_psbt
}: {
funded_psbt: Uint8Array;
}) => Promise<walletrpc.FinalizePsbtResponse>;
publishTransaction: ({
tx_hex
}: {
tx_hex: Uint8Array;
}) => Promise<walletrpc.PublishResponse>;
};
autopilot: {
status: () => Promise<autopilotrpc.StatusResponse>;
Expand Down Expand Up @@ -421,7 +443,10 @@ export default {
verifyMessageNodePubkey,
signMessage,
signMessageNodePubkey,
bumpFee
bumpFee,
fundPsbt,
finalizePsbt,
publishTransaction
},
autopilot: {
status,
Expand Down
78 changes: 78 additions & 0 deletions lndmobile/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,84 @@ export const bumpFee = async ({
return response;
};

/**
* @throws
*/
export const fundPsbt = async ({
raw,
spend_unconfirmed,
sat_per_vbyte
}: {
raw: walletrpc.TxTemplate;
spend_unconfirmed?: boolean;
sat_per_vbyte?: Long;
}): Promise<walletrpc.FundPsbtResponse> => {
const options: walletrpc.IFundPsbtRequest = {
raw,
spend_unconfirmed,
sat_per_vbyte
};
const response = await sendCommand<
walletrpc.IFundPsbtRequest,
walletrpc.FundPsbtRequest,
walletrpc.FundPsbtResponse
>({
request: walletrpc.FundPsbtRequest,
response: walletrpc.FundPsbtResponse,
method: 'FundPsbt',
options
});
return response;
};

/**
* @throws
*/
export const finalizePsbt = async ({
funded_psbt
}: {
funded_psbt: Uint8Array;
}): Promise<walletrpc.FinalizePsbtResponse> => {
const options: walletrpc.IFinalizePsbtRequest = {
funded_psbt
};
const response = await sendCommand<
walletrpc.IFinalizePsbtRequest,
walletrpc.FinalizePsbtRequest,
walletrpc.FinalizePsbtResponse
>({
request: walletrpc.FinalizePsbtRequest,
response: walletrpc.FinalizePsbtResponse,
method: 'FinalizePsbt',
options
});
return response;
};

/**
* @throws
*/
export const publishTransaction = async ({
tx_hex
}: {
tx_hex: Uint8Array;
}): Promise<walletrpc.PublishResponse> => {
const options: walletrpc.ITransaction = {
tx_hex
};
const response = await sendCommand<
walletrpc.ITransaction,
walletrpc.Transaction,
walletrpc.PublishResponse
>({
request: walletrpc.Transaction,
response: walletrpc.PublishResponse,
method: 'PublishTransaction',
options
});
return response;
};

// Base wallet

/**
Expand Down

0 comments on commit f712f97

Please sign in to comment.