-
Notifications
You must be signed in to change notification settings - Fork 1
/
blocks.go
149 lines (126 loc) · 3.81 KB
/
blocks.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
// 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/output"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
// EXISTING_CODE
)
type BlocksOptions struct {
BlockIds []string `json:"blocks,omitempty"`
Flow BlocksFlow `json:"flow,omitempty"`
Emitter []string `json:"emitter,omitempty"`
Topic []string `json:"topic,omitempty"`
Articulate bool `json:"articulate,omitempty"`
CacheTxs bool `json:"cacheTxs,omitempty"`
CacheTraces bool `json:"cacheTraces,omitempty"`
RenderCtx *output.RenderCtx `json:"-"`
Globals
}
// String implements the stringer interface
func (opts BlocksOptions) String() string {
bytes, _ := json.Marshal(opts)
return string(bytes)
}
// Blocks implements the chifra blocks command.
func (opts *BlocksOptions) Blocks() ([]types.Block, *types.MetaData, error) {
in := opts.toInternal()
return queryBlocks[types.Block](in)
}
// BlocksHashes implements the chifra blocks --hashes command.
func (opts *BlocksOptions) BlocksHashes() ([]types.LightBlock, *types.MetaData, error) {
in := opts.toInternal()
in.Hashes = true
return queryBlocks[types.LightBlock](in)
}
// BlocksUncles implements the chifra blocks --uncles command.
func (opts *BlocksOptions) BlocksUncles() ([]types.LightBlock, *types.MetaData, error) {
in := opts.toInternal()
in.Uncles = true
return queryBlocks[types.LightBlock](in)
}
// BlocksTraces implements the chifra blocks --traces command.
func (opts *BlocksOptions) BlocksTraces() ([]types.Trace, *types.MetaData, error) {
in := opts.toInternal()
in.Traces = true
return queryBlocks[types.Trace](in)
}
// BlocksUniq implements the chifra blocks --uniq command.
func (opts *BlocksOptions) BlocksUniq() ([]types.Appearance, *types.MetaData, error) {
in := opts.toInternal()
in.Uniq = true
return queryBlocks[types.Appearance](in)
}
// BlocksLogs implements the chifra blocks --logs command.
func (opts *BlocksOptions) BlocksLogs() ([]types.Log, *types.MetaData, error) {
in := opts.toInternal()
in.Logs = true
return queryBlocks[types.Log](in)
}
// BlocksWithdrawals implements the chifra blocks --withdrawals command.
func (opts *BlocksOptions) BlocksWithdrawals() ([]types.Withdrawal, *types.MetaData, error) {
in := opts.toInternal()
in.Withdrawals = true
return queryBlocks[types.Withdrawal](in)
}
// BlocksCount implements the chifra blocks --count command.
func (opts *BlocksOptions) BlocksCount() ([]types.BlockCount, *types.MetaData, error) {
in := opts.toInternal()
in.Count = true
return queryBlocks[types.BlockCount](in)
}
type BlocksFlow int
const (
NoBF BlocksFlow = 0
BFFrom = 1 << iota
BFTo
BFReward
)
func (v BlocksFlow) String() string {
switch v {
case NoBF:
return "none"
}
var m = map[BlocksFlow]string{
BFFrom: "from",
BFTo: "to",
BFReward: "reward",
}
var ret []string
for _, val := range []BlocksFlow{BFFrom, BFTo, BFReward} {
if v&val != 0 {
ret = append(ret, m[val])
}
}
return strings.Join(ret, ",")
}
func enumFromBlocksFlow(values []string) (BlocksFlow, error) {
if len(values) == 0 {
return NoBF, fmt.Errorf("no value provided for flow option")
}
var result BlocksFlow
for _, val := range values {
switch val {
case "from":
result |= BFFrom
case "to":
result |= BFTo
case "reward":
result |= BFReward
default:
return NoBF, fmt.Errorf("unknown flow: %s", val)
}
}
return result, nil
}
// EXISTING_CODE
// EXISTING_CODE