forked from centrifuge/go-substrate-rpc-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option_uint.go
185 lines (151 loc) · 4.82 KB
/
option_uint.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
// Copyright (C) 2019 Centrifuge GmbH
//
// This file is part of Go Substrate RPC Client (GSRPC).
//
// GSRPC is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GSRPC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package types
import "github.com/centrifuge/go-substrate-rpc-client/scale"
// OptionU8 is a structure that can store a U8 or a missing value
type OptionU8 struct {
option
value U8
}
// NewOptionU8 creates an OptionU8 with a value
func NewOptionU8(value U8) OptionU8 {
return OptionU8{option{true}, value}
}
// NewOptionU8Empty creates an OptionU8 without a value
func NewOptionU8Empty() OptionU8 {
return OptionU8{option: option{false}}
}
func (o OptionU8) Encode(encoder scale.Encoder) error {
return encoder.EncodeOption(o.hasValue, o.value)
}
func (o *OptionU8) Decode(decoder scale.Decoder) error {
return decoder.DecodeOption(&o.hasValue, &o.value)
}
// SetSome sets a value
func (o *OptionU8) SetSome(value U8) {
o.hasValue = true
o.value = value
}
// SetNone removes a value and marks it as missing
func (o *OptionU8) SetNone() {
o.hasValue = false
o.value = U8(0)
}
// Unwrap returns a flag that indicates whether a value is present and the stored value
func (o OptionU8) Unwrap() (ok bool, value U8) {
return o.hasValue, o.value
}
// OptionU16 is a structure that can store a U16 or a missing value
type OptionU16 struct {
option
value U16
}
// NewOptionU16 creates an OptionU16 with a value
func NewOptionU16(value U16) OptionU16 {
return OptionU16{option{true}, value}
}
// NewOptionU16Empty creates an OptionU16 without a value
func NewOptionU16Empty() OptionU16 {
return OptionU16{option: option{false}}
}
func (o OptionU16) Encode(encoder scale.Encoder) error {
return encoder.EncodeOption(o.hasValue, o.value)
}
func (o *OptionU16) Decode(decoder scale.Decoder) error {
return decoder.DecodeOption(&o.hasValue, &o.value)
}
// SetSome sets a value
func (o *OptionU16) SetSome(value U16) {
o.hasValue = true
o.value = value
}
// SetNone removes a value and marks it as missing
func (o *OptionU16) SetNone() {
o.hasValue = false
o.value = U16(0)
}
// Unwrap returns a flag that indicates whether a value is present and the stored value
func (o OptionU16) Unwrap() (ok bool, value U16) {
return o.hasValue, o.value
}
// OptionU32 is a structure that can store a U32 or a missing value
type OptionU32 struct {
option
value U32
}
// NewOptionU32 creates an OptionU32 with a value
func NewOptionU32(value U32) OptionU32 {
return OptionU32{option{true}, value}
}
// NewOptionU32Empty creates an OptionU32 without a value
func NewOptionU32Empty() OptionU32 {
return OptionU32{option: option{false}}
}
func (o OptionU32) Encode(encoder scale.Encoder) error {
return encoder.EncodeOption(o.hasValue, o.value)
}
func (o *OptionU32) Decode(decoder scale.Decoder) error {
return decoder.DecodeOption(&o.hasValue, &o.value)
}
// SetSome sets a value
func (o *OptionU32) SetSome(value U32) {
o.hasValue = true
o.value = value
}
// SetNone removes a value and marks it as missing
func (o *OptionU32) SetNone() {
o.hasValue = false
o.value = U32(0)
}
// Unwrap returns a flag that indicates whether a value is present and the stored value
func (o OptionU32) Unwrap() (ok bool, value U32) {
return o.hasValue, o.value
}
// OptionU64 is a structure that can store a U64 or a missing value
type OptionU64 struct {
option
value U64
}
// NewOptionU64 creates an OptionU64 with a value
func NewOptionU64(value U64) OptionU64 {
return OptionU64{option{true}, value}
}
// NewOptionU64Empty creates an OptionU64 without a value
func NewOptionU64Empty() OptionU64 {
return OptionU64{option: option{false}}
}
func (o OptionU64) Encode(encoder scale.Encoder) error {
return encoder.EncodeOption(o.hasValue, o.value)
}
func (o *OptionU64) Decode(decoder scale.Decoder) error {
return decoder.DecodeOption(&o.hasValue, &o.value)
}
// SetSome sets a value
func (o *OptionU64) SetSome(value U64) {
o.hasValue = true
o.value = value
}
// SetNone removes a value and marks it as missing
func (o *OptionU64) SetNone() {
o.hasValue = false
o.value = U64(0)
}
// Unwrap returns a flag that indicates whether a value is present and the stored value
func (o OptionU64) Unwrap() (ok bool, value U64) {
return o.hasValue, o.value
}