@@ -1600,6 +1600,24 @@ func (w *WalletKit) FundPsbt(_ context.Context,
1600
1600
account = req .Account
1601
1601
}
1602
1602
1603
+ var customLockID * wtxmgr.LockID
1604
+ if len (req .CustomLockId ) > 0 {
1605
+ lockID := wtxmgr.LockID {}
1606
+ if len (req .CustomLockId ) != len (lockID ) {
1607
+ return nil , fmt .Errorf ("custom lock ID must be " +
1608
+ "exactly 32 bytes" )
1609
+ }
1610
+
1611
+ copy (lockID [:], req .CustomLockId )
1612
+ customLockID = & lockID
1613
+ }
1614
+
1615
+ var customLockDuration time.Duration
1616
+ if req .LockExpirationSeconds != 0 {
1617
+ customLockDuration = time .Duration (req .LockExpirationSeconds ) *
1618
+ time .Second
1619
+ }
1620
+
1603
1621
// There are three ways a user can specify what we call the template (a
1604
1622
// list of inputs and outputs to use in the PSBT): Either as a PSBT
1605
1623
// packet directly with no coin selection, a PSBT with coin selection or
@@ -1619,6 +1637,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
1619
1637
return w .fundPsbtInternalWallet (
1620
1638
account , keyScopeFromChangeAddressType (req .ChangeType ),
1621
1639
packet , minConfs , feeSatPerKW , coinSelectionStrategy ,
1640
+ customLockID , customLockDuration ,
1622
1641
)
1623
1642
1624
1643
// The template is specified as a PSBT with the intention to perform
@@ -1701,6 +1720,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
1701
1720
return w .fundPsbtCoinSelect (
1702
1721
account , changeIndex , packet , minConfs , changeType ,
1703
1722
feeSatPerKW , coinSelectionStrategy , maxFeeRatio ,
1723
+ customLockID , customLockDuration ,
1704
1724
)
1705
1725
1706
1726
// The template is specified as a RPC message. We need to create a new
@@ -1758,6 +1778,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
1758
1778
return w .fundPsbtInternalWallet (
1759
1779
account , keyScopeFromChangeAddressType (req .ChangeType ),
1760
1780
packet , minConfs , feeSatPerKW , coinSelectionStrategy ,
1781
+ customLockID , customLockDuration ,
1761
1782
)
1762
1783
1763
1784
default :
@@ -1770,8 +1791,9 @@ func (w *WalletKit) FundPsbt(_ context.Context,
1770
1791
// wallet that does not allow specifying custom inputs while selecting coins.
1771
1792
func (w * WalletKit ) fundPsbtInternalWallet (account string ,
1772
1793
keyScope * waddrmgr.KeyScope , packet * psbt.Packet , minConfs int32 ,
1773
- feeSatPerKW chainfee.SatPerKWeight ,
1774
- strategy base.CoinSelectionStrategy ) (* FundPsbtResponse , error ) {
1794
+ feeSatPerKW chainfee.SatPerKWeight , strategy base.CoinSelectionStrategy ,
1795
+ customLockID * wtxmgr.LockID , customLockDuration time.Duration ) (
1796
+ * FundPsbtResponse , error ) {
1775
1797
1776
1798
// The RPC parsing part is now over. Several of the following operations
1777
1799
// require us to hold the global coin selection lock, so we do the rest
@@ -1885,7 +1907,8 @@ func (w *WalletKit) fundPsbtInternalWallet(account string,
1885
1907
}
1886
1908
1887
1909
response , err = w .lockAndCreateFundingResponse (
1888
- packet , outpoints , changeIndex ,
1910
+ packet , outpoints , changeIndex , customLockID ,
1911
+ customLockDuration ,
1889
1912
)
1890
1913
1891
1914
return err
@@ -1904,7 +1927,8 @@ func (w *WalletKit) fundPsbtCoinSelect(account string, changeIndex int32,
1904
1927
packet * psbt.Packet , minConfs int32 ,
1905
1928
changeType chanfunding.ChangeAddressType ,
1906
1929
feeRate chainfee.SatPerKWeight , strategy base.CoinSelectionStrategy ,
1907
- maxFeeRatio float64 ) (* FundPsbtResponse , error ) {
1930
+ maxFeeRatio float64 , customLockID * wtxmgr.LockID ,
1931
+ customLockDuration time.Duration ) (* FundPsbtResponse , error ) {
1908
1932
1909
1933
// We want to make sure we don't select any inputs that are already
1910
1934
// specified in the template. To do that, we require those inputs to
@@ -2019,7 +2043,10 @@ func (w *WalletKit) fundPsbtCoinSelect(account string, changeIndex int32,
2019
2043
}
2020
2044
2021
2045
// We're done. Let's serialize and return the updated package.
2022
- return w .lockAndCreateFundingResponse (packet , nil , changeIndex )
2046
+ return w .lockAndCreateFundingResponse (
2047
+ packet , nil , changeIndex , customLockID ,
2048
+ customLockDuration ,
2049
+ )
2023
2050
}
2024
2051
2025
2052
// The RPC parsing part is now over. Several of the following operations
@@ -2091,7 +2118,8 @@ func (w *WalletKit) fundPsbtCoinSelect(account string, changeIndex int32,
2091
2118
}
2092
2119
2093
2120
response , err = w .lockAndCreateFundingResponse (
2094
- packet , addedOutpoints , changeIndex ,
2121
+ packet , addedOutpoints , changeIndex , customLockID ,
2122
+ customLockDuration ,
2095
2123
)
2096
2124
2097
2125
return err
@@ -2136,8 +2164,9 @@ func (w *WalletKit) assertNotAvailable(inputs []*wire.TxIn, minConfs int32,
2136
2164
// lockAndCreateFundingResponse locks the given outpoints and creates a funding
2137
2165
// response with the serialized PSBT, the change index and the locked UTXOs.
2138
2166
func (w * WalletKit ) lockAndCreateFundingResponse (packet * psbt.Packet ,
2139
- newOutpoints []wire.OutPoint , changeIndex int32 ) (* FundPsbtResponse ,
2140
- error ) {
2167
+ newOutpoints []wire.OutPoint , changeIndex int32 ,
2168
+ customLockID * wtxmgr.LockID , customLockDuration time.Duration ) (
2169
+ * FundPsbtResponse , error ) {
2141
2170
2142
2171
// Make sure we can properly serialize the packet. If this goes wrong
2143
2172
// then something isn't right with the inputs, and we probably shouldn't
@@ -2148,7 +2177,9 @@ func (w *WalletKit) lockAndCreateFundingResponse(packet *psbt.Packet,
2148
2177
return nil , fmt .Errorf ("error serializing funded PSBT: %w" , err )
2149
2178
}
2150
2179
2151
- locks , err := lockInputs (w .cfg .Wallet , newOutpoints )
2180
+ locks , err := lockInputs (
2181
+ w .cfg .Wallet , newOutpoints , customLockID , customLockDuration ,
2182
+ )
2152
2183
if err != nil {
2153
2184
return nil , fmt .Errorf ("could not lock inputs: %w" , err )
2154
2185
}
0 commit comments