Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.

Commit 44836f9

Browse files
authored
Merge pull request #41 from losh11/patch-3
feat: add lnd api SendCoins
2 parents 848cbbe + 6952824 commit 44836f9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/lnd.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,55 @@ class LND {
898898
return err(e);
899899
}
900900
}
901+
902+
/**
903+
* LND SendCoins
904+
* Send onchain transaction to a single output
905+
* @param address
906+
* @param amount
907+
* @param targetConf
908+
* @param feeRate
909+
* @param sendAll
910+
* @param label
911+
* @returns {Promise<Ok<lnrpc.SendCoinsResponse> | Err<unknown>>}
912+
*/
913+
async sendCoins(
914+
address: string,
915+
amount: number,
916+
targetConf?: number,
917+
feeRate?: number,
918+
sendAll?: boolean,
919+
label?: string
920+
): Promise<Result<lnrpc.SendCoinsResponse>> {
921+
try {
922+
const message = lnrpc.SendCoinsRequest.create();
923+
924+
message.addr = address;
925+
message.amount = amount;
926+
927+
if (targetConf) {
928+
message.targetConf = targetConf;
929+
}
930+
if (feeRate) {
931+
message.satPerVbyte = feeRate;
932+
}
933+
if (sendAll) {
934+
message.sendAll = sendAll;
935+
}
936+
if (label) {
937+
message.label = label;
938+
}
939+
940+
const serializedResponse = await this.grpc.sendCommand(
941+
EGrpcSyncMethods.SendCoins,
942+
lnrpc.SendCoinsRequest.encode(message).finish()
943+
);
944+
945+
return ok(lnrpc.SendCoinsResponse.decode(serializedResponse));
946+
} catch (e) {
947+
return err(e);
948+
}
949+
}
901950
}
902951

903952
export default new LND();

0 commit comments

Comments
 (0)