Begin tracking newly created wallets against btcd.

This commit is contained in:
Josh Rickmar 2013-09-05 12:50:39 -04:00
parent ed98256553
commit 2789502ec9
3 changed files with 20 additions and 4 deletions

2
cmd.go
View file

@ -73,7 +73,7 @@ func main() {
log.Info("Unable to connect to btcd. Retrying in 5 seconds.")
time.Sleep(5 * time.Second)
} else if err != nil {
log.Info(err.Error())
log.Error(err)
break
}
}

View file

@ -336,10 +336,22 @@ func CreateEncryptedWallet(reply chan []byte, msg []byte) {
return
}
wallets.Lock()
wallets.m[wname] = &BtcWallet{
Wallet: w,
// Grab a new unique sequence number for tx notifications in new blocks.
seq.Lock()
n := seq.n
seq.n++
seq.Unlock()
bw := &BtcWallet{
Wallet: w,
NewBlockTxSeqN: n,
}
// TODO(jrick): only begin tracking wallet if btcwallet is already
// connected to btcd.
bw.Track()
wallets.Lock()
wallets.m[wname] = bw
wallets.Unlock()
ReplySuccess(reply, v["id"], nil)
}

View file

@ -45,6 +45,10 @@ var (
// Messages sent to this channel are sent to each connected frontend.
frontendNotificationMaster = make(chan []byte, 100)
// replyHandlers maps between a sequence number (passed as part of
// the JSON Id field) and a function to handle a reply or notification
// from btcd. As requests are received, this map is checked for a
// handler function to route the reply to.
replyHandlers = struct {
sync.Mutex
m map[uint64]func(interface{}) bool