diff --git a/database/database.go b/database/database.go index 8e3869b..d9be243 100644 --- a/database/database.go +++ b/database/database.go @@ -31,7 +31,7 @@ var ( privateKeyK = []byte("privatekey") ) -// Open initialises and returns an open database. If no database file is found +// Open initializes and returns an open database. If no database file is found // at the provided path, a new one will be created. func Open(ctx context.Context, shutdownWg *sync.WaitGroup, dbFile string) (*VspDatabase, error) { @@ -61,14 +61,14 @@ func Open(ctx context.Context, shutdownWg *sync.WaitGroup, dbFile string) (*VspD // Create all storage buckets of the VSP if they don't already exist. err = db.Update(func(tx *bolt.Tx) error { if tx.Bucket(vspBktK) == nil { - log.Debug("Initialising new database") + log.Debug("Initializing new database") // Create parent bucket. vspBkt, err := tx.CreateBucket(vspBktK) if err != nil { return fmt.Errorf("failed to create %s bucket: %v", string(vspBktK), err) } - // Initialise with database version 1. + // Initialize with database version 1. vbytes := make([]byte, 4) binary.LittleEndian.PutUint32(vbytes, uint32(1)) err = vspBkt.Put(versionK, vbytes) diff --git a/database/ticket.go b/database/ticket.go index 08c802d..4b9f9b6 100644 --- a/database/ticket.go +++ b/database/ticket.go @@ -155,3 +155,31 @@ func (vdb *VspDatabase) UpdateExpireAndFee(ticketHash string, expiration int64, return ticketBkt.Put(hashBytes, ticketBytes) }) } + +func (vdb *VspDatabase) CountTickets() (int, int, error) { + var total, feePaid int + err := vdb.db.View(func(tx *bolt.Tx) error { + ticketBkt := tx.Bucket(vspBktK).Bucket(ticketBktK) + + return ticketBkt.ForEach(func(k, v []byte) error { + total++ + var ticket Ticket + err := json.Unmarshal(v, &ticket) + if err != nil { + return fmt.Errorf("could not unmarshal ticket: %v", err) + } + + if ticket.FeeTxHash != "" { + feePaid++ + } + + return nil + }) + }) + + if err != nil { + return 0, 0, err + } + + return total, feePaid, nil +} diff --git a/main.go b/main.go index a45c58a..931ee6d 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func run(ctx context.Context) error { // Load config file and parse CLI args. cfg, err := loadConfig() if err != nil { - // Don't use logger here because it may not be initialised. + // Don't use logger here because it may not be initialized. fmt.Fprintf(os.Stderr, "Config error: %v\n", err) return err } @@ -120,7 +120,7 @@ func run(ctx context.Context) error { } err = webapi.Start(ctx, shutdownRequestChannel, &shutdownWg, cfg.Listen, db, feeWalletConnect, votingWalletConnect, cfg.WebServerDebug, apiCfg) if err != nil { - log.Errorf("Failed to initialise webapi: %v", err) + log.Errorf("Failed to initialize webapi: %v", err) requestShutdown() shutdownWg.Wait() return err diff --git a/webapi/templates/homepage.html b/webapi/templates/homepage.html index e9eaec2..47caa4c 100644 --- a/webapi/templates/homepage.html +++ b/webapi/templates/homepage.html @@ -11,5 +11,12 @@
| Total tickets: | {{ .TotalTickets }} |
| FeePaid tickets: | {{ .FeePaidTickets }} |
| VSP Fee: | {{ .VSPFee }} |
| Network: | {{ .Network }} |
Last updated: {{.UpdateTime}}