forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_change_processor.go
204 lines (178 loc) · 6.56 KB
/
stats_change_processor.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package ingest
import (
"context"
"fmt"
"github.com/pownieh/stellar_go/xdr"
)
// StatsChangeProcessor is a state processors that counts number of changes types
// and entry types.
type StatsChangeProcessor struct {
results StatsChangeProcessorResults
}
// StatsChangeProcessorResults contains results after running StatsChangeProcessor.
type StatsChangeProcessorResults struct {
AccountsCreated int64
AccountsUpdated int64
AccountsRemoved int64
ClaimableBalancesCreated int64
ClaimableBalancesUpdated int64
ClaimableBalancesRemoved int64
DataCreated int64
DataUpdated int64
DataRemoved int64
OffersCreated int64
OffersUpdated int64
OffersRemoved int64
TrustLinesCreated int64
TrustLinesUpdated int64
TrustLinesRemoved int64
LiquidityPoolsCreated int64
LiquidityPoolsUpdated int64
LiquidityPoolsRemoved int64
ContractDataCreated int64
ContractDataUpdated int64
ContractDataRemoved int64
ContractCodeCreated int64
ContractCodeUpdated int64
ContractCodeRemoved int64
ConfigSettingsCreated int64
ConfigSettingsUpdated int64
ConfigSettingsRemoved int64
ExpirationCreated int64
ExpirationUpdated int64
ExpirationRemoved int64
}
func (p *StatsChangeProcessor) ProcessChange(ctx context.Context, change Change) error {
switch change.Type {
case xdr.LedgerEntryTypeAccount:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.AccountsCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.AccountsUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.AccountsRemoved++
}
case xdr.LedgerEntryTypeClaimableBalance:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.ClaimableBalancesCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.ClaimableBalancesUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.ClaimableBalancesRemoved++
}
case xdr.LedgerEntryTypeData:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.DataCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.DataUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.DataRemoved++
}
case xdr.LedgerEntryTypeOffer:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.OffersCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.OffersUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.OffersRemoved++
}
case xdr.LedgerEntryTypeTrustline:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.TrustLinesCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.TrustLinesUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.TrustLinesRemoved++
}
case xdr.LedgerEntryTypeLiquidityPool:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.LiquidityPoolsCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.LiquidityPoolsUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.LiquidityPoolsRemoved++
}
case xdr.LedgerEntryTypeContractData:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.ContractDataCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.ContractDataUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.ContractDataRemoved++
}
case xdr.LedgerEntryTypeContractCode:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.ContractCodeCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.ContractCodeUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.ContractCodeRemoved++
}
case xdr.LedgerEntryTypeConfigSetting:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.ConfigSettingsCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.ConfigSettingsUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.ConfigSettingsRemoved++
}
case xdr.LedgerEntryTypeExpiration:
switch change.LedgerEntryChangeType() {
case xdr.LedgerEntryChangeTypeLedgerEntryCreated:
p.results.ExpirationCreated++
case xdr.LedgerEntryChangeTypeLedgerEntryUpdated:
p.results.ExpirationUpdated++
case xdr.LedgerEntryChangeTypeLedgerEntryRemoved:
p.results.ExpirationRemoved++
}
default:
return fmt.Errorf("unsupported ledger entry type: %s", change.Type.String())
}
return nil
}
func (p *StatsChangeProcessor) GetResults() StatsChangeProcessorResults {
return p.results
}
func (stats *StatsChangeProcessorResults) Map() map[string]interface{} {
return map[string]interface{}{
"stats_accounts_created": stats.AccountsCreated,
"stats_accounts_updated": stats.AccountsUpdated,
"stats_accounts_removed": stats.AccountsRemoved,
"stats_claimable_balances_created": stats.ClaimableBalancesCreated,
"stats_claimable_balances_updated": stats.ClaimableBalancesUpdated,
"stats_claimable_balances_removed": stats.ClaimableBalancesRemoved,
"stats_data_created": stats.DataCreated,
"stats_data_updated": stats.DataUpdated,
"stats_data_removed": stats.DataRemoved,
"stats_offers_created": stats.OffersCreated,
"stats_offers_updated": stats.OffersUpdated,
"stats_offers_removed": stats.OffersRemoved,
"stats_trust_lines_created": stats.TrustLinesCreated,
"stats_trust_lines_updated": stats.TrustLinesUpdated,
"stats_trust_lines_removed": stats.TrustLinesRemoved,
"stats_liquidity_pools_created": stats.LiquidityPoolsCreated,
"stats_liquidity_pools_updated": stats.LiquidityPoolsUpdated,
"stats_liquidity_pools_removed": stats.LiquidityPoolsRemoved,
"stats_contract_data_created": stats.ContractDataCreated,
"stats_contract_data_updated": stats.ContractDataUpdated,
"stats_contract_data_removed": stats.ContractDataRemoved,
"stats_contract_code_created": stats.ContractCodeCreated,
"stats_contract_code_updated": stats.ContractCodeUpdated,
"stats_contract_code_removed": stats.ContractCodeRemoved,
"stats_config_settings_created": stats.ConfigSettingsCreated,
"stats_config_settings_updated": stats.ConfigSettingsUpdated,
"stats_config_settings_removed": stats.ConfigSettingsRemoved,
"stats_expiration_created": stats.ExpirationCreated,
"stats_expiration_updated": stats.ExpirationUpdated,
"stats_expiration_removed": stats.ExpirationRemoved,
}
}