-
Notifications
You must be signed in to change notification settings - Fork 15
/
chainid.go
50 lines (39 loc) · 1.05 KB
/
chainid.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
package query
import (
"fmt"
"github.com/AccumulateNetwork/accumulate/types"
"github.com/AccumulateNetwork/accumulate/types/state"
)
type RequestByChainId struct {
ChainId types.Bytes32
}
type ResponseByChainId struct {
state.Object
}
func (*RequestByChainId) Type() types.QueryType { return types.QueryTypeChainId }
func (r *RequestByChainId) MarshalBinary() ([]byte, error) {
return r.ChainId[:], nil
}
func (r *RequestByChainId) UnmarshalBinary(data []byte) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("error unmarshaling RequestByChainId data %v", r)
}
}()
if len(data) < 32 {
return fmt.Errorf("insufficient data for chain id")
}
r.ChainId.FromBytes(data)
return nil
}
func (r *ResponseByChainId) MarshalBinary() ([]byte, error) {
return r.Object.MarshalBinary()
}
func (r *ResponseByChainId) UnmarshalBinary(data []byte) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("error unmarshaling ResponseByChainId data %v", r)
}
}()
return r.Object.UnmarshalBinary(data)
}