-
Notifications
You must be signed in to change notification settings - Fork 174
/
junction_v1.go
319 lines (249 loc) · 5.77 KB
/
junction_v1.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
//
// Copyright 2019 Centrifuge GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"github.com/centrifuge/go-substrate-rpc-client/v4/scale"
)
type JunctionV1 struct {
IsParachain bool
ParachainID UCompact
IsAccountID32 bool
AccountID32NetworkID NetworkID
AccountID []U8
IsAccountIndex64 bool
AccountIndex64NetworkID NetworkID
AccountIndex U64
IsAccountKey20 bool
AccountKey20NetworkID NetworkID
AccountKey []U8
IsPalletInstance bool
PalletIndex U8
IsGeneralIndex bool
GeneralIndex U128
IsGeneralKey bool
GeneralKey []U8
IsOnlyChild bool
IsPlurality bool
BodyID BodyID
BodyPart BodyPart
}
func (j *JunctionV1) Decode(decoder scale.Decoder) error {
b, err := decoder.ReadOneByte()
if err != nil {
return err
}
switch b {
case 0:
j.IsParachain = true
return decoder.Decode(&j.ParachainID)
case 1:
j.IsAccountID32 = true
if err := decoder.Decode(&j.AccountID32NetworkID); err != nil {
return nil
}
return decoder.Decode(&j.AccountID)
case 2:
j.IsAccountIndex64 = true
if err := decoder.Decode(&j.AccountIndex64NetworkID); err != nil {
return nil
}
return decoder.Decode(&j.AccountIndex)
case 3:
j.IsAccountKey20 = true
if err := decoder.Decode(&j.AccountKey20NetworkID); err != nil {
return nil
}
return decoder.Decode(&j.AccountKey)
case 4:
j.IsPalletInstance = true
return decoder.Decode(&j.PalletIndex)
case 5:
j.IsGeneralIndex = true
return decoder.Decode(&j.GeneralIndex)
case 6:
j.IsGeneralKey = true
return decoder.Decode(&j.GeneralKey)
case 7:
j.IsOnlyChild = true
case 8:
j.IsPlurality = true
if err := decoder.Decode(&j.BodyID); err != nil {
return err
}
return decoder.Decode(&j.BodyPart)
}
return nil
}
func (j JunctionV1) Encode(encoder scale.Encoder) error { //nolint:funlen
switch {
case j.IsParachain:
if err := encoder.PushByte(0); err != nil {
return err
}
return encoder.Encode(j.ParachainID)
case j.IsAccountID32:
if err := encoder.PushByte(1); err != nil {
return err
}
if err := encoder.Encode(j.AccountID32NetworkID); err != nil {
return err
}
return encoder.Encode(j.AccountID)
case j.IsAccountIndex64:
if err := encoder.PushByte(2); err != nil {
return err
}
if err := encoder.Encode(j.AccountIndex64NetworkID); err != nil {
return err
}
return encoder.Encode(j.AccountIndex)
case j.IsAccountKey20:
if err := encoder.PushByte(3); err != nil {
return err
}
if err := encoder.Encode(j.AccountKey20NetworkID); err != nil {
return err
}
return encoder.Encode(j.AccountKey)
case j.IsPalletInstance:
if err := encoder.PushByte(4); err != nil {
return err
}
return encoder.Encode(j.PalletIndex)
case j.IsGeneralIndex:
if err := encoder.PushByte(5); err != nil {
return err
}
return encoder.Encode(j.GeneralIndex)
case j.IsGeneralKey:
if err := encoder.PushByte(6); err != nil {
return err
}
return encoder.Encode(j.GeneralKey)
case j.IsOnlyChild:
return encoder.PushByte(7)
case j.IsPlurality:
if err := encoder.PushByte(8); err != nil {
return err
}
if err := encoder.Encode(j.BodyID); err != nil {
return err
}
return encoder.Encode(j.BodyPart)
}
return nil
}
type JunctionsV1 struct {
IsHere bool
IsX1 bool
X1 JunctionV1
IsX2 bool
X2 [2]JunctionV1
IsX3 bool
X3 [3]JunctionV1
IsX4 bool
X4 [4]JunctionV1
IsX5 bool
X5 [5]JunctionV1
IsX6 bool
X6 [6]JunctionV1
IsX7 bool
X7 [7]JunctionV1
IsX8 bool
X8 [8]JunctionV1
}
func (j *JunctionsV1) Decode(decoder scale.Decoder) error { //nolint:dupl
b, err := decoder.ReadOneByte()
if err != nil {
return err
}
switch b {
case 0:
j.IsHere = true
case 1:
j.IsX1 = true
return decoder.Decode(&j.X1)
case 2:
j.IsX2 = true
return decoder.Decode(&j.X2)
case 3:
j.IsX3 = true
return decoder.Decode(&j.X3)
case 4:
j.IsX4 = true
return decoder.Decode(&j.X4)
case 5:
j.IsX5 = true
return decoder.Decode(&j.X5)
case 6:
j.IsX6 = true
return decoder.Decode(&j.X6)
case 7:
j.IsX7 = true
return decoder.Decode(&j.X7)
case 8:
j.IsX8 = true
return decoder.Decode(&j.X8)
}
return nil
}
func (j JunctionsV1) Encode(encoder scale.Encoder) error {
switch {
case j.IsHere:
return encoder.PushByte(0)
case j.IsX1:
if err := encoder.PushByte(1); err != nil {
return err
}
return encoder.Encode(j.X1)
case j.IsX2:
if err := encoder.PushByte(2); err != nil {
return err
}
return encoder.Encode(j.X2)
case j.IsX3:
if err := encoder.PushByte(3); err != nil {
return err
}
return encoder.Encode(j.X3)
case j.IsX4:
if err := encoder.PushByte(4); err != nil {
return err
}
return encoder.Encode(j.X4)
case j.IsX5:
if err := encoder.PushByte(5); err != nil {
return err
}
return encoder.Encode(j.X5)
case j.IsX6:
if err := encoder.PushByte(6); err != nil {
return err
}
return encoder.Encode(j.X6)
case j.IsX7:
if err := encoder.PushByte(7); err != nil {
return err
}
return encoder.Encode(j.X7)
case j.IsX8:
if err := encoder.PushByte(8); err != nil {
return err
}
return encoder.Encode(j.X8)
}
return nil
}