-
Notifications
You must be signed in to change notification settings - Fork 1
/
when.go
85 lines (72 loc) · 2.39 KB
/
when.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
// 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"
"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 WhenOptions struct {
BlockIds []string `json:"blocks,omitempty"`
Truncate base.Blknum `json:"truncate,omitempty"`
Repair bool `json:"repair,omitempty"`
Check bool `json:"check,omitempty"`
Update bool `json:"update,omitempty"`
Deep bool `json:"deep,omitempty"`
RenderCtx *output.RenderCtx `json:"-"`
Globals
}
// String implements the stringer interface
func (opts WhenOptions) String() string {
bytes, _ := json.Marshal(opts)
return string(bytes)
}
// When implements the chifra when command.
func (opts *WhenOptions) When() ([]types.NamedBlock, *types.MetaData, error) {
in := opts.toInternal()
return queryWhen[types.NamedBlock](in)
}
// WhenList implements the chifra when --list command.
func (opts *WhenOptions) WhenList() ([]types.NamedBlock, *types.MetaData, error) {
in := opts.toInternal()
in.List = true
return queryWhen[types.NamedBlock](in)
}
// WhenTimestamps implements the chifra when --timestamps command.
func (opts *WhenOptions) WhenTimestamps() ([]types.Timestamp, *types.MetaData, error) {
in := opts.toInternal()
in.Timestamps = true
return queryWhen[types.Timestamp](in)
}
// WhenCount implements the chifra when --count command.
func (opts *WhenOptions) WhenCount() ([]types.Count, *types.MetaData, error) {
in := opts.toInternal()
in.Count = true
return queryWhen[types.Count](in)
}
// No enums
// EXISTING_CODE
func TsFromBlock(chain string, blockNum base.Blknum) (base.Timestamp, error) {
whenOpts := WhenOptions{
BlockIds: []string{fmt.Sprintf("%d", blockNum)},
Globals: Globals{
Chain: chain,
},
}
var err error
var when []types.NamedBlock
if when, _, err = whenOpts.When(); err != nil {
return 0, fmt.Errorf("error getting timestamp on chain %s: %w", chain, err)
}
return when[0].Timestamp, nil
}
// EXISTING_CODE