-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexport.go
More file actions
253 lines (218 loc) · 6.99 KB
/
export.go
File metadata and controls
253 lines (218 loc) · 6.99 KB
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
244
245
246
247
248
249
250
251
252
253
// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
/*
* Parts of this file were auto generated. Edit only those parts of
* the code inside of 'EXISTING_CODE' tags.
*/
package sdk
import (
// EXISTING_CODE
"encoding/json"
"fmt"
"strings"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/base"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/output"
"github.com/TrueBlocks/trueblocks-chifra/v6/pkg/types"
// EXISTING_CODE
)
type ExportOptions struct {
Addrs []string `json:"addrs,omitempty"`
Topics []string `json:"topics,omitempty"`
Fourbytes []string `json:"fourbytes,omitempty"`
Articulate bool `json:"articulate,omitempty"`
CacheTraces bool `json:"cacheTraces,omitempty"`
FirstRecord uint64 `json:"firstRecord,omitempty"`
MaxRecords uint64 `json:"maxRecords,omitempty"`
Relevant bool `json:"relevant,omitempty"`
Emitter []string `json:"emitter,omitempty"`
Topic []string `json:"topic,omitempty"`
Nfts bool `json:"nfts,omitempty"`
Reverted bool `json:"reverted,omitempty"`
Asset []string `json:"asset,omitempty"`
Flow ExportFlow `json:"flow,omitempty"`
Factory bool `json:"factory,omitempty"`
Unripe bool `json:"unripe,omitempty"`
Reversed bool `json:"reversed,omitempty"`
NoZero bool `json:"noZero,omitempty"`
FirstBlock base.Blknum `json:"firstBlock,omitempty"`
LastBlock base.Blknum `json:"lastBlock,omitempty"`
Accounting bool `json:"accounting,omitempty"`
RenderCtx *output.RenderCtx `json:"-"`
Globals
}
// String implements the stringer interface
func (opts ExportOptions) String() string {
bytes, _ := json.Marshal(opts)
return string(bytes)
}
// Export implements the chifra export command.
func (opts *ExportOptions) Export() ([]types.Transaction, *types.MetaData, error) {
in := opts.toInternal()
return queryExport[types.Transaction](in)
}
// ExportAppearances implements the chifra export --appearances command.
func (opts *ExportOptions) ExportAppearances() ([]types.Appearance, *types.MetaData, error) {
in := opts.toInternal()
in.Appearances = true
return queryExport[types.Appearance](in)
}
// ExportReceipts implements the chifra export --receipts command.
func (opts *ExportOptions) ExportReceipts() ([]types.Receipt, *types.MetaData, error) {
in := opts.toInternal()
in.Receipts = true
return queryExport[types.Receipt](in)
}
// ExportLogs implements the chifra export --logs command.
func (opts *ExportOptions) ExportLogs() ([]types.Log, *types.MetaData, error) {
in := opts.toInternal()
in.Logs = true
return queryExport[types.Log](in)
}
// ExportApprovals implements the chifra export --approvals command.
func (opts *ExportOptions) ExportApprovals() ([]types.Transaction, *types.MetaData, error) {
in := opts.toInternal()
in.Approvals = true
return queryExport[types.Transaction](in)
}
// ExportTraces implements the chifra export --traces command.
func (opts *ExportOptions) ExportTraces() ([]types.Trace, *types.MetaData, error) {
in := opts.toInternal()
in.Traces = true
return queryExport[types.Trace](in)
}
// ExportNeighbors implements the chifra export --neighbors command.
func (opts *ExportOptions) ExportNeighbors() ([]types.Message, *types.MetaData, error) {
in := opts.toInternal()
in.Neighbors = true
return queryExport[types.Message](in)
}
// ExportStatements implements the chifra export --statements command.
func (opts *ExportOptions) ExportStatements() ([]types.Statement, *types.MetaData, error) {
in := opts.toInternal()
in.Statements = true
return queryExport[types.Statement](in)
}
// ExportTransfers implements the chifra export --transfers command.
func (opts *ExportOptions) ExportTransfers() ([]types.Transfer, *types.MetaData, error) {
in := opts.toInternal()
in.Transfers = true
return queryExport[types.Transfer](in)
}
// ExportAssets implements the chifra export --assets command.
func (opts *ExportOptions) ExportAssets() ([]types.Name, *types.MetaData, error) {
in := opts.toInternal()
in.Assets = true
return queryExport[types.Name](in)
}
// ExportBalances implements the chifra export --balances command.
func (opts *ExportOptions) ExportBalances() ([]types.Token, *types.MetaData, error) {
in := opts.toInternal()
in.Balances = true
return queryExport[types.Token](in)
}
// ExportWithdrawals implements the chifra export --withdrawals command.
func (opts *ExportOptions) ExportWithdrawals() ([]types.Withdrawal, *types.MetaData, error) {
in := opts.toInternal()
in.Withdrawals = true
return queryExport[types.Withdrawal](in)
}
// ExportCount implements the chifra export --count command.
func (opts *ExportOptions) ExportCount() ([]types.Count, *types.MetaData, error) {
in := opts.toInternal()
in.Count = true
return queryExport[types.Count](in)
}
type ExportFlow int
const (
NoEF ExportFlow = 0
EFIn = 1 << iota
EFOut
EFZero
)
func (v ExportFlow) String() string {
switch v {
case NoEF:
return "none"
}
var m = map[ExportFlow]string{
EFIn: "in",
EFOut: "out",
EFZero: "zero",
}
var ret []string
for _, val := range []ExportFlow{EFIn, EFOut, EFZero} {
if v&val != 0 {
ret = append(ret, m[val])
}
}
return strings.Join(ret, ",")
}
func enumFromExportFlow(values []string) (ExportFlow, error) {
if len(values) == 0 {
return NoEF, fmt.Errorf("no value provided for flow option")
}
var result ExportFlow
for _, val := range values {
switch val {
case "in":
result |= EFIn
case "out":
result |= EFOut
case "zero":
result |= EFZero
default:
return NoEF, fmt.Errorf("unknown flow: %s", val)
}
}
return result, nil
}
// EXISTING_CODE
func SortStatements(statuses []types.Statement, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
func SortBalances(statuses []types.Token, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
func SortTransfers(statuses []types.Transfer, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
func SortWithdrawals(statuses []types.Withdrawal, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
func SortAssets(statuses []types.Statement, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
func SortLogs(statuses []types.Log, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
func SortTraces(statuses []types.Trace, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
func SortReceipts(statuses []types.Receipt, sortSpec SortSpec) error {
_ = statuses
_ = sortSpec
return nil
}
// ExportApprovalsLogs implements the chifra export --approvals command.
func (opts *ExportOptions) ExportApprovalsLogs() ([]types.Log, *types.MetaData, error) {
in := opts.toInternal()
in.Approvals = true
in.Logs = true
return queryExport[types.Log](in)
}
// EXISTING_CODE