Move fee increment to Account structure.

When a BIP0032 wallet is implemented and multiple address chains can
be supported by a single keystore, the Account structure will
represent a single wallet (and be renamed to reflect that change),
rather than keeping the collection of Account structs as currently
managed by the AccountManager.  In preperation for this, and to remove
a global variable, move the fee increment for created transactions to
this structure.  When setting the fee, look it up from the default
account.
This commit is contained in:
Josh Rickmar 2014-07-07 09:35:54 -05:00
parent 0abe6e32bf
commit 2d9fb71afd
4 changed files with 39 additions and 43 deletions

View file

@ -1334,22 +1334,26 @@ func GetInfo(icmd btcjson.Cmd) (interface{}, error) {
return nil, err
}
var balance btcutil.Amount
accounts, err := AcctMgr.ListAccounts(1)
if err != nil {
return nil, err
}
for _, v := range accounts {
balance += v
var balance, feeIncr btcutil.Amount
accounts := AcctMgr.AllAccounts()
for _, a := range accounts {
bal, err := a.CalculateBalance(1)
if err == nil {
balance += bal
}
// For now we assume all transactions can only be created
// with the default account (as this is the only account
// that's usable), so use it for the fee increment.
if a.name == "" {
feeIncr = a.FeeIncrement
}
}
info.WalletVersion = int32(wallet.VersCurrent.Uint32())
info.Balance = balance.ToUnit(btcutil.AmountBTC)
// Keypool times are not tracked. set to current time.
info.KeypoolOldest = time.Now().Unix()
info.KeypoolSize = int32(cfg.KeypoolSize)
TxFeeIncrement.Lock()
info.PaytxFee = float64(TxFeeIncrement.i) / btcutil.SatoshiPerBitcoin
TxFeeIncrement.Unlock()
info.PaytxFee = feeIncr.ToUnit(btcutil.AmountBTC)
// We don't set the following since they don't make much sense in the
// wallet architecture:
// - unlocked_until
@ -2306,10 +2310,14 @@ func SetTxFee(icmd btcjson.Cmd) (interface{}, error) {
return nil, ErrNeedPositiveAmount
}
// Set global tx fee.
TxFeeIncrement.Lock()
TxFeeIncrement.i = btcutil.Amount(cmd.Amount)
TxFeeIncrement.Unlock()
// Lookup default account (which realistically is the only account
// that transactions can be made with at the moment) and set its
// fee increment field.
a, err := AcctMgr.Account("")
if err != nil {
return nil, ErrNoAccounts
}
a.FeeIncrement = btcutil.Amount(cmd.Amount)
// A boolean true result is returned upon success.
return true, nil