diff --git a/rpc/legacyrpc/methods.go b/rpc/legacyrpc/methods.go index e4b2464..db8f9ea 100644 --- a/rpc/legacyrpc/methods.go +++ b/rpc/legacyrpc/methods.go @@ -512,7 +512,7 @@ func GetInfo(icmd interface{}, w *wallet.Wallet, chainClient *chain.RPCClient) ( // to using the manager version. info.WalletVersion = int32(waddrmgr.LatestMgrVersion) info.Balance = bal.ToBTC() - info.PaytxFee = w.RelayFee.ToBTC() + info.PaytxFee = w.RelayFee().ToBTC() // We don't set the following since they don't make much sense in the // wallet architecture: // - unlocked_until @@ -1572,11 +1572,11 @@ func SetTxFee(icmd interface{}, w *wallet.Wallet) (interface{}, error) { return nil, ErrNeedPositiveAmount } - incr, err := btcutil.NewAmount(cmd.Amount) + relayFee, err := btcutil.NewAmount(cmd.Amount) if err != nil { return nil, err } - w.RelayFee = incr + w.SetRelayFee(relayFee) // A boolean true result is returned upon success. return true, nil diff --git a/wallet/createtx.go b/wallet/createtx.go index 500f0b3..d072796 100644 --- a/wallet/createtx.go +++ b/wallet/createtx.go @@ -134,7 +134,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, w.RelayFee(), inputSource, changeSource) if err != nil { return nil, err diff --git a/wallet/wallet.go b/wallet/wallet.go index 4bfa72b..f0c90d8 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -75,8 +75,8 @@ type Wallet struct { chainClientSyncMtx sync.Mutex lockedOutpoints map[wire.OutPoint]struct{} - RelayFee btcutil.Amount - DisallowFree bool + 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 @@ -357,6 +357,23 @@ func (w *Wallet) ChainClient() *chain.RPCClient { 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() @@ -2009,7 +2026,7 @@ func (w *Wallet) SendOutputs(outputs []*wire.TxOut, account uint32, } for _, output := range outputs { - err = txrules.CheckOutput(output, w.RelayFee) + err = txrules.CheckOutput(output, w.RelayFee()) if err != nil { return nil, err } @@ -2230,7 +2247,7 @@ func Open(pubPass []byte, params *chaincfg.Params, db walletdb.DB, waddrmgrNS, w Manager: addrMgr, TxStore: txMgr, lockedOutpoints: map[wire.OutPoint]struct{}{}, - RelayFee: txrules.DefaultRelayFeePerKb, + relayFee: txrules.DefaultRelayFeePerKb, rescanAddJob: make(chan *RescanJob), rescanBatch: make(chan *rescanBatch), rescanNotifications: make(chan interface{}),