From d44159b4520f59b94f4009bf6646dec55f5fa789 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 14 Oct 2013 16:39:15 -0400 Subject: [PATCH] Fix issues found by golint and go vet. --- cmd.go | 13 +++++++++---- cmdmgr.go | 14 +++++++++++++- createtx_test.go | 2 +- sockets.go | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cmd.go b/cmd.go index f542335..142a2bc 100644 --- a/cmd.go +++ b/cmd.go @@ -75,6 +75,10 @@ type BtcWallet struct { } } +// BtcWalletStore stores all wallets currently being handled by +// btcwallet. Wallet are stored in a map with the account name as the +// key. A RWMutex is used to protect against incorrect concurrent +// access. type BtcWalletStore struct { sync.RWMutex m map[string]*BtcWallet @@ -87,10 +91,7 @@ func NewBtcWalletStore() *BtcWalletStore { } } -// Rollback reverts each stored BtcWallet to a state before the block -// with the passed chainheight and block hash was connected to the main -// chain. This is used to remove transactions and utxos for each wallet -// that occured on a chain no longer considered to be the main chain. +// Rollback rolls back each BtcWallet saved in the store. func (s *BtcWalletStore) Rollback(height int64, hash *btcwire.ShaHash) { s.Lock() for _, w := range s.m { @@ -99,6 +100,10 @@ func (s *BtcWalletStore) Rollback(height int64, hash *btcwire.ShaHash) { s.Unlock() } +// Rollback reverts each stored BtcWallet to a state before the block +// with the passed chainheight and block hash was connected to the main +// chain. This is used to remove transactions and utxos for each wallet +// that occured on a chain no longer considered to be the main chain. func (w *BtcWallet) Rollback(height int64, hash *btcwire.ShaHash) { w.UtxoStore.Lock() w.UtxoStore.dirty = w.UtxoStore.dirty || w.UtxoStore.s.Rollback(height, hash) diff --git a/cmdmgr.go b/cmdmgr.go index 2d62662..0f34a48 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -310,6 +310,11 @@ func GetBalance(reply chan []byte, msg *btcjson.Message) { } } +// GetBalances notifies each attached wallet of the current confirmed +// and unconfirmed account balances. +// +// TODO(jrick): Switch this to return a JSON object (map) of all accounts +// and their balances, instead of separate notifications for each account. func GetBalances(reply chan []byte, msg *btcjson.Message) { wallets.RLock() for _, w := range wallets.m { @@ -839,7 +844,10 @@ func BtcdConnected(reply chan []byte, msg *btcjson.Message) { ReplySuccess(reply, msg.Id, btcdConnected.b) } -// TODO(jrick): move somewhere better so it can be shared with frontends. +// AccountNtfn is a struct for marshalling any generic notification +// about a account for a wallet frontend. +// +// TODO(jrick): move to btcjson so it can be shared with frontends? type AccountNtfn struct { Account string `json:"account"` Notification interface{} `json:"notification"` @@ -860,6 +868,8 @@ func NotifyWalletLockStateChange(account string, locked bool) { frontendNotificationMaster <- msg } +// NotifyWalletBalance sends a confirmed account balance notification +// to a frontend. func NotifyWalletBalance(frontend chan []byte, account string, balance float64) { var id interface{} = "btcwallet:accountbalance" m := btcjson.Reply{ @@ -873,6 +883,8 @@ func NotifyWalletBalance(frontend chan []byte, account string, balance float64) frontend <- msg } +// NotifyWalletBalanceUnconfirmed sends a confirmed account balance +// notification to a frontend. func NotifyWalletBalanceUnconfirmed(frontend chan []byte, account string, balance float64) { var id interface{} = "btcwallet:accountbalanceunconfirmed" m := btcjson.Reply{ diff --git a/createtx_test.go b/createtx_test.go index 547659a..1f9274a 100644 --- a/createtx_test.go +++ b/createtx_test.go @@ -64,7 +64,7 @@ func TestFakeTxs(t *testing.T) { pairs := map[string]uint64{ "17XhEvq9Nahdj7Xe1nv6oRe1tEmaHUuynH": 5000, } - rawtx, err := btcw.txToPairs(pairs, 100, 0) + rawtx, _, err := btcw.txToPairs(pairs, 100, 0) if err != nil { t.Errorf("Tx creation failed: %s", err) return diff --git a/sockets.go b/sockets.go index 2b7a2c6..a6b1574 100644 --- a/sockets.go +++ b/sockets.go @@ -217,7 +217,7 @@ func BtcdHandler(ws *websocket.Conn) { case r := <-btcdMsgs: if err := websocket.Message.Send(ws, r); err != nil { // btcd disconnected. - log.Error("Unable to send message to btcd: %v", err) + log.Errorf("Unable to send message to btcd: %v", err) return } }