Fix issues found by golint and go vet.

This commit is contained in:
Josh Rickmar 2013-10-14 16:39:15 -04:00
parent a77fb8f0ae
commit d44159b452
4 changed files with 24 additions and 7 deletions

13
cmd.go
View file

@ -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)

View file

@ -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{

View file

@ -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

View file

@ -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
}
}