This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
admin_actions_stats.go
102 lines (88 loc) · 2.65 KB
/
admin_actions_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package bux
import (
"context"
)
// AdminStats are statistics about the bux server
type AdminStats struct {
Balance int64 `json:"balance"`
Destinations int64 `json:"destinations"`
PaymailAddresses int64 `json:"paymail_addresses"`
Transactions int64 `json:"transactions"`
TransactionsPerDay map[string]interface{} `json:"transactions_per_day"`
Utxos int64 `json:"utxos"`
UtxosPerType map[string]interface{} `json:"utxos_per_type"`
XPubs int64 `json:"xpubs"`
}
// GetStats will get stats for the BUX Console (admin)
func (c *Client) GetStats(ctx context.Context, opts ...ModelOps) (*AdminStats, error) {
// Check for existing NewRelic transaction
ctx = c.GetOrStartTxn(ctx, "admin_get_stats")
// Set the default model options
defaultOpts := c.DefaultModelOptions(opts...)
var (
destinationsCount int64
err error
paymailAddressCount int64
transactionsCount int64
transactionsPerDay map[string]interface{}
utxosCount int64
utxosPerType map[string]interface{}
xpubsCount int64
)
// Get the destination count
if destinationsCount, err = getDestinationsCount(
ctx, nil, nil, defaultOpts...,
); err != nil {
return nil, err
}
// Get the transaction count
if transactionsCount, err = getTransactionsCount(
ctx, nil, nil, defaultOpts...,
); err != nil {
return nil, err
}
// Get the paymail address count
conditions := map[string]interface{}{
"deleted_at": nil,
}
if paymailAddressCount, err = getPaymailAddressesCount(
ctx, nil, &conditions, defaultOpts...,
); err != nil {
return nil, err
}
// Get the utxo count
if utxosCount, err = getUtxosCount(
ctx, nil, nil, defaultOpts...,
); err != nil {
return nil, err
}
// Get the xpub count
if xpubsCount, err = getXPubsCount(
ctx, nil, nil, defaultOpts...,
); err != nil {
return nil, err
}
// Get the transactions per day count
if transactionsPerDay, err = getTransactionsAggregate(
ctx, nil, nil, "created_at", defaultOpts...,
); err != nil {
return nil, err
}
// Get the utxos per day count
if utxosPerType, err = getUtxosAggregate(
ctx, nil, nil, "type", defaultOpts...,
); err != nil {
return nil, err
}
// Return the statistics
return &AdminStats{
Balance: 0,
Destinations: destinationsCount,
PaymailAddresses: paymailAddressCount,
Transactions: transactionsCount,
TransactionsPerDay: transactionsPerDay,
Utxos: utxosCount,
UtxosPerType: utxosPerType,
XPubs: xpubsCount,
}, nil
}