-
Notifications
You must be signed in to change notification settings - Fork 39
/
broadcast.go
61 lines (52 loc) · 1.62 KB
/
broadcast.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
package types
import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)
// SignatureKey --------------------------------------
type SignatureKey struct {
AccountNum uint64 `json:"account_num,omitempty"`
AccountSequence uint64 `json:"account_sequence,omitempty"`
Address string `json:"address,omitempty"`
PrivateKey []byte `json:"private_key,omitempty"`
Type int `json:"type,omitempty"`
}
// UnsignedMsgs --------------------------------------
type UnsignedMsgs struct {
Msgs []*UnsignedMsgBytes `json:"msgs,omitempty"`
}
// UnsignedMsg ---------------------------------------
type UnsignedMsg struct {
Msg *anypb.Any `json:"msg,omitempty"`
SignatureKeys []*SignatureKey `json:"signature_keys,omitempty"`
Type string `json:"type,omitempty"`
}
func (u *UnsignedMsg) ToBytes() (*UnsignedMsgBytes, error) {
msgBz, err := proto.Marshal(u.Msg)
if err != nil {
return nil, err
}
return &UnsignedMsgBytes{
Msg: msgBz,
SignatureKeys: u.SignatureKeys,
Type: u.Type,
}, nil
}
// UnsignedMsgBytes ----------------------------------
type UnsignedMsgBytes struct {
Msg []byte `json:"msg,omitempty"`
SignatureKeys []*SignatureKey `json:"signature_keys,omitempty"`
Type string `json:"type,omitempty"`
}
func (u *UnsignedMsgBytes) FromBytes() (*UnsignedMsg, error) {
msgAny := &anypb.Any{}
err := proto.Unmarshal(u.Msg, msgAny)
if err != nil {
return nil, err
}
return &UnsignedMsg{
Msg: msgAny,
SignatureKeys: u.SignatureKeys,
Type: u.Type,
}, nil
}