From 5c9d64647ed54879892695974281a17132827e99 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Wed, 23 Feb 2022 11:08:36 -0500 Subject: [PATCH] Add PSBT functions for LND (#4124) --- .../org/bitcoins/lnd/rpc/LndRpcClient.scala | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala b/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala index 0279b9adf5..aa52dd9ff2 100644 --- a/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala +++ b/lnd-rpc/src/main/scala/org/bitcoins/lnd/rpc/LndRpcClient.scala @@ -36,6 +36,8 @@ import org.bitcoins.lnd.rpc.LndUtils._ import org.bitcoins.lnd.rpc.config._ import scodec.bits._ import signrpc._ +import walletrpc.FundPsbtRequest.Fees.SatPerVbyte +import walletrpc.FundPsbtRequest.Template.Psbt import walletrpc.{ AddressType => _, ListUnspentRequest => _, @@ -562,6 +564,48 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)( .map(res => Tx(res.rawTx)) } + def fundPSBT( + psbt: PSBT, + feeRate: SatoshisPerVirtualByte, + spendUnconfirmed: Boolean): Future[PSBT] = { + val template = Psbt(psbt.bytes) + val fees = SatPerVbyte(feeRate.toLong) + val request = FundPsbtRequest(template = template, + fees = fees, + spendUnconfirmed = spendUnconfirmed) + + fundPSBT(request) + } + + def fundPSBT(psbt: PSBT, feeRate: SatoshisPerVirtualByte): Future[PSBT] = { + val template = Psbt(psbt.bytes) + val fees = SatPerVbyte(feeRate.toLong) + val request = FundPsbtRequest(template, fees) + + fundPSBT(request) + } + + def fundPSBT(request: FundPsbtRequest): Future[PSBT] = { + logger.trace("lnd calling fundpsbt") + + wallet + .fundPsbt(request) + .map(res => PSBT(res.fundedPsbt)) + } + + def signPSBT(psbt: PSBT): Future[PSBT] = { + val request = SignPsbtRequest(psbt.bytes) + signPSBT(request) + } + + def signPSBT(request: SignPsbtRequest): Future[PSBT] = { + logger.trace("lnd calling signpsbt") + + wallet + .signPsbt(request) + .map(res => PSBT(res.signedPsbt)) + } + def finalizePSBT(psbt: PSBT): Future[PSBT] = { val request = FinalizePsbtRequest(psbt.bytes)