/
blindinout.go
116 lines (96 loc) · 3.01 KB
/
blindinout.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
package types
//go:generate ffjson $GOFILE
import (
"github.com/denkhaus/bitshares/util"
"github.com/juju/errors"
)
type StealthConfirmation struct {
// struct memo_data
// {
// optional<public_key_type> from;
// asset amount;
// fc::sha256 blinding_factor;
// fc::ecc::commitment_type commitment;
// uint32_t check = 0;
// };
// (from)(amount)(blinding_factor)(commitment)(check)
OneTimeKey PublicKey `json:"one_time_key"`
To *PublicKey `json:"to,omitempty"`
EncryptedMemo Buffer `json:"encrypted_memo"`
}
func (p StealthConfirmation) Marshal(enc *util.TypeEncoder) error {
if err := enc.Encode(p.OneTimeKey); err != nil {
return errors.Annotate(err, "encode OneTimeKey")
}
if err := enc.Encode(p.To != nil); err != nil {
return errors.Annotate(err, "encode has To")
}
if err := enc.Encode(p.To); err != nil {
return errors.Annotate(err, "encode To")
}
if err := enc.Encode(p.EncryptedMemo); err != nil {
return errors.Annotate(err, "encode EncryptedMemo")
}
return nil
}
type BlindOutputs []BlindOutput
func (p BlindOutputs) Marshal(enc *util.TypeEncoder) error {
if err := enc.EncodeUVarint(uint64(len(p))); err != nil {
return errors.Annotate(err, "encode length")
}
for _, o := range p {
if err := enc.Encode(o); err != nil {
return errors.Annotate(err, "encode Output")
}
}
return nil
}
type BlindOutput struct {
Commitment FixedBuffer `json:"commitment"`
Owner Authority `json:"owner"`
RangeProof Buffer `json:"range_proof"`
StealthConfirmation *StealthConfirmation `json:"stealth_memo,omitempty"`
}
func (p BlindOutput) Marshal(enc *util.TypeEncoder) error {
if err := enc.Encode(p.Commitment); err != nil {
return errors.Annotate(err, "encode Commitment")
}
if err := enc.Encode(p.RangeProof); err != nil {
return errors.Annotate(err, "encode RangeProof")
}
if err := enc.Encode(p.Owner); err != nil {
return errors.Annotate(err, "encode Owner")
}
if err := enc.Encode(p.StealthConfirmation != nil); err != nil {
return errors.Annotate(err, "encode has StealthConfirmation")
}
if err := enc.Encode(p.StealthConfirmation); err != nil {
return errors.Annotate(err, "encode StealthConfirmation")
}
return nil
}
type BlindInputs []BlindInput
func (p BlindInputs) Marshal(enc *util.TypeEncoder) error {
if err := enc.EncodeUVarint(uint64(len(p))); err != nil {
return errors.Annotate(err, "encode length")
}
for _, o := range p {
if err := enc.Encode(o); err != nil {
return errors.Annotate(err, "encode Input")
}
}
return nil
}
type BlindInput struct {
Commitment FixedBuffer `json:"commitment"`
Owner Authority `json:"owner"`
}
func (p BlindInput) Marshal(enc *util.TypeEncoder) error {
if err := enc.Encode(p.Commitment); err != nil {
return errors.Annotate(err, "encode Commitment")
}
if err := enc.Encode(p.Owner); err != nil {
return errors.Annotate(err, "encode Owner")
}
return nil
}