wallet: remove internal relayFee in favor of passing in fee rate when sending

In this commit, we do away with the internal relayFee all together.
Instead, we’ll pass in the fee rate when we’re crafting any
transactions. This allows the caller to manually dictate their desired
fee rate.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-18 15:22:46 -08:00
parent 60b23c144e
commit 7b9d880fee
2 changed files with 12 additions and 30 deletions

View file

@ -101,7 +101,9 @@ func (s secretSource) GetScript(addr btcutil.Address) ([]byte, error) {
// UTXO set and minconf policy. An additional output may be added to return
// change to the wallet. An appropriate fee is included based on the wallet's
// current relay fee. The wallet must be unlocked to create the transaction.
func (w *Wallet) txToOutputs(outputs []*wire.TxOut, account uint32, minconf int32) (tx *txauthor.AuthoredTx, err error) {
func (w *Wallet) txToOutputs(outputs []*wire.TxOut, account uint32,
minconf int32, feeSatPerKb btcutil.Amount) (tx *txauthor.AuthoredTx, err error) {
chainClient, err := w.requireChainClient()
if err != nil {
return nil, err
@ -137,7 +139,7 @@ func (w *Wallet) txToOutputs(outputs []*wire.TxOut, account uint32, minconf int3
}
return txscript.PayToAddrScript(changeAddr)
}
tx, err = txauthor.NewUnsignedTransaction(outputs, w.RelayFee(),
tx, err = txauthor.NewUnsignedTransaction(outputs, feeSatPerKb,
inputSource, changeSource)
if err != nil {
return err

View file

@ -75,8 +75,6 @@ type Wallet struct {
chainClientSyncMtx sync.Mutex
lockedOutpoints map[wire.OutPoint]struct{}
relayFee btcutil.Amount
relayFeeMu sync.Mutex
// Channels for rescan processing. Requests are added and merged with
// any waiting requests, before being sent to another goroutine to
@ -205,23 +203,6 @@ func (w *Wallet) ChainClient() chain.Interface {
return chainClient
}
// RelayFee returns the current minimum relay fee (per kB of serialized
// transaction) used when constructing transactions.
func (w *Wallet) RelayFee() btcutil.Amount {
w.relayFeeMu.Lock()
relayFee := w.relayFee
w.relayFeeMu.Unlock()
return relayFee
}
// SetRelayFee sets a new minimum relay fee (per kB of serialized
// transaction) used when constructing transactions.
func (w *Wallet) SetRelayFee(relayFee btcutil.Amount) {
w.relayFeeMu.Lock()
w.relayFee = relayFee
w.relayFeeMu.Unlock()
}
// quitChan atomically reads the quit channel.
func (w *Wallet) quitChan() <-chan struct{} {
w.quitMu.Lock()
@ -529,10 +510,11 @@ func (w *Wallet) syncWithChain() error {
type (
createTxRequest struct {
account uint32
outputs []*wire.TxOut
minconf int32
resp chan createTxResponse
account uint32
outputs []*wire.TxOut
minconf int32
feeSatPerKB btcutil.Amount
resp chan createTxResponse
}
createTxResponse struct {
tx *txauthor.AuthoredTx
@ -562,7 +544,7 @@ out:
continue
}
tx, err := w.txToOutputs(txr.outputs, txr.account,
txr.minconf)
txr.minconf, txr.feeSatPerKB)
heldUnlock.release()
txr.resp <- createTxResponse{tx, err}
case <-quit:
@ -2318,16 +2300,15 @@ func (w *Wallet) TotalReceivedForAddr(addr btcutil.Address, minConf int32) (btcu
// SendOutputs creates and sends payment transactions. It returns the
// transaction hash upon success.
func (w *Wallet) SendOutputs(outputs []*wire.TxOut, account uint32,
minconf int32) (*chainhash.Hash, error) {
minconf int32, satPerKb btcutil.Amount) (*chainhash.Hash, error) {
chainClient, err := w.requireChainClient()
if err != nil {
return nil, err
}
relayFee := w.RelayFee()
for _, output := range outputs {
err = txrules.CheckOutput(output, relayFee)
err = txrules.CheckOutput(output, satPerKb)
if err != nil {
return nil, err
}
@ -2658,7 +2639,6 @@ func Open(db walletdb.DB, pubPass []byte, cbs *waddrmgr.OpenCallbacks, params *c
Manager: addrMgr,
TxStore: txMgr,
lockedOutpoints: map[wire.OutPoint]struct{}{},
relayFee: txrules.DefaultRelayFeePerKb,
rescanAddJob: make(chan *RescanJob),
rescanBatch: make(chan *rescanBatch),
rescanNotifications: make(chan interface{}),