/
ProposalKinds.ts
771 lines (627 loc) · 22.4 KB
/
ProposalKinds.ts
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
import { Transaction, utils } from 'ethers';
import { hexToU8a, u8aToHex } from '@polkadot/util';
import { BE } from './index.js';
import { ProposalHeader } from './ProposalHeader.js';
import { ResourceId } from './ResourceId.js';
export interface IEVMProposal {
readonly chainId: number;
readonly nonce: number;
readonly tx: Transaction
}
export class EVMProposal implements IEVMProposal {
readonly chainId: number;
readonly nonce: number;
readonly tx: Transaction;
constructor (
chainId: number,
nonce: number,
tx: Transaction
) {
this.chainId = chainId;
this.nonce = nonce;
this.tx = tx;
}
static fromBytes (bytes: Uint8Array): EVMProposal {
const tx = utils.parseTransaction(bytes);
const chainId = tx.chainId || 0;
const nonce = tx.nonce;
return new EVMProposal(chainId, nonce, tx);
}
toU8a (): Uint8Array {
const serialized = utils.serializeTransaction(this.tx);
return hexToU8a(serialized);
}
}
export interface IRefreshVoteProposal {
readonly nonce: number;
readonly publicKey: string;
}
export class RefreshVoteProposal implements IRefreshVoteProposal {
nonce: number;
publicKey: string;
constructor (
nonce: number,
publicKey: string
) {
this.nonce = nonce;
this.publicKey = publicKey;
}
toU8a (): Uint8Array {
const publicKey = hexToU8a(this.publicKey);
const nonceBytes = new Uint8Array(4);
const dataView = new DataView(nonceBytes.buffer);
dataView.setUint32(this.nonce, 0, BE);
return new Uint8Array([...nonceBytes, ...publicKey]);
}
static fromBytes (bytes: Uint8Array): RefreshVoteProposal {
const dataView = new DataView(bytes.buffer);
const nonce = dataView.getUint32(0, BE);
const publicKey = bytes.slice(4, bytes.length);
return new RefreshVoteProposal(nonce, u8aToHex(publicKey));
}
}
export interface IAnchorCreateProposal {
readonly header: ProposalHeader;
readonly encodedCall: string;
}
export class AnchorCreateProposal implements IAnchorCreateProposal {
header: ProposalHeader;
encodedCall: string;
constructor (header: ProposalHeader, encodedCall: string) {
this.header = header;
this.encodedCall = encodedCall;
}
static fromBytes (bytes: Uint8Array): AnchorCreateProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const encodedCall = u8aToHex(bytes.slice(40, bytes.length));
return new AnchorCreateProposal(header, encodedCall);
}
toU8a (): Uint8Array {
const header = this.header.toU8a();
const encodedCall = hexToU8a(this.encodedCall);
return new Uint8Array([...header, ...encodedCall]);
}
}
export interface IProposerSetUpdateProposal {
readonly merkleRoot: string;
readonly averageSessionLength: bigint;
readonly numberOfProposers: number;
readonly nonce: number;
}
export class ProposerSetUpdateProposal implements IProposerSetUpdateProposal {
merkleRoot: string;
averageSessionLength: bigint;
numberOfProposers: number;
nonce: number;
constructor (
merkleRoot: string,
averageSessionLength: bigint,
numberOfProposers: number,
nonce: number
) {
this.averageSessionLength = averageSessionLength;
this.merkleRoot = merkleRoot;
this.nonce = nonce;
this.numberOfProposers = numberOfProposers;
}
static fromBytes (bytes: Uint8Array): ProposerSetUpdateProposal {
const merkleRoot = u8aToHex(bytes.slice(0, 32));
const dataView = new DataView(bytes.buffer);
const averageSessionLength = dataView.getBigUint64(32, BE);
const numberOfProposers = dataView.getUint32(32 + 8, BE);
const nonce = dataView.getUint32(32 + 12, BE);
return new ProposerSetUpdateProposal(merkleRoot, averageSessionLength, numberOfProposers, nonce);
}
toU8a (): Uint8Array {
const merkleRootBytesLength = 32;
const proposerSetUpdate = new Uint8Array(8 + 4 + 4);
const merkleRoot = hexToU8a(this.merkleRoot, merkleRootBytesLength * 8);
const dataView = new DataView(proposerSetUpdate.buffer);
dataView.setBigUint64(0, this.averageSessionLength, BE);
dataView.setUint32(8, this.numberOfProposers, BE);
dataView.setUint32(8 + 4, this.nonce, BE);
return new Uint8Array([...merkleRoot, ...proposerSetUpdate]);
}
}
export interface IAnchorUpdateProposal {
/**
* The Anchor Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 32 bytes Hex-encoded string of the `merkleRoot`.
*/
readonly merkleRoot: string;
/**
* 32 bytes Hex-encoded string of the `srcResourceId`.
*/
readonly srcResourceId: ResourceId;
}
export class AnchorUpdateProposal implements IAnchorUpdateProposal {
header: ProposalHeader;
merkleRoot: string;
srcResourceId: ResourceId;
constructor (header: ProposalHeader, merkleRoot: string, srcResourceId: ResourceId) {
this.header = header;
this.merkleRoot = merkleRoot;
this.srcResourceId = srcResourceId;
}
static fromBytes (bytes: Uint8Array): AnchorUpdateProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const merkleRoot = u8aToHex(bytes.slice(40, 72));
const srcResourceId = ResourceId.fromBytes(bytes.slice(72, 104));
return new AnchorUpdateProposal(header, merkleRoot, srcResourceId);
}
toU8a (): Uint8Array {
const merkleRootBytesLength = 32;
const rIdBytesLength = 32;
const header = this.header.toU8a();
const updateProposal = new Uint8Array(header.length + merkleRootBytesLength + rIdBytesLength);
updateProposal.set(header, 0); // 0 -> 40
const merkleRoot = hexToU8a(this.merkleRoot, merkleRootBytesLength * 8);
updateProposal.set(merkleRoot, 40); // 40 -> 72
updateProposal.set(this.srcResourceId.toU8a(), 72); // 72 -> 104
return updateProposal;
}
}
export interface ITokenAddProposal {
/**
* The Token Add Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly newTokenAddress: string;
}
export class TokenAddProposal implements ITokenAddProposal {
header: ProposalHeader;
newTokenAddress: string;
constructor (header: ProposalHeader, newTokenAddress: string) {
this.header = header;
this.newTokenAddress = newTokenAddress;
}
static fromBytes (bytes: Uint8Array): TokenAddProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const newTokenAddress = u8aToHex(bytes.slice(40, 60));
return new TokenAddProposal(header, newTokenAddress);
}
toU8a (): Uint8Array {
const header = this.header.toU8a();
const addressBytesLength = 20;
const tokenAddProposal = new Uint8Array(header.length + 20);
tokenAddProposal.set(header, 0); // 0 -> 40
tokenAddProposal.set(hexToU8a(this.newTokenAddress, addressBytesLength * 8), 40); // 40 -> 60
return tokenAddProposal;
}
}
export interface ITokenRemoveProposal {
/**
* The Token Remove Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly removeTokenAddress: string;
}
export class TokenRemoveProposal implements ITokenRemoveProposal {
header: ProposalHeader;
removeTokenAddress: string;
constructor (header: ProposalHeader, removeTokenAddress: string) {
this.header = header;
this.removeTokenAddress = removeTokenAddress;
}
static fromBytes (bytes: Uint8Array): TokenRemoveProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const removeTokenAddress = u8aToHex(bytes.slice(40, 60));
return new TokenRemoveProposal(header, removeTokenAddress);
}
toU8a (): Uint8Array {
const header = this.header.toU8a();
const addressBytesLength = 20;
const tokenRemoveProposal = new Uint8Array(header.length + addressBytesLength);
tokenRemoveProposal.set(header, 0); // 0 -> 40
tokenRemoveProposal.set(hexToU8a(this.removeTokenAddress, addressBytesLength * 8), 40); // 40 -> 60
return tokenRemoveProposal;
}
}
export interface IWrappingFeeUpdateProposal {
/**
* The Wrapping Fee Update Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 2 byte Hex-encoded string.
*/
readonly newFee: string;
}
export class WrappingFeeUpdateProposal implements IWrappingFeeUpdateProposal {
header: ProposalHeader;
newFee: string;
constructor (header: ProposalHeader, newFee: string) {
this.header = header;
this.newFee = newFee;
}
static fromBytes (bytes: Uint8Array): WrappingFeeUpdateProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const newFee = u8aToHex(bytes.slice(40, 42));
return new WrappingFeeUpdateProposal(header, newFee);
}
toU8a (): Uint8Array {
const newFeeBytesLength = 2;
const header = this.header.toU8a();
const wrappingFeeUpdateProposal = new Uint8Array(header.length + newFeeBytesLength);
wrappingFeeUpdateProposal.set(header, 0); // 0 -> 40
wrappingFeeUpdateProposal.set(hexToU8a(this.newFee, newFeeBytesLength * 8), 40); // 40 -> 42
return wrappingFeeUpdateProposal;
}
}
export interface IMinWithdrawalLimitProposal {
/**
* The Wrapping Fee Update Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 32 bytes Hex-encoded string.
*/
readonly minWithdrawalLimitBytes: string;
}
export class MinWithdrawalLimitProposal implements IMinWithdrawalLimitProposal {
header: ProposalHeader;
minWithdrawalLimitBytes: string;
constructor (header: ProposalHeader, minWithdrawalLimitBytes: string) {
this.header = header;
this.minWithdrawalLimitBytes = minWithdrawalLimitBytes;
}
static fromBytes (bytes: Uint8Array): MinWithdrawalLimitProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const minWithdrawalLimitBytes = u8aToHex(bytes.slice(40, 72));
return new MinWithdrawalLimitProposal(header, minWithdrawalLimitBytes);
}
toU8a (): Uint8Array {
const limitBytesLength = 32;
const header = this.header.toU8a();
const minWithdrawalLimitProposal = new Uint8Array(header.length + limitBytesLength);
minWithdrawalLimitProposal.set(header, 0); // 0 -> 40
minWithdrawalLimitProposal.set(hexToU8a(this.minWithdrawalLimitBytes, limitBytesLength * 8), 40); // 40 -> 72
return minWithdrawalLimitProposal;
}
}
export interface IMaxDepositLimitProposal {
/**
* The Wrapping Fee Update Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 32 bytes Hex-encoded string.
*/
readonly maxDepositLimitBytes: string;
}
export class MaxDepositLimitProposal implements IMaxDepositLimitProposal {
header: ProposalHeader;
maxDepositLimitBytes: string;
constructor (header: ProposalHeader, maxDepositLimitBytes: string) {
this.header = header;
this.maxDepositLimitBytes = maxDepositLimitBytes;
}
static fromBytes (bytes: Uint8Array): MaxDepositLimitProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const maxDepositLimitBytes = u8aToHex(bytes.slice(40, 72));
return new MaxDepositLimitProposal(header, maxDepositLimitBytes);
}
toU8a (): Uint8Array {
const limitBytesLength = 32;
const header = this.header.toU8a();
const maxDepositLimitProposal = new Uint8Array(header.length + limitBytesLength);
maxDepositLimitProposal.set(header, 0); // 0 -> 40
maxDepositLimitProposal.set(hexToU8a(this.maxDepositLimitBytes, limitBytesLength * 8), 40); // 40 -> 72
return maxDepositLimitProposal;
}
}
export interface IResourceIdUpdateProposal {
/**
* The ResourceIdUpdateProposal Header.
*/
readonly header: ProposalHeader;
/**
* 32 bytes Hex-encoded string.
*/
readonly newResourceId: string;
/**
* 20 bytes Hex-encoded string.
*/
readonly handlerAddress: string;
}
export class ResourceIdUpdateProposal implements IResourceIdUpdateProposal {
header: ProposalHeader;
newResourceId: string;
handlerAddress: string;
constructor (header: ProposalHeader, newResourceId: string, handlerAddress: string) {
this.header = header;
this.newResourceId = newResourceId;
this.handlerAddress = handlerAddress;
}
static fromBytes (bytes: Uint8Array): ResourceIdUpdateProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const newResourceId = u8aToHex(bytes.slice(40, 72));
const handlerAddress = u8aToHex(bytes.slice(72, 92));
return new ResourceIdUpdateProposal(header, newResourceId, handlerAddress);
}
toU8a (): Uint8Array {
const rIdBytesLength = 32;
const addressBytesLength = 20;
const header = this.header.toU8a();
const resourceIdUpdateProposal = new Uint8Array(header.length + rIdBytesLength + addressBytesLength);
resourceIdUpdateProposal.set(header, 0); // 0 -> 40
resourceIdUpdateProposal.set(hexToU8a(this.newResourceId, rIdBytesLength * 8), 40); // 40 -> 72
resourceIdUpdateProposal.set(hexToU8a(this.handlerAddress, addressBytesLength * 8), 72); // 72 -> 92
return resourceIdUpdateProposal;
}
}
export interface ISetTreasuryHandlerProposal {
/**
* The Token Add Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly newTreasuryHandler: string;
}
export class SetTreasuryHandlerProposal implements ISetTreasuryHandlerProposal {
header: ProposalHeader;
newTreasuryHandler: string;
constructor (header: ProposalHeader, newTreasuryHandler: string) {
this.header = header;
this.newTreasuryHandler = newTreasuryHandler;
}
static fromBytes (bytes: Uint8Array): SetTreasuryHandlerProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const newTreasuryHandler = u8aToHex(bytes.slice(40, 60));
return new SetTreasuryHandlerProposal(header, newTreasuryHandler);
}
toU8a (): Uint8Array {
const addressBytesLength = 20;
const header = this.header.toU8a();
const setTreasuryHandlerProposal = new Uint8Array(header.length + addressBytesLength);
setTreasuryHandlerProposal.set(header, 0); // 0 -> 40
setTreasuryHandlerProposal.set(hexToU8a(this.newTreasuryHandler, addressBytesLength * 8), 40); // 40 -> 60
return setTreasuryHandlerProposal;
}
}
export interface ISetVerifierProposal {
/**
* The Token Add Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly newVerifier: string;
}
export class SetVerifierProposal implements ISetVerifierProposal {
header: ProposalHeader;
newVerifier: string;
constructor (header: ProposalHeader, newVerifier: string) {
this.header = header;
this.newVerifier = newVerifier;
}
static fromBytes (bytes: Uint8Array): SetVerifierProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const newVerifier = u8aToHex(bytes.slice(40, 60));
return new SetVerifierProposal(header, newVerifier);
}
toU8a (): Uint8Array {
const addressBytesLength = 20;
const header = this.header.toU8a();
const setVerifierProposal = new Uint8Array(header.length + addressBytesLength);
setVerifierProposal.set(header, 0); // 0 -> 40
setVerifierProposal.set(hexToU8a(this.newVerifier, addressBytesLength * 8), 40); // 40 -> 60
return setVerifierProposal;
}
}
export interface IFeeRecipientUpdateProposal {
/**
* The Token Add Proposal Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly newFeeRecipient: string;
}
export class FeeRecipientUpdateProposal implements IFeeRecipientUpdateProposal {
header: ProposalHeader;
newFeeRecipient: string;
constructor (header: ProposalHeader, newFeeRecipient: string) {
this.header = header;
this.newFeeRecipient = newFeeRecipient;
}
static fromBytes (bytes: Uint8Array): FeeRecipientUpdateProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const newFeeRecipient = u8aToHex(bytes.slice(40, 60));
return new FeeRecipientUpdateProposal(header, newFeeRecipient);
}
toU8a (): Uint8Array {
const addressBytesLength = 20;
const header = this.header.toU8a();
const feeRecipientUpdateProposal = new Uint8Array(header.length + addressBytesLength);
feeRecipientUpdateProposal.set(header, 0); // 0 -> 40
feeRecipientUpdateProposal.set(hexToU8a(this.newFeeRecipient, addressBytesLength * 8), 40); // 40 -> 60
return feeRecipientUpdateProposal;
}
}
export interface IRescueTokensProposal {
/**
* The Rescue Token Proposals Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly tokenAddress: string;
/**
* 20 bytes Hex-encoded string.
*/
readonly toAddress: string;
/**
* 32 bytes Hex-encoded string.
*/
readonly amount: string;
}
export class RescueTokensProposal implements IRescueTokensProposal {
header: ProposalHeader;
tokenAddress: string;
toAddress: string;
amount: string;
constructor (header: ProposalHeader, tokenAddress: string, toAddress: string, amount: string) {
this.header = header;
this.tokenAddress = tokenAddress;
this.toAddress = toAddress;
this.amount = amount;
}
static fromBytes (bytes: Uint8Array): RescueTokensProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const tokenAddress = u8aToHex(bytes.slice(40, 60));
const toAddress = u8aToHex(bytes.slice(60, 80));
const amount = u8aToHex(bytes.slice(80, 112));
return new RescueTokensProposal(header, tokenAddress, toAddress, amount);
}
toU8a (): Uint8Array {
const addressBytesLength = 20;
const amountBytesLength = 32;
const header = this.header.toU8a();
const rescueTokensProposal = new Uint8Array(header.length + addressBytesLength + addressBytesLength + amountBytesLength);
rescueTokensProposal.set(header, 0); // 0 -> 40
rescueTokensProposal.set(hexToU8a(this.tokenAddress, addressBytesLength * 8), 40); // 40 -> 60
rescueTokensProposal.set(hexToU8a(this.toAddress, addressBytesLength * 8), 60); // 60 -> 80
rescueTokensProposal.set(hexToU8a(this.amount, amountBytesLength * 8), 80); // 80 -> 112
return rescueTokensProposal;
}
}
export interface IRegisterFungibleTokenProposal {
/**
* The Rescue Token Proposals Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly tokenHandler: string;
/**
* 4 bytes Hex-encoded string.
*/
readonly assetId: string;
/**
* 32 bytes Hex-encoded string.
*/
readonly name: string;
/**
* 32 bytes Hex-encoded string.
*/
readonly symbol: string;
}
export class RegisterFungibleTokenProposal implements IRegisterFungibleTokenProposal {
header: ProposalHeader;
tokenHandler: string;
assetId: string;
name: string;
symbol: string;
constructor (header: ProposalHeader, tokenHandler: string, assetId: string, name: string, symbol: string) {
this.header = header;
this.tokenHandler = tokenHandler;
this.assetId = assetId;
this.name = name;
this.symbol = symbol;
}
static fromBytes (bytes: Uint8Array): RegisterFungibleTokenProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const tokenHandler = u8aToHex(bytes.slice(40, 60));
const assetId = u8aToHex(bytes.slice(60, 64));
const name = u8aToHex(bytes.slice(64, 96));
const symbol = u8aToHex(bytes.slice(96, 128));
return new RegisterFungibleTokenProposal(header, tokenHandler, assetId, name, symbol);
}
toU8a (): Uint8Array {
const header = this.header.toU8a();
const tokenHandlerBytesLength = 20;
const assetIdBytesLength = 4;
const nameBytesLength = 32;
const symbolBytesLength = 32;
const registerFungibleTokenProposal = new Uint8Array(header.length + tokenHandlerBytesLength + assetIdBytesLength + nameBytesLength + symbolBytesLength);
registerFungibleTokenProposal.set(header, 0); // 0 -> 40
registerFungibleTokenProposal.set(hexToU8a(this.tokenHandler, tokenHandlerBytesLength * 8), 40); // 40 -> 60
registerFungibleTokenProposal.set(hexToU8a(this.assetId, assetIdBytesLength * 8), 60); // 60 -> 64
registerFungibleTokenProposal.set(hexToU8a(this.name, nameBytesLength * 8), 64); // 64 -> 96
registerFungibleTokenProposal.set(hexToU8a(this.symbol, symbolBytesLength * 8), 96); // 96 -> 128
return registerFungibleTokenProposal;
}
}
export interface IRegisterNftTokenProposal {
/**
* The Rescue Token Proposals Header.
*/
readonly header: ProposalHeader;
/**
* 20 bytes Hex-encoded string.
*/
readonly tokenHandler: string;
/**
* 4 bytes Hex-encoded string.
*/
readonly assetId: string;
/**
* 20 bytes Hex-encoded string.
*/
readonly collectionAddress: string;
/**
* 32 bytes Hex-encoded string.
*/
readonly salt: string;
/**
* 64 bytes Hex-encoded string.
*/
readonly uri: string;
}
export class RegisterNftTokenProposal implements IRegisterNftTokenProposal {
header: ProposalHeader;
tokenHandler: string;
assetId: string;
collectionAddress: string;
salt: string;
uri: string;
constructor (header: ProposalHeader, tokenHandler: string, assetId: string, collectionAddress: string, salt: string, uri: string) {
this.header = header;
this.tokenHandler = tokenHandler;
this.assetId = assetId;
this.collectionAddress = collectionAddress;
this.salt = salt;
this.uri = uri;
}
static fromBytes (bytes: Uint8Array): RegisterNftTokenProposal {
const header = ProposalHeader.fromBytes(bytes.slice(0, 40));
const tokenHandler = u8aToHex(bytes.slice(40, 60));
const assetId = u8aToHex(bytes.slice(60, 64));
const collectionAddress = u8aToHex(bytes.slice(64, 84));
const salt = u8aToHex(bytes.slice(84, 116));
const uri = u8aToHex(bytes.slice(116, 180));
return new RegisterNftTokenProposal(header, tokenHandler, assetId, collectionAddress, salt, uri);
}
toU8a (): Uint8Array {
const header = this.header.toU8a();
const tokenHandlerBytesLength = 20;
const assetIdBytesLength = 4;
const collectionAddressBytesLength = 20;
const saltBytesLength = 32;
const uriBytesLength = 64;
const registerNftTokenProposal = new Uint8Array(header.length + tokenHandlerBytesLength + assetIdBytesLength + collectionAddressBytesLength + saltBytesLength + uriBytesLength);
registerNftTokenProposal.set(header, 0); // 0 -> 40
registerNftTokenProposal.set(hexToU8a(this.tokenHandler, tokenHandlerBytesLength * 8), 40); // 40 -> 60
registerNftTokenProposal.set(hexToU8a(this.assetId, assetIdBytesLength * 8), 60); // 60 -> 64
registerNftTokenProposal.set(hexToU8a(this.collectionAddress, collectionAddressBytesLength * 8), 64); // 64 -> 84
registerNftTokenProposal.set(hexToU8a(this.salt, saltBytesLength * 8), 84); // 84 -> 116
registerNftTokenProposal.set(hexToU8a(this.uri, uriBytesLength * 8), 116); // 116 -> 180
return registerNftTokenProposal;
}
}