forked from stellar/go
/
main.go
243 lines (216 loc) · 6.5 KB
/
main.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package effects
import (
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/resource/base"
"github.com/stellar/go/services/horizon/internal/render/hal"
"golang.org/x/net/context"
)
var TypeNames = map[history.EffectType]string{
history.EffectAccountCreated: "account_created",
history.EffectAccountRemoved: "account_removed",
history.EffectAccountCredited: "account_credited",
history.EffectAccountDebited: "account_debited",
history.EffectAccountThresholdsUpdated: "account_thresholds_updated",
history.EffectAccountHomeDomainUpdated: "account_home_domain_updated",
history.EffectAccountFlagsUpdated: "account_flags_updated",
history.EffectSignerCreated: "signer_created",
history.EffectSignerRemoved: "signer_removed",
history.EffectSignerUpdated: "signer_updated",
history.EffectTrustlineCreated: "trustline_created",
history.EffectTrustlineRemoved: "trustline_removed",
history.EffectTrustlineUpdated: "trustline_updated",
history.EffectTrustlineAuthorized: "trustline_authorized",
history.EffectTrustlineDeauthorized: "trustline_deauthorized",
history.EffectOfferCreated: "offer_created",
history.EffectOfferRemoved: "offer_removed",
history.EffectOfferUpdated: "offer_updated",
history.EffectTrade: "trade",
history.EffectDataCreated: "data_created",
history.EffectDataRemoved: "data_removed",
history.EffectDataUpdated: "data_updated",
}
// New creates a new effect resource from the provided database representation
// of the effect.
func New(
ctx context.Context,
row history.Effect,
) (result hal.Pageable, err error) {
basev := Base{}
basev.Populate(ctx, row)
switch row.Type {
case history.EffectAccountCreated:
e := AccountCreated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectAccountCredited:
e := AccountCredited{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectAccountDebited:
e := AccountDebited{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectAccountThresholdsUpdated:
e := AccountThresholdsUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectAccountHomeDomainUpdated:
e := AccountHomeDomainUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectAccountFlagsUpdated:
e := AccountFlagsUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectSignerCreated:
e := SignerCreated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectSignerUpdated:
e := SignerUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectSignerRemoved:
e := SignerRemoved{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectTrustlineCreated:
e := TrustlineCreated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectTrustlineUpdated:
e := TrustlineUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectTrustlineRemoved:
e := TrustlineRemoved{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectTrustlineAuthorized:
e := TrustlineAuthorized{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectTrustlineDeauthorized:
e := TrustlineDeauthorized{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectTrade:
e := Trade{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
default:
result = basev
}
if err != nil {
return
}
rh, ok := result.(base.Rehydratable)
if ok {
err = rh.Rehydrate()
}
return
}
// Base provides the common structure for any effect resource effect.
type Base struct {
Links struct {
Operation hal.Link `json:"operation"`
Succeeds hal.Link `json:"succeeds"`
Precedes hal.Link `json:"precedes"`
} `json:"_links"`
ID string `json:"id"`
PT string `json:"paging_token"`
Account string `json:"account"`
Type string `json:"type"`
TypeI int32 `json:"type_i"`
}
type AccountCreated struct {
Base
StartingBalance string `json:"starting_balance"`
}
type AccountCredited struct {
Base
base.Asset
Amount string `json:"amount"`
}
type AccountDebited struct {
Base
base.Asset
Amount string `json:"amount"`
}
type AccountThresholdsUpdated struct {
Base
LowThreshold int32 `json:"low_threshold"`
MedThreshold int32 `json:"med_threshold"`
HighThreshold int32 `json:"high_threshold"`
}
type AccountHomeDomainUpdated struct {
Base
HomeDomain string `json:"home_domain"`
}
type AccountFlagsUpdated struct {
Base
AuthRequired *bool `json:"auth_required_flag,omitempty"`
AuthRevokable *bool `json:"auth_revokable_flag,omitempty"`
}
type SignerCreated struct {
Base
Weight int32 `json:"weight"`
PublicKey string `json:"public_key"`
Key string `json:"key"`
}
type SignerRemoved struct {
Base
Weight int32 `json:"weight"`
PublicKey string `json:"public_key"`
Key string `json:"key"`
}
type SignerUpdated struct {
Base
Weight int32 `json:"weight"`
PublicKey string `json:"public_key"`
Key string `json:"key"`
}
type TrustlineCreated struct {
Base
base.Asset
Limit string `json:"limit"`
}
type TrustlineRemoved struct {
Base
base.Asset
Limit string `json:"limit"`
}
type TrustlineUpdated struct {
Base
base.Asset
Limit string `json:"limit"`
}
type TrustlineAuthorized struct {
Base
Trustor string `json:"trustor"`
AssetType string `json:"asset_type"`
AssetCode string `json:"asset_code,omitempty"`
}
type TrustlineDeauthorized struct {
Base
Trustor string `json:"trustor"`
AssetType string `json:"asset_type"`
AssetCode string `json:"asset_code,omitempty"`
}
type Trade struct {
Base
Seller string `json:"seller"`
OfferID int64 `json:"offer_id"`
SoldAmount string `json:"sold_amount"`
SoldAssetType string `json:"sold_asset_type"`
SoldAssetCode string `json:"sold_asset_code,omitempty"`
SoldAssetIssuer string `json:"sold_asset_issuer,omitempty"`
BoughtAmount string `json:"bought_amount"`
BoughtAssetType string `json:"bought_asset_type"`
BoughtAssetCode string `json:"bought_asset_code,omitempty"`
BoughtAssetIssuer string `json:"bought_asset_issuer,omitempty"`
}
// interface implementations
var _ base.Rehydratable = &SignerCreated{}
var _ base.Rehydratable = &SignerRemoved{}
var _ base.Rehydratable = &SignerUpdated{}