lnwallet/btcwallet: implement CreateSimpleTx
This commit is contained in:
parent
b4a1024ac7
commit
6fb664dbe1
@ -17,6 +17,8 @@ import (
|
||||
"github.com/btcsuite/btcwallet/chain"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
base "github.com/btcsuite/btcwallet/wallet"
|
||||
"github.com/btcsuite/btcwallet/wallet/txauthor"
|
||||
"github.com/btcsuite/btcwallet/wallet/txrules"
|
||||
"github.com/btcsuite/btcwallet/walletdb"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
@ -300,6 +302,35 @@ func (b *BtcWallet) SendOutputs(outputs []*wire.TxOut,
|
||||
return b.wallet.SendOutputs(outputs, defaultAccount, 1, feeSatPerKB)
|
||||
}
|
||||
|
||||
// CreateSimpleTx creates a Bitcoin transaction paying to the specified
|
||||
// outputs. The transaction is not broadcasted to the network, but a new change
|
||||
// address might be created in the wallet database. In the case the wallet has
|
||||
// insufficient funds, or the outputs are non-standard, an error should be
|
||||
// returned. This method also takes the target fee expressed in sat/kw that
|
||||
// should be used when crafting the transaction.
|
||||
//
|
||||
// NOTE: The dryRun argument can be set true to create a tx that doesn't alter
|
||||
// the database. A tx created with this set to true SHOULD NOT be broadcasted.
|
||||
//
|
||||
// This is a part of the WalletController interface.
|
||||
func (b *BtcWallet) CreateSimpleTx(outputs []*wire.TxOut,
|
||||
feeRate lnwallet.SatPerKWeight, dryRun bool) (*txauthor.AuthoredTx, error) {
|
||||
|
||||
// The fee rate is passed in using units of sat/kw, so we'll convert
|
||||
// this to sat/KB as the CreateSimpleTx method requires this unit.
|
||||
feeSatPerKB := btcutil.Amount(feeRate.FeePerKVByte())
|
||||
|
||||
// Sanity check outputs.
|
||||
for _, output := range outputs {
|
||||
err := txrules.CheckOutput(output, feeSatPerKB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return b.wallet.CreateSimpleTx(defaultAccount, outputs, 1, feeSatPerKB, dryRun)
|
||||
}
|
||||
|
||||
// LockOutpoint marks an outpoint as locked meaning it will no longer be deemed
|
||||
// as eligible for coin selection. Locking outputs are utilized in order to
|
||||
// avoid race conditions when selecting inputs for usage when funding a
|
||||
|
Loading…
Reference in New Issue
Block a user