/
cmd_gov.go
761 lines (728 loc) · 24.8 KB
/
cmd_gov.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
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
package main
import (
"bytes"
"errors"
"flag"
"fmt"
"io"
"time"
"github.com/iov-one/weave"
bnsd "github.com/iov-one/weave/cmd/bnsd/app"
"github.com/iov-one/weave/cmd/bnsd/x/account"
"github.com/iov-one/weave/cmd/bnsd/x/preregistration"
"github.com/iov-one/weave/cmd/bnsd/x/qualityscore"
"github.com/iov-one/weave/cmd/bnsd/x/termdeposit"
"github.com/iov-one/weave/cmd/bnsd/x/username"
"github.com/iov-one/weave/datamigration"
"github.com/iov-one/weave/migration"
"github.com/iov-one/weave/x/cash"
"github.com/iov-one/weave/x/currency"
"github.com/iov-one/weave/x/distribution"
"github.com/iov-one/weave/x/escrow"
"github.com/iov-one/weave/x/gov"
"github.com/iov-one/weave/x/msgfee"
"github.com/iov-one/weave/x/multisig"
"github.com/iov-one/weave/x/txfee"
"github.com/iov-one/weave/x/validators"
)
func cmdAsProposal(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Read a transaction from the stdin and extract message from it. create a
proposal transaction for that message. All attributes of the original
transaction (ie signatures) are being dropped.
`)
fl.PrintDefaults()
}
var (
titleFl = fl.String("title", "Transfer funds to distribution account", "The proposal title.")
descFl = fl.String("description", "Transfer funds to distribution account", "The proposal description.")
startFl = flTime(fl, "start", inOneHour, "Start time as 'YYYY-MM-DD HH:MM' in UTC. If not provided, an arbitrary time in the future is used.")
eRuleFl = flSeq(fl, "electionrule", "", "The ID of the election rule to be used.")
)
fl.Parse(args)
msg, err := readProposalPayloadMsg(input)
// We must manually assign the message to the right attribute according
// to it's type.
//
// List of all supported message types can be found in the
// cmd/bnsd/app/codec.proto file.
//
// Instead of manually managing this list, use the script from the
// bottom comment to generate all the cases. Remember to leave nil and
// default case as they are not being generated.
// You are welcome.
var option bnsd.ProposalOptions
switch msg := msg.(type) {
case nil:
return errors.New("transaction without a message")
default:
return fmt.Errorf("message type not supported: %T", msg)
case *cash.SendMsg:
option.Option = &bnsd.ProposalOptions_CashSendMsg{
CashSendMsg: msg,
}
case *escrow.ReleaseMsg:
option.Option = &bnsd.ProposalOptions_EscrowReleaseMsg{
EscrowReleaseMsg: msg,
}
case *escrow.UpdatePartiesMsg:
option.Option = &bnsd.ProposalOptions_UpdateEscrowPartiesMsg{
UpdateEscrowPartiesMsg: msg,
}
case *multisig.UpdateMsg:
option.Option = &bnsd.ProposalOptions_MultisigUpdateMsg{
MultisigUpdateMsg: msg,
}
case *validators.ApplyDiffMsg:
option.Option = &bnsd.ProposalOptions_ValidatorsApplyDiffMsg{
ValidatorsApplyDiffMsg: msg,
}
case *currency.CreateMsg:
option.Option = &bnsd.ProposalOptions_CurrencyCreateMsg{
CurrencyCreateMsg: msg,
}
case *bnsd.ExecuteBatchMsg:
msgs, err := msg.MsgList()
if err != nil {
return fmt.Errorf("cannot extract messages: %s", err)
}
var messages []bnsd.ExecuteProposalBatchMsg_Union
for _, m := range msgs {
switch m := m.(type) {
case *cash.SendMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_SendMsg{
SendMsg: m,
},
})
case *escrow.ReleaseMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_EscrowReleaseMsg{
EscrowReleaseMsg: m,
},
})
case *escrow.UpdatePartiesMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_UpdateEscrowPartiesMsg{
UpdateEscrowPartiesMsg: m,
},
})
case *multisig.UpdateMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_MultisigUpdateMsg{
MultisigUpdateMsg: m,
},
})
case *validators.ApplyDiffMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_ValidatorsApplyDiffMsg{
ValidatorsApplyDiffMsg: m,
},
})
case *username.RegisterTokenMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_UsernameRegisterTokenMsg{
UsernameRegisterTokenMsg: m,
},
})
case *username.TransferTokenMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_UsernameTransferTokenMsg{
UsernameTransferTokenMsg: m,
},
})
case *username.ChangeTokenTargetsMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_UsernameChangeTokenTargetsMsg{
UsernameChangeTokenTargetsMsg: m,
},
})
case *username.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_UsernameUpdateConfigurationMsg{
UsernameUpdateConfigurationMsg: m,
},
})
case *distribution.CreateMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_DistributionCreateMsg{
DistributionCreateMsg: m,
},
})
case *distribution.DistributeMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_DistributionMsg{
DistributionMsg: m,
},
})
case *distribution.ResetMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_DistributionResetMsg{
DistributionResetMsg: m,
},
})
case *gov.UpdateElectorateMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_GovUpdateElectorateMsg{
GovUpdateElectorateMsg: m,
},
})
case *gov.UpdateElectionRuleMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_GovUpdateElectionRuleMsg{
GovUpdateElectionRuleMsg: m,
},
})
case *gov.CreateTextResolutionMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_GovCreateTextResolutionMsg{
GovCreateTextResolutionMsg: m,
},
})
case *msgfee.SetMsgFeeMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_MsgfeeSetMsgFeeMsg{
MsgfeeSetMsgFeeMsg: m,
},
})
case *datamigration.ExecuteMigrationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_DatamigrationExecuteMigrationMsg{
DatamigrationExecuteMigrationMsg: m,
},
})
case *account.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountUpdateConfigurationMsg{
AccountUpdateConfigurationMsg: m,
},
})
case *account.RegisterDomainMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountRegisterDomainMsg{
AccountRegisterDomainMsg: m,
},
})
case *account.ReplaceAccountMsgFeesMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountReplaceAccountMsgFeesMsg{
AccountReplaceAccountMsgFeesMsg: m,
},
})
case *account.TransferDomainMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountTransferDomainMsg{
AccountTransferDomainMsg: m,
},
})
case *account.RenewDomainMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountRenewDomainMsg{
AccountRenewDomainMsg: m,
},
})
case *account.DeleteDomainMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountDeleteDomainMsg{
AccountDeleteDomainMsg: m,
},
})
case *account.RegisterAccountMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountRegisterAccountMsg{
AccountRegisterAccountMsg: m,
},
})
case *account.TransferAccountMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountTransferAccountMsg{
AccountTransferAccountMsg: m,
},
})
case *account.ReplaceAccountTargetsMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountReplaceAccountTargetsMsg{
AccountReplaceAccountTargetsMsg: m,
},
})
case *account.DeleteAccountMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountDeleteAccountMsg{
AccountDeleteAccountMsg: m,
},
})
case *account.FlushDomainMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountFlushDomainMsg{
AccountFlushDomainMsg: m,
},
})
case *account.RenewAccountMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountRenewAccountMsg{
AccountRenewAccountMsg: m,
},
})
case *account.AddAccountCertificateMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountAddAccountCertificateMsg{
AccountAddAccountCertificateMsg: m,
},
})
case *account.DeleteAccountCertificateMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_AccountDeleteAccountCertificateMsg{
AccountDeleteAccountCertificateMsg: m,
},
})
case *cash.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_CashUpdateConfigurationMsg{
CashUpdateConfigurationMsg: m,
},
})
case *txfee.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_TxfeeUpdateConfigurationMsg{
TxfeeUpdateConfigurationMsg: m,
},
})
case *termdeposit.CreateDepositContractMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_TermdepositCreateDepositContractMsg{
TermdepositCreateDepositContractMsg: m,
},
})
case *termdeposit.DepositMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_TermdepositDepositMsg{
TermdepositDepositMsg: m,
},
})
case *termdeposit.ReleaseDepositMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_TermdepositReleaseDepositMsg{
TermdepositReleaseDepositMsg: m,
},
})
case *termdeposit.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_TermdepositUpdateConfigurationMsg{
TermdepositUpdateConfigurationMsg: m,
},
})
case *qualityscore.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_QualityscoreUpdateConfigurationMsg{
QualityscoreUpdateConfigurationMsg: m,
},
})
case *preregistration.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_PreregistrationUpdateConfigurationMsg{
PreregistrationUpdateConfigurationMsg: m,
},
})
case *msgfee.UpdateConfigurationMsg:
messages = append(messages, bnsd.ExecuteProposalBatchMsg_Union{
Sum: &bnsd.ExecuteProposalBatchMsg_Union_MsgfeeUpdateConfigurationMsg{
MsgfeeUpdateConfigurationMsg: m,
},
})
}
}
option.Option = &bnsd.ProposalOptions_ExecuteProposalBatchMsg{
ExecuteProposalBatchMsg: &bnsd.ExecuteProposalBatchMsg{
Messages: messages,
},
}
case *username.RegisterTokenMsg:
option.Option = &bnsd.ProposalOptions_UsernameRegisterTokenMsg{
UsernameRegisterTokenMsg: msg,
}
case *username.TransferTokenMsg:
option.Option = &bnsd.ProposalOptions_UsernameTransferTokenMsg{
UsernameTransferTokenMsg: msg,
}
case *username.ChangeTokenTargetsMsg:
option.Option = &bnsd.ProposalOptions_UsernameChangeTokenTargetsMsg{
UsernameChangeTokenTargetsMsg: msg,
}
case *username.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_UsernameUpdateConfigurationMsg{
UsernameUpdateConfigurationMsg: msg,
}
case *distribution.CreateMsg:
option.Option = &bnsd.ProposalOptions_DistributionCreateMsg{
DistributionCreateMsg: msg,
}
case *distribution.DistributeMsg:
option.Option = &bnsd.ProposalOptions_DistributionMsg{
DistributionMsg: msg,
}
case *distribution.ResetMsg:
option.Option = &bnsd.ProposalOptions_DistributionResetMsg{
DistributionResetMsg: msg,
}
case *migration.UpgradeSchemaMsg:
option.Option = &bnsd.ProposalOptions_MigrationUpgradeSchemaMsg{
MigrationUpgradeSchemaMsg: msg,
}
case *gov.UpdateElectorateMsg:
option.Option = &bnsd.ProposalOptions_GovUpdateElectorateMsg{
GovUpdateElectorateMsg: msg,
}
case *gov.UpdateElectionRuleMsg:
option.Option = &bnsd.ProposalOptions_GovUpdateElectionRuleMsg{
GovUpdateElectionRuleMsg: msg,
}
case *gov.CreateTextResolutionMsg:
option.Option = &bnsd.ProposalOptions_GovCreateTextResolutionMsg{
GovCreateTextResolutionMsg: msg,
}
case *msgfee.SetMsgFeeMsg:
option.Option = &bnsd.ProposalOptions_MsgfeeSetMsgFeeMsg{
MsgfeeSetMsgFeeMsg: msg,
}
case *datamigration.ExecuteMigrationMsg:
option.Option = &bnsd.ProposalOptions_DatamigrationExecuteMigrationMsg{
DatamigrationExecuteMigrationMsg: msg,
}
case *account.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_AccountUpdateConfigurationMsg{
AccountUpdateConfigurationMsg: msg,
}
case *account.RegisterDomainMsg:
option.Option = &bnsd.ProposalOptions_AccountRegisterDomainMsg{
AccountRegisterDomainMsg: msg,
}
case *account.ReplaceAccountMsgFeesMsg:
option.Option = &bnsd.ProposalOptions_AccountReplaceAccountMsgFeesMsg{
AccountReplaceAccountMsgFeesMsg: msg,
}
case *account.TransferDomainMsg:
option.Option = &bnsd.ProposalOptions_AccountTransferDomainMsg{
AccountTransferDomainMsg: msg,
}
case *account.RenewDomainMsg:
option.Option = &bnsd.ProposalOptions_AccountRenewDomainMsg{
AccountRenewDomainMsg: msg,
}
case *account.DeleteDomainMsg:
option.Option = &bnsd.ProposalOptions_AccountDeleteDomainMsg{
AccountDeleteDomainMsg: msg,
}
case *account.RegisterAccountMsg:
option.Option = &bnsd.ProposalOptions_AccountRegisterAccountMsg{
AccountRegisterAccountMsg: msg,
}
case *account.TransferAccountMsg:
option.Option = &bnsd.ProposalOptions_AccountTransferAccountMsg{
AccountTransferAccountMsg: msg,
}
case *account.ReplaceAccountTargetsMsg:
option.Option = &bnsd.ProposalOptions_AccountReplaceAccountTargetsMsg{
AccountReplaceAccountTargetsMsg: msg,
}
case *account.DeleteAccountMsg:
option.Option = &bnsd.ProposalOptions_AccountDeleteAccountMsg{
AccountDeleteAccountMsg: msg,
}
case *account.FlushDomainMsg:
option.Option = &bnsd.ProposalOptions_AccountFlushDomainMsg{
AccountFlushDomainMsg: msg,
}
case *account.RenewAccountMsg:
option.Option = &bnsd.ProposalOptions_AccountRenewAccountMsg{
AccountRenewAccountMsg: msg,
}
case *account.AddAccountCertificateMsg:
option.Option = &bnsd.ProposalOptions_AccountAddAccountCertificateMsg{
AccountAddAccountCertificateMsg: msg,
}
case *account.DeleteAccountCertificateMsg:
option.Option = &bnsd.ProposalOptions_AccountDeleteAccountCertificateMsg{
AccountDeleteAccountCertificateMsg: msg,
}
case *cash.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_CashUpdateConfigurationMsg{
CashUpdateConfigurationMsg: msg,
}
case *txfee.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_TxfeeUpdateConfigurationMsg{
TxfeeUpdateConfigurationMsg: msg,
}
case *termdeposit.CreateDepositContractMsg:
option.Option = &bnsd.ProposalOptions_TermdepositCreateDepositContractMsg{
TermdepositCreateDepositContractMsg: msg,
}
case *termdeposit.DepositMsg:
option.Option = &bnsd.ProposalOptions_TermdepositDepositMsg{
TermdepositDepositMsg: msg,
}
case *termdeposit.ReleaseDepositMsg:
option.Option = &bnsd.ProposalOptions_TermdepositReleaseDepositMsg{
TermdepositReleaseDepositMsg: msg,
}
case *termdeposit.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_TermdepositUpdateConfigurationMsg{
TermdepositUpdateConfigurationMsg: msg,
}
case *qualityscore.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_QualityscoreUpdateConfigurationMsg{
QualityscoreUpdateConfigurationMsg: msg,
}
case *preregistration.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_PreregistrationUpdateConfigurationMsg{
PreregistrationUpdateConfigurationMsg: msg,
}
case *msgfee.UpdateConfigurationMsg:
option.Option = &bnsd.ProposalOptions_MsgfeeUpdateConfigurationMsg{
MsgfeeUpdateConfigurationMsg: msg,
}
}
rawOption, err := option.Marshal()
if err != nil {
return fmt.Errorf("cannot serialize %T option: %s", option, err)
}
propTx := &bnsd.Tx{
Sum: &bnsd.Tx_GovCreateProposalMsg{
GovCreateProposalMsg: &gov.CreateProposalMsg{
Metadata: &weave.Metadata{Schema: 1},
Title: *titleFl,
Description: *descFl,
StartTime: startFl.UnixTime(),
ElectionRuleID: *eRuleFl,
RawOption: rawOption,
},
},
}
_, err = writeTx(output, propTx)
return err
}
func readProposalPayloadMsg(input io.Reader) (weave.Msg, error) {
var buf bytes.Buffer
if _, err := io.Copy(&buf, input); err != nil {
return nil, fmt.Errorf("cannot read input data: %s", err)
}
tx, _, err := readTx(bytes.NewReader(buf.Bytes()))
if err == nil {
return tx.GetMsg()
}
// ignore error as this may be due to a non Tx proposal option
var msg gov.CreateTextResolutionMsg
if err := msg.Unmarshal(buf.Bytes()); err != nil {
return nil, fmt.Errorf("failed to unmarshal proposal payload: %s", err)
}
return &msg, nil
}
func inOneHour() time.Time {
return time.Now().Add(time.Hour)
}
// cmdDelProposal is the cli command to delete an existing proposal.
func cmdDelProposal(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Delete an existing proposal before the voting period has started.
`)
fl.PrintDefaults()
}
var (
id = flSeq(fl, "proposal-id", "", "The ID of the proposal that is to be deleted.")
)
fl.Parse(args)
if len(*id) == 0 {
flagDie("the id must not be empty")
}
govTx := &bnsd.Tx{
Sum: &bnsd.Tx_GovDeleteProposalMsg{
GovDeleteProposalMsg: &gov.DeleteProposalMsg{
Metadata: &weave.Metadata{Schema: 1},
ProposalID: []byte(*id),
},
},
}
_, err := writeTx(output, govTx)
return err
}
var supportedVoteOptions = map[string]gov.VoteOption{
"yes": gov.VoteOption_Yes,
"no": gov.VoteOption_No,
"abstain": gov.VoteOption_Abstain,
}
// cmdVote is the cli command create a vote for a proposal
func cmdVote(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Vote on a governance proposal.
`)
fl.PrintDefaults()
}
var (
id = flSeq(fl, "proposal-id", "", "The ID of the proposal to vote for.")
voterFl = flHex(fl, "voter", "", "Optional address of a voter. If not provided the main signer will be used.")
selectedFl = fl.String("select", "", "Supported options are: yes, no, abstain")
)
fl.Parse(args)
if len(*id) == 0 {
flagDie("the proposal id must not be empty")
}
if len(*voterFl) != 0 {
if err := weave.Address(*voterFl).Validate(); err != nil {
flagDie("invalid voter address: %q", err)
}
}
selected, ok := supportedVoteOptions[*selectedFl]
if !ok {
flagDie("unsupported vote option: %q", *selectedFl)
}
govTx := &bnsd.Tx{
Sum: &bnsd.Tx_GovVoteMsg{
GovVoteMsg: &gov.VoteMsg{
Metadata: &weave.Metadata{Schema: 1},
ProposalID: []byte(*id),
Voter: weave.Address(*voterFl),
Selected: selected,
},
},
}
_, err := writeTx(output, govTx)
return err
}
func cmdTextResolution(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Text resolution creates a human readable gov proposal payload. To be used with 'as-proposal' command.
`)
fl.PrintDefaults()
}
var (
textFl = fl.String("text", "", "Human readable resolution text")
)
fl.Parse(args)
if len(*textFl) == 0 {
flagDie("the text must not be empty")
}
msg := &gov.CreateTextResolutionMsg{
Metadata: &weave.Metadata{Schema: 1},
Resolution: *textFl,
}
data, err := msg.Marshal()
if err != nil {
return fmt.Errorf("can not serialize msg: %s", err)
}
_, err = output.Write(data)
return err
}
func cmdUpdateElectorate(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Electorate creates a new version for an existing electorate. - new version is used for new proposals.
`)
fl.PrintDefaults()
}
var (
id = flSeq(fl, "id", "", "The ID of the electorate")
)
fl.Parse(args)
if len(*id) == 0 {
flagDie("the electorate id must not be empty")
}
govTx := &bnsd.Tx{
Sum: &bnsd.Tx_GovUpdateElectorateMsg{
GovUpdateElectorateMsg: &gov.UpdateElectorateMsg{
Metadata: &weave.Metadata{Schema: 1},
ElectorateID: []byte(*id),
},
},
}
_, err := writeTx(output, govTx)
return err
}
func cmdWithElector(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Reads a transaction from the input and attaches the provided elector address, weight pair.
`)
fl.PrintDefaults()
}
var (
addressFl = flAddress(fl, "address", "", "Electors address")
weightFl = fl.Uint("weight", 1, "Electors weight")
)
fl.Parse(args)
if len(*addressFl) == 0 {
flagDie("address must not be empty")
}
tx, _, err := readTx(input)
if err != nil {
return fmt.Errorf("cannot read input transaction: %s", err)
}
msg, err := tx.GetMsg()
if err != nil {
return fmt.Errorf("cannot extract transaction message: %s", err)
}
switch msg := msg.(type) {
case *gov.UpdateElectorateMsg:
msg.DiffElectors = append(msg.DiffElectors, gov.Elector{
Address: *addressFl,
Weight: uint32(*weightFl),
})
default:
return fmt.Errorf("message %T cannot be modified to contain multisig participant", msg)
}
_, err = writeTx(output, tx)
return nil
}
func cmdUpdateElectionRule(input io.Reader, output io.Writer, args []string) error {
fl := flag.NewFlagSet("", flag.ExitOnError)
fl.Usage = func() {
fmt.Fprintln(flag.CommandLine.Output(), `
Creates a new version for an existing election rule. The new version is used for new proposals.
`)
fl.PrintDefaults()
}
var (
id = flSeq(fl, "id", "", "The ID of the election rule")
durationFl = fl.Int("voting-period", 0, "Duration in seconds how long the voting period will take place")
numeratorFl = fl.Int("threshold-numerator", 0, "The top number of the fraction.")
denominatorFl = fl.Uint("threshold-denominator", 0, "The bottom number of the fraction")
quorumFl = flFraction(fl, "quorum", "", "New quorum fraction in format <numerator>/<denominator>. Zero quorum deletes the value.")
)
fl.Parse(args)
if len(*id) == 0 {
flagDie("the electorate id must not be empty")
}
if *durationFl == 0 {
flagDie("the duration must not be empty")
}
fraction := gov.Fraction{Numerator: uint32(*numeratorFl), Denominator: uint32(*denominatorFl)}
if err := fraction.Validate(); err != nil {
flagDie("invalid voting period: %s", err)
}
var quorum *gov.Fraction
if frac := quorumFl.Fraction(); frac.Numerator != 0 {
// If fraction value was provided, set it.
quorum = &gov.Fraction{Numerator: frac.Numerator, Denominator: frac.Denominator}
}
govTx := &bnsd.Tx{
Sum: &bnsd.Tx_GovUpdateElectionRuleMsg{
GovUpdateElectionRuleMsg: &gov.UpdateElectionRuleMsg{
Metadata: &weave.Metadata{Schema: 1},
ElectionRuleID: []byte(*id),
VotingPeriod: weave.AsUnixDuration(time.Duration(*durationFl) * time.Second),
Threshold: fraction,
Quorum: quorum,
},
},
}
_, err := writeTx(output, govTx)
return err
}