-
Notifications
You must be signed in to change notification settings - Fork 1
/
export.go
177 lines (152 loc) · 5.12 KB
/
export.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
// 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-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
// EXISTING_CODE
)
type ExportOptions struct {
Addrs []string `json:"addrs,omitempty"`
Topics []string `json:"topics,omitempty"`
Fourbytes []string `json:"fourbytes,omitempty"`
Accounting bool `json:"accounting,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"`
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"`
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)
}
// 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)
}
// ExportBalances implements the chifra export --balances command.
func (opts *ExportOptions) ExportBalances() ([]types.State, *types.MetaData, error) {
in := opts.toInternal()
in.Balances = true
return queryExport[types.State](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.Monitor, *types.MetaData, error) {
in := opts.toInternal()
in.Count = true
return queryExport[types.Monitor](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
// EXISTING_CODE