-
Notifications
You must be signed in to change notification settings - Fork 38
/
list_results.go
150 lines (115 loc) · 4.42 KB
/
list_results.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
package audit
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// ListResultsArgs groups the arguments
// of "list all audit result IDs" test invoke call.
type ListResultsArgs struct{}
// ListResultsByEpochArgs groups the arguments
// of "list audit result IDs by epoch" test invoke call.
type ListResultsByEpochArgs struct {
epoch int64
}
// ListResultsByCIDArgs groups the arguments
// of "list audit result IDs by epoch and CID" test invoke call.
type ListResultsByCIDArgs struct {
ListResultsByEpochArgs
cid []byte
}
// ListResultsByNodeArgs groups the arguments
// of "list audit result IDs by epoch, CID, and node key" test invoke call.
type ListResultsByNodeArgs struct {
ListResultsByCIDArgs
nodeKey []byte
}
// ListResultsValues groups the stack parameters
// returned by "list audit results" test invoke.
type ListResultsValues struct {
rawResults [][]byte // audit results in a binary format
}
// RawResults returns list of audit result IDs
// in a binary format.
func (v *ListResultsValues) RawResults() [][]byte {
return v.rawResults
}
// SetEpoch sets epoch of listing audit results.
func (v *ListResultsByEpochArgs) SetEpoch(epoch int64) {
v.epoch = epoch
}
// SetCID sets container ID of listing audit results.
func (v *ListResultsByCIDArgs) SetCID(cid []byte) {
v.cid = cid
}
// SetNodeKey sets public key of node that produced listing audit results.
func (v *ListResultsByNodeArgs) SetNodeKey(key []byte) {
v.nodeKey = key
}
// ListAuditResults performs the test invoke of "list all audit result IDs"
// method of NeoFS Audit contract.
func (c *Client) ListAuditResults(args ListResultsArgs) (*ListResultsValues, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(c.listResultsMethod)
items, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listResultsMethod, err)
}
return parseAuditResults(items, c.listResultsMethod)
}
// ListAuditResultsByEpoch performs the test invoke of "list audit result IDs
// by epoch" method of NeoFS Audit contract.
func (c *Client) ListAuditResultsByEpoch(args ListResultsByEpochArgs) (*ListResultsValues, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(c.listByEpochResultsMethod)
invokePrm.SetArgs(args.epoch)
items, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByEpochResultsMethod, err)
}
return parseAuditResults(items, c.listByEpochResultsMethod)
}
// ListAuditResultsByCID performs the test invoke of "list audit result IDs
// by epoch and CID" method of NeoFS Audit contract.
func (c *Client) ListAuditResultsByCID(args ListResultsByCIDArgs) (*ListResultsValues, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(c.listByCIDResultsMethod)
invokePrm.SetArgs(args.epoch, args.cid)
items, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByCIDResultsMethod, err)
}
return parseAuditResults(items, c.listByCIDResultsMethod)
}
// ListAuditResultsByNode performs the test invoke of "list audit result IDs
// by epoch, CID, and node key" method of NeoFS Audit contract.
func (c *Client) ListAuditResultsByNode(args ListResultsByNodeArgs) (*ListResultsValues, error) {
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(c.listByNodeResultsMethod)
invokePrm.SetArgs(args.epoch, args.cid, args.nodeKey)
items, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", c.listByNodeResultsMethod, err)
}
return parseAuditResults(items, c.listByNodeResultsMethod)
}
func parseAuditResults(items []stackitem.Item, method string) (*ListResultsValues, error) {
if ln := len(items); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln)
}
items, err := client.ArrayFromStackItem(items[0])
if err != nil {
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", method, err)
}
res := &ListResultsValues{
rawResults: make([][]byte, 0, len(items)),
}
for i := range items {
rawRes, err := client.BytesFromStackItem(items[i])
if err != nil {
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", method, err)
}
res.rawResults = append(res.rawResults, rawRes)
}
return res, nil
}