github.com/KiraCore/sekai@v0.3.43/x/gov/client/cli/query.go (about) 1 package cli 2 3 import ( 4 "context" 5 "fmt" 6 "strconv" 7 "strings" 8 9 "github.com/pkg/errors" 10 "github.com/spf13/cobra" 11 12 "github.com/cosmos/cosmos-sdk/client" 13 "github.com/cosmos/cosmos-sdk/client/flags" 14 sdk "github.com/cosmos/cosmos-sdk/types" 15 "github.com/cosmos/cosmos-sdk/version" 16 17 "github.com/KiraCore/sekai/x/gov/types" 18 ) 19 20 // Proposal flags 21 const ( 22 flagVoter = "voter" 23 ) 24 25 // NewQueryCmd returns a root CLI command handler for all x/tokens transaction commands. 26 func NewQueryCmd() *cobra.Command { 27 queryCmd := &cobra.Command{ 28 Use: types.RouterKey, 29 Short: "query commands for the customgov module", 30 } 31 queryCmd.AddCommand( 32 GetCmdQueryPermissions(), 33 GetCmdQueryNetworkProperties(), 34 GetCmdQueryExecutionFee(), 35 GetCmdQueryAllExecutionFees(), 36 GetCmdQueryPoorNetworkMessages(), 37 GetCmdQueryRole(), 38 GetCmdQueryAllRoles(), 39 GetCmdQueryRolesByAddress(), 40 GetCmdQueryProposals(), 41 GetCmdQueryPolls(), 42 GetCmdQueryPollVotes(), 43 GetCmdQueryCouncilRegistry(), 44 GetCmdQueryProposal(), 45 GetCmdQueryVote(), 46 GetCmdQueryVotes(), 47 GetCmdQueryWhitelistedProposalVoters(), 48 GetCmdQueryProposerVotersCount(), 49 GetCmdQueryIdentityRecord(), 50 GetCmdQueryIdentityRecordByAddress(), 51 GetCmdQueryAllIdentityRecords(), 52 GetCmdQueryIdentityRecordVerifyRequest(), 53 GetCmdQueryIdentityRecordVerifyRequestsByRequester(), 54 GetCmdQueryIdentityRecordVerifyRequestsByApprover(), 55 GetCmdQueryAllIdentityRecordVerifyRequests(), 56 GetCmdQueryAllDataReferenceKeys(), 57 GetCmdQueryDataReference(), 58 GetCmdQueryAllProposalDurations(), 59 GetCmdQueryProposalDuration(), 60 GetCmdQueryCouncilors(), 61 GetCmdQueryNonCouncilors(), 62 GetCmdQueryAddressesByWhitelistedPermission(), 63 GetCmdQueryAddressesByBlacklistedPermission(), 64 GetCmdQueryAddressesByWhitelistedRole(), 65 GetCmdQueryCustomPrefixes(), 66 ) 67 68 return queryCmd 69 } 70 71 // GetCmdQueryPermissions the query delegation command. 72 func GetCmdQueryPermissions() *cobra.Command { 73 cmd := &cobra.Command{ 74 Use: "permissions [addr]", 75 Short: "Query permissions of an address", 76 Args: cobra.ExactArgs(1), 77 RunE: func(cmd *cobra.Command, args []string) error { 78 clientCtx := client.GetClientContextFromCmd(cmd) 79 80 accAddr, err := sdk.AccAddressFromBech32(args[0]) 81 if err != nil { 82 return errors.Wrap(err, "invalid account address") 83 } 84 85 params := &types.PermissionsByAddressRequest{Addr: accAddr.String()} 86 87 queryClient := types.NewQueryClient(clientCtx) 88 res, err := queryClient.PermissionsByAddress(context.Background(), params) 89 if err != nil { 90 return err 91 } 92 93 return clientCtx.PrintProto(res.Permissions) 94 }, 95 } 96 97 flags.AddQueryFlagsToCmd(cmd) 98 99 return cmd 100 } 101 102 // GetCmdQueryAllRoles is the querier for all registered roles 103 func GetCmdQueryAllRoles() *cobra.Command { 104 cmd := &cobra.Command{ 105 Use: "all-roles", 106 Short: "Query all registered roles", 107 RunE: func(cmd *cobra.Command, args []string) error { 108 clientCtx := client.GetClientContextFromCmd(cmd) 109 110 request := &types.AllRolesRequest{} 111 112 queryClient := types.NewQueryClient(clientCtx) 113 res, err := queryClient.AllRoles(context.Background(), request) 114 if err != nil { 115 return err 116 } 117 118 return clientCtx.PrintProto(res) 119 }, 120 } 121 122 flags.AddQueryFlagsToCmd(cmd) 123 124 return cmd 125 } 126 127 // GetCmdQueryRolesByAddress is the querier for roles by address. 128 func GetCmdQueryRolesByAddress() *cobra.Command { 129 cmd := &cobra.Command{ 130 Use: "roles [addr]", 131 Short: "Query roles assigned to an address", 132 Args: cobra.ExactArgs(1), 133 RunE: func(cmd *cobra.Command, args []string) error { 134 clientCtx := client.GetClientContextFromCmd(cmd) 135 136 accAddr, err := sdk.AccAddressFromBech32(args[0]) 137 if err != nil { 138 return errors.Wrap(err, "invalid account address") 139 } 140 141 params := &types.RolesByAddressRequest{Addr: accAddr.String()} 142 143 queryClient := types.NewQueryClient(clientCtx) 144 res, err := queryClient.RolesByAddress(context.Background(), params) 145 if err != nil { 146 return err 147 } 148 149 return clientCtx.PrintProto(res) 150 }, 151 } 152 153 flags.AddQueryFlagsToCmd(cmd) 154 155 return cmd 156 } 157 158 func GetCmdQueryRole() *cobra.Command { 159 cmd := &cobra.Command{ 160 Use: "role [role_sid | role_id]", 161 Short: "Query role by sid or id", 162 Args: cobra.ExactArgs(1), 163 SilenceUsage: true, 164 RunE: func(cmd *cobra.Command, args []string) error { 165 clientCtx := client.GetClientContextFromCmd(cmd) 166 167 params := &types.RoleRequest{ 168 Identifier: args[0], 169 } 170 171 queryClient := types.NewQueryClient(clientCtx) 172 res, err := queryClient.Role(context.Background(), params) 173 if err != nil { 174 return err 175 } 176 177 return clientCtx.PrintProto(res.Role) 178 }, 179 } 180 181 flags.AddQueryFlagsToCmd(cmd) 182 183 return cmd 184 } 185 186 // GetCmdQueryNetworkProperties implement query network properties 187 func GetCmdQueryNetworkProperties() *cobra.Command { 188 cmd := &cobra.Command{ 189 Use: "network-properties", 190 Short: "Query network properties", 191 Args: cobra.MinimumNArgs(0), 192 RunE: func(cmd *cobra.Command, args []string) error { 193 clientCtx := client.GetClientContextFromCmd(cmd) 194 195 params := &types.NetworkPropertiesRequest{} 196 queryClient := types.NewQueryClient(clientCtx) 197 res, err := queryClient.NetworkProperties(context.Background(), params) 198 if err != nil { 199 return err 200 } 201 return clientCtx.PrintProto(res) 202 }, 203 } 204 205 flags.AddQueryFlagsToCmd(cmd) 206 207 return cmd 208 } 209 210 // GetCmdQueryCustomPrefixes implement query custom prefixes 211 func GetCmdQueryCustomPrefixes() *cobra.Command { 212 cmd := &cobra.Command{ 213 Use: "custom-prefixes", 214 Short: "Query custom prefixes", 215 Args: cobra.MinimumNArgs(0), 216 RunE: func(cmd *cobra.Command, args []string) error { 217 clientCtx := client.GetClientContextFromCmd(cmd) 218 219 params := &types.QueryCustomPrefixesRequest{} 220 queryClient := types.NewQueryClient(clientCtx) 221 res, err := queryClient.CustomPrefixes(context.Background(), params) 222 if err != nil { 223 return err 224 } 225 return clientCtx.PrintProto(res) 226 }, 227 } 228 229 flags.AddQueryFlagsToCmd(cmd) 230 231 return cmd 232 } 233 234 // GetCmdQueryPoorNetworkMessages query for poor network messages 235 func GetCmdQueryPoorNetworkMessages() *cobra.Command { 236 cmd := &cobra.Command{ 237 Use: "poor-network-messages", 238 Short: "Query poor network messages", 239 Args: cobra.MinimumNArgs(0), 240 RunE: func(cmd *cobra.Command, args []string) error { 241 clientCtx := client.GetClientContextFromCmd(cmd) 242 243 params := &types.PoorNetworkMessagesRequest{} 244 queryClient := types.NewQueryClient(clientCtx) 245 res, err := queryClient.PoorNetworkMessages(context.Background(), params) 246 if err != nil { 247 return err 248 } 249 250 return clientCtx.PrintProto(res) 251 }, 252 } 253 254 flags.AddQueryFlagsToCmd(cmd) 255 return cmd 256 } 257 258 // GetCmdQueryExecutionFee query for execution fee by execution name 259 func GetCmdQueryExecutionFee() *cobra.Command { 260 cmd := &cobra.Command{ 261 Use: "execution-fee [transaction_type]", 262 Short: "Query execution fee by the type of transaction", 263 Args: cobra.MinimumNArgs(1), 264 RunE: func(cmd *cobra.Command, args []string) error { 265 clientCtx := client.GetClientContextFromCmd(cmd) 266 267 params := &types.ExecutionFeeRequest{ 268 TransactionType: args[0], 269 } 270 queryClient := types.NewQueryClient(clientCtx) 271 res, err := queryClient.ExecutionFee(context.Background(), params) 272 if err != nil { 273 return err 274 } 275 276 return clientCtx.PrintProto(res) 277 }, 278 } 279 280 flags.AddQueryFlagsToCmd(cmd) 281 return cmd 282 } 283 284 // GetCmdQueryAllExecutionFees query for all execution fees 285 func GetCmdQueryAllExecutionFees() *cobra.Command { 286 cmd := &cobra.Command{ 287 Use: "all-execution-fees", 288 Short: "Query all execution fees", 289 Args: cobra.MinimumNArgs(0), 290 RunE: func(cmd *cobra.Command, args []string) error { 291 clientCtx := client.GetClientContextFromCmd(cmd) 292 293 params := &types.AllExecutionFeesRequest{} 294 queryClient := types.NewQueryClient(clientCtx) 295 res, err := queryClient.AllExecutionFees(context.Background(), params) 296 if err != nil { 297 return err 298 } 299 300 return clientCtx.PrintProto(res) 301 }, 302 } 303 304 flags.AddQueryFlagsToCmd(cmd) 305 return cmd 306 } 307 308 func GetCmdQueryCouncilRegistry() *cobra.Command { 309 cmd := &cobra.Command{ 310 Use: "council-registry", 311 Short: "Query governance registry.", 312 Args: cobra.ExactArgs(0), 313 SilenceUsage: true, 314 RunE: func(cmd *cobra.Command, args []string) error { 315 clientCtx := client.GetClientContextFromCmd(cmd) 316 317 addr, err := cmd.Flags().GetString(FlagAddr) 318 if err != nil { 319 return err 320 } 321 322 moniker, err := cmd.Flags().GetString(FlagMoniker) 323 if err != nil { 324 return err 325 } 326 if addr == "" && moniker == "" { 327 return fmt.Errorf("at least one flag (--flag or --moniker) is mandatory") 328 } 329 330 var res *types.CouncilorResponse 331 if moniker != "" { 332 params := &types.CouncilorByMonikerRequest{Moniker: moniker} 333 334 queryClient := types.NewQueryClient(clientCtx) 335 res, err = queryClient.CouncilorByMoniker(context.Background(), params) 336 if err != nil { 337 return err 338 } 339 } else { 340 bech32, err := sdk.AccAddressFromBech32(addr) 341 if err != nil { 342 return fmt.Errorf("invalid address: %w", err) 343 } 344 345 params := &types.CouncilorByAddressRequest{Addr: bech32.String()} 346 347 queryClient := types.NewQueryClient(clientCtx) 348 res, err = queryClient.CouncilorByAddress(context.Background(), params) 349 if err != nil { 350 return err 351 } 352 } 353 354 return clientCtx.PrintProto(&res.Councilor) 355 }, 356 } 357 358 flags.AddQueryFlagsToCmd(cmd) 359 360 cmd.Flags().String(FlagAddr, "", "the address you want to query information") 361 cmd.Flags().String(FlagMoniker, "", "the moniker you want to query information") 362 363 return cmd 364 } 365 366 // GetCmdQueryProposals implements a query proposals command. Command to Get a 367 // Proposal Information. 368 func GetCmdQueryProposals() *cobra.Command { 369 cmd := &cobra.Command{ 370 Use: "proposals", 371 Short: "Query proposals with optional filters", 372 Long: strings.TrimSpace( 373 fmt.Sprintf(`Query for a all paginated proposals that match optional filters: 374 375 Example: 376 $ %s query customgov proposals --voter kira12m2g0dxjx7cekaxlgw8pv39euyfhk2ns54e5pv 377 `, 378 version.AppName, 379 ), 380 ), 381 RunE: func(cmd *cobra.Command, args []string) error { 382 bechVoterAddr, _ := cmd.Flags().GetString(flagVoter) 383 384 if len(bechVoterAddr) != 0 { 385 _, err := sdk.AccAddressFromBech32(bechVoterAddr) 386 if err != nil { 387 return err 388 } 389 } 390 391 clientCtx := client.GetClientContextFromCmd(cmd) 392 queryClient := types.NewQueryClient(clientCtx) 393 394 pageReq, err := client.ReadPageRequest(cmd.Flags()) 395 if err != nil { 396 return err 397 } 398 399 res, err := queryClient.Proposals( 400 context.Background(), 401 &types.QueryProposalsRequest{ 402 Voter: bechVoterAddr, 403 Pagination: pageReq, 404 }, 405 ) 406 if err != nil { 407 return err 408 } 409 410 if len(res.GetProposals()) == 0 { 411 return fmt.Errorf("no proposals found") 412 } 413 414 return clientCtx.PrintProto(res) 415 }, 416 } 417 418 cmd.Flags().String(flagVoter, "", "(optional) filter by proposals voted on by voted") 419 flags.AddQueryFlagsToCmd(cmd) 420 flags.AddPaginationFlagsToCmd(cmd, "customgov") 421 422 return cmd 423 } 424 425 // GetCmdQueryPolls implements a query polls command. Command to Get a 426 // poll ids. 427 func GetCmdQueryPolls() *cobra.Command { 428 cmd := &cobra.Command{ 429 Use: "polls [address]", 430 Short: "Get polls by address", 431 Args: cobra.ExactArgs(1), 432 RunE: func(cmd *cobra.Command, args []string) error { 433 clientCtx := client.GetClientContextFromCmd(cmd) 434 accAddr, err := sdk.AccAddressFromBech32(args[0]) 435 436 if err != nil { 437 return errors.Wrap(err, "invalid account address") 438 } 439 440 params := &types.QueryPollsListByAddress{Creator: accAddr} 441 queryClient := types.NewQueryClient(clientCtx) 442 res, err := queryClient.PollsListByAddress(context.Background(), params) 443 444 if err != nil { 445 return err 446 } 447 448 return clientCtx.PrintProto(res) 449 }, 450 } 451 452 flags.AddQueryFlagsToCmd(cmd) 453 454 return cmd 455 } 456 457 // GetCmdQueryPollVotes implements a query poll votes command. Command to Get a 458 // poll votes by id. 459 func GetCmdQueryPollVotes() *cobra.Command { 460 cmd := &cobra.Command{ 461 Use: "poll-votes [ID]", 462 Short: "Get poll votes by id", 463 Args: cobra.ExactArgs(1), 464 RunE: func(cmd *cobra.Command, args []string) error { 465 clientCtx := client.GetClientContextFromCmd(cmd) 466 id, err := strconv.Atoi(args[0]) 467 468 if err != nil { 469 return errors.Wrap(err, "invalid poll id") 470 } 471 472 params := &types.QueryPollsVotesByPollId{PollId: uint64(id)} 473 queryClient := types.NewQueryClient(clientCtx) 474 res, err := queryClient.PollsVotesByPollId(context.Background(), params) 475 476 if err != nil { 477 return err 478 } 479 480 return clientCtx.PrintProto(res) 481 }, 482 } 483 484 flags.AddQueryFlagsToCmd(cmd) 485 486 return cmd 487 } 488 489 // GetCmdQueryProposal implements the query proposal command. 490 func GetCmdQueryProposal() *cobra.Command { 491 cmd := &cobra.Command{ 492 Use: "proposal [proposal-id]", 493 Args: cobra.ExactArgs(1), 494 Short: "Query proposal details", 495 Long: strings.TrimSpace( 496 fmt.Sprintf(`Query details for a proposal. You can find the 497 proposal-id by running "%s query gov proposals". 498 499 Example: 500 $ %s query gov proposal 1 501 `, 502 version.AppName, version.AppName, 503 ), 504 ), 505 RunE: func(cmd *cobra.Command, args []string) error { 506 clientCtx := client.GetClientContextFromCmd(cmd) 507 508 queryClient := types.NewQueryClient(clientCtx) 509 510 // validate that the proposal id is a uint 511 proposalID, err := strconv.ParseUint(args[0], 10, 64) 512 if err != nil { 513 return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0]) 514 } 515 516 // Query the proposal 517 res, err := queryClient.Proposal( 518 context.Background(), 519 &types.QueryProposalRequest{ProposalId: proposalID}, 520 ) 521 if err != nil { 522 return err 523 } 524 525 return clientCtx.PrintProto(&res.Proposal) 526 }, 527 } 528 529 flags.AddQueryFlagsToCmd(cmd) 530 531 return cmd 532 } 533 534 // GetCmdQueryVote implements the query proposal vote command. Command to Get a 535 // Proposal Information. 536 func GetCmdQueryVote() *cobra.Command { 537 cmd := &cobra.Command{ 538 Use: "vote [proposal-id] [voter-addr]", 539 Args: cobra.ExactArgs(2), 540 Short: "Query details of a single vote", 541 Long: strings.TrimSpace( 542 fmt.Sprintf(`Query details for a single vote on a proposal given its identifier. 543 544 Example: 545 $ %s query gov vote 1 kira1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk 546 `, 547 version.AppName, 548 ), 549 ), 550 RunE: func(cmd *cobra.Command, args []string) error { 551 clientCtx := client.GetClientContextFromCmd(cmd) 552 553 queryClient := types.NewQueryClient(clientCtx) 554 555 // validate that the proposal id is a uint 556 proposalID, err := strconv.ParseUint(args[0], 10, 64) 557 if err != nil { 558 return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) 559 } 560 561 // check to see if the proposal is in the store 562 _, err = queryClient.Proposal( 563 context.Background(), 564 &types.QueryProposalRequest{ProposalId: proposalID}, 565 ) 566 if err != nil { 567 return fmt.Errorf("failed to fetch proposal-id %d: %s", proposalID, err) 568 } 569 570 voterAddr, err := sdk.AccAddressFromBech32(args[1]) 571 if err != nil { 572 return err 573 } 574 575 res, err := queryClient.Vote( 576 context.Background(), 577 &types.QueryVoteRequest{ProposalId: proposalID, Voter: voterAddr.String()}, 578 ) 579 if err != nil { 580 return err 581 } 582 583 return clientCtx.PrintProto(&res.Vote) 584 }, 585 } 586 587 flags.AddQueryFlagsToCmd(cmd) 588 589 return cmd 590 } 591 592 // GetCmdQueryVotes implements the command to query for proposal votes. 593 func GetCmdQueryVotes() *cobra.Command { 594 cmd := &cobra.Command{ 595 Use: "votes [proposal-id]", 596 Args: cobra.ExactArgs(1), 597 Short: "Query votes on a proposal", 598 Long: strings.TrimSpace( 599 fmt.Sprintf(`Query vote details for a single proposal by its identifier. 600 601 Example: 602 $ %[1]s query gov votes 1 603 `, 604 version.AppName, 605 ), 606 ), 607 RunE: func(cmd *cobra.Command, args []string) error { 608 clientCtx := client.GetClientContextFromCmd(cmd) 609 610 queryClient := types.NewQueryClient(clientCtx) 611 612 // validate that the proposal id is a uint 613 proposalID, err := strconv.ParseUint(args[0], 10, 64) 614 if err != nil { 615 return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) 616 } 617 618 res, err := queryClient.Votes( 619 context.Background(), 620 &types.QueryVotesRequest{ProposalId: proposalID}, 621 ) 622 623 if err != nil { 624 return err 625 } 626 627 return clientCtx.PrintProto(res) 628 629 }, 630 } 631 632 flags.AddQueryFlagsToCmd(cmd) 633 634 return cmd 635 } 636 637 // GetCmdQueryWhitelistedProposalVoters implements the command to query for possible proposal voters. 638 func GetCmdQueryWhitelistedProposalVoters() *cobra.Command { 639 cmd := &cobra.Command{ 640 Use: "voters [proposal-id]", 641 Args: cobra.ExactArgs(1), 642 Short: "Query voters of a proposal", 643 Long: strings.TrimSpace( 644 fmt.Sprintf(`Query voters for a single proposal by its identifier. 645 646 Example: 647 $ %[1]s query gov voters 1 648 `, 649 version.AppName, 650 ), 651 ), 652 RunE: func(cmd *cobra.Command, args []string) error { 653 clientCtx := client.GetClientContextFromCmd(cmd) 654 queryClient := types.NewQueryClient(clientCtx) 655 656 // validate that the proposal id is a uint 657 proposalID, err := strconv.ParseUint(args[0], 10, 64) 658 if err != nil { 659 return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) 660 } 661 662 res, err := queryClient.WhitelistedProposalVoters( 663 context.Background(), 664 &types.QueryWhitelistedProposalVotersRequest{ProposalId: proposalID}, 665 ) 666 667 if err != nil { 668 return err 669 } 670 671 return clientCtx.PrintProto(res) 672 673 }, 674 } 675 676 flags.AddQueryFlagsToCmd(cmd) 677 678 return cmd 679 } 680 681 func GetCmdQueryProposerVotersCount() *cobra.Command { 682 cmd := &cobra.Command{ 683 Use: "proposer-voters-count", 684 Args: cobra.ExactArgs(0), 685 Short: "Query proposer and voters count that can create at least a type of proposal", 686 Long: strings.TrimSpace( 687 fmt.Sprintf(`Query proposer and voters count that can create at least a type of proposal. 688 689 Example: 690 $ %[1]s query gov proposer-voters-count 691 `, 692 version.AppName, 693 ), 694 ), 695 RunE: func(cmd *cobra.Command, args []string) error { 696 clientCtx := client.GetClientContextFromCmd(cmd) 697 queryClient := types.NewQueryClient(clientCtx) 698 699 res, err := queryClient.ProposerVotersCount( 700 context.Background(), 701 &types.QueryProposerVotersCountRequest{}, 702 ) 703 704 if err != nil { 705 return err 706 } 707 708 return clientCtx.PrintProto(res) 709 710 }, 711 } 712 713 flags.AddQueryFlagsToCmd(cmd) 714 715 return cmd 716 } 717 718 // GetCmdQueryIdentityRecord implements the command to query identity record by id 719 func GetCmdQueryIdentityRecord() *cobra.Command { 720 cmd := &cobra.Command{ 721 Use: "identity-record [id]", 722 Args: cobra.ExactArgs(1), 723 Short: "Query identity record by id", 724 Long: strings.TrimSpace( 725 fmt.Sprintf(`Query identity record by id. 726 727 Example: 728 $ %[1]s query gov identity-record 1 729 `, 730 version.AppName, 731 ), 732 ), 733 RunE: func(cmd *cobra.Command, args []string) error { 734 clientCtx := client.GetClientContextFromCmd(cmd) 735 queryClient := types.NewQueryClient(clientCtx) 736 737 // validate that the id is a uint 738 id, err := strconv.ParseUint(args[0], 10, 64) 739 if err != nil { 740 return fmt.Errorf("id %s not a valid int, please input a valid id", args[0]) 741 } 742 743 res, err := queryClient.IdentityRecord( 744 context.Background(), 745 &types.QueryIdentityRecordRequest{Id: id}, 746 ) 747 748 if err != nil { 749 return err 750 } 751 752 return clientCtx.PrintProto(res) 753 }, 754 } 755 756 flags.AddQueryFlagsToCmd(cmd) 757 758 return cmd 759 } 760 761 // GetCmdQueryIdentityRecordByAddress implements the command to query identity records by records creator 762 func GetCmdQueryIdentityRecordByAddress() *cobra.Command { 763 cmd := &cobra.Command{ 764 Use: "identity-records-by-addr [addr]", 765 Args: cobra.ExactArgs(1), 766 Short: "Query identity records by address", 767 Long: strings.TrimSpace( 768 fmt.Sprintf(`Query identity records by address. 769 770 Example: 771 $ %[1]s query gov identity-records-by-addr [addr] 772 `, 773 version.AppName, 774 ), 775 ), 776 RunE: func(cmd *cobra.Command, args []string) error { 777 clientCtx := client.GetClientContextFromCmd(cmd) 778 queryClient := types.NewQueryClient(clientCtx) 779 780 // validate address 781 addr, err := sdk.AccAddressFromBech32(args[0]) 782 if err != nil { 783 return err 784 } 785 786 keysStr, err := cmd.Flags().GetString(FlagKeys) 787 if err != nil { 788 return err 789 } 790 791 keys := strings.Split(keysStr, ",") 792 if keysStr == "" { 793 keys = []string{} 794 } 795 796 res, err := queryClient.IdentityRecordsByAddress( 797 context.Background(), 798 &types.QueryIdentityRecordsByAddressRequest{ 799 Creator: addr, 800 Keys: keys, 801 }, 802 ) 803 804 if err != nil { 805 return err 806 } 807 808 return clientCtx.PrintProto(res) 809 }, 810 } 811 812 flags.AddQueryFlagsToCmd(cmd) 813 cmd.Flags().String(FlagKeys, "", "keys required when needs to be filtered") 814 815 return cmd 816 } 817 818 // GetCmdQueryAllIdentityRecords implements the command to query all identity records 819 func GetCmdQueryAllIdentityRecords() *cobra.Command { 820 cmd := &cobra.Command{ 821 Use: "identity-records", 822 Args: cobra.ExactArgs(0), 823 Short: "Query all identity records", 824 Long: strings.TrimSpace( 825 fmt.Sprintf(`Query all identity records. 826 827 Example: 828 $ %[1]s query gov identity-records 829 `, 830 version.AppName, 831 ), 832 ), 833 RunE: func(cmd *cobra.Command, args []string) error { 834 clientCtx := client.GetClientContextFromCmd(cmd) 835 queryClient := types.NewQueryClient(clientCtx) 836 837 pageReq, err := client.ReadPageRequest(cmd.Flags()) 838 if err != nil { 839 return err 840 } 841 842 res, err := queryClient.AllIdentityRecords( 843 context.Background(), 844 &types.QueryAllIdentityRecordsRequest{ 845 Pagination: pageReq, 846 }, 847 ) 848 849 if err != nil { 850 return err 851 } 852 853 return clientCtx.PrintProto(res) 854 }, 855 } 856 857 flags.AddQueryFlagsToCmd(cmd) 858 flags.AddPaginationFlagsToCmd(cmd, "customgov") 859 860 return cmd 861 } 862 863 // GetCmdQueryIdentityRecordVerifyRequest implements the command to query identity record verify request by id 864 func GetCmdQueryIdentityRecordVerifyRequest() *cobra.Command { 865 cmd := &cobra.Command{ 866 Use: "identity-record-verify-request [id]", 867 Args: cobra.ExactArgs(1), 868 Short: "Query identity record verify request by id", 869 Long: strings.TrimSpace( 870 fmt.Sprintf(`Query identity record verify request by id. 871 872 Example: 873 $ %[1]s query gov identity-record-verify-request 1 874 `, 875 version.AppName, 876 ), 877 ), 878 RunE: func(cmd *cobra.Command, args []string) error { 879 clientCtx := client.GetClientContextFromCmd(cmd) 880 queryClient := types.NewQueryClient(clientCtx) 881 882 // validate that the id is a uint 883 id, err := strconv.ParseUint(args[0], 10, 64) 884 if err != nil { 885 return fmt.Errorf("id %s not a valid int, please input a valid id", args[0]) 886 } 887 888 res, err := queryClient.IdentityRecordVerifyRequest( 889 context.Background(), 890 &types.QueryIdentityVerifyRecordRequest{ 891 RequestId: id, 892 }, 893 ) 894 895 if err != nil { 896 return err 897 } 898 899 return clientCtx.PrintProto(res) 900 }, 901 } 902 903 flags.AddQueryFlagsToCmd(cmd) 904 905 return cmd 906 } 907 908 // GetCmdQueryIdentityRecordVerifyRequestsByRequester implements the command to query identity records verify requests by requester 909 func GetCmdQueryIdentityRecordVerifyRequestsByRequester() *cobra.Command { 910 cmd := &cobra.Command{ 911 Use: "identity-record-verify-requests-by-requester [addr]", 912 Args: cobra.ExactArgs(1), 913 Short: "Query identity records verify requests by requester", 914 Long: strings.TrimSpace( 915 fmt.Sprintf(`Query identity records verify requests by requester. 916 917 Example: 918 $ %[1]s query gov identity-record-verify-requests-by-requester [addr] 919 `, 920 version.AppName, 921 ), 922 ), 923 RunE: func(cmd *cobra.Command, args []string) error { 924 clientCtx := client.GetClientContextFromCmd(cmd) 925 queryClient := types.NewQueryClient(clientCtx) 926 927 // validate address 928 addr, err := sdk.AccAddressFromBech32(args[0]) 929 if err != nil { 930 return err 931 } 932 933 pageReq, err := client.ReadPageRequest(cmd.Flags()) 934 if err != nil { 935 return err 936 } 937 938 res, err := queryClient.IdentityRecordVerifyRequestsByRequester( 939 context.Background(), 940 &types.QueryIdentityRecordVerifyRequestsByRequester{ 941 Requester: addr, 942 Pagination: pageReq, 943 }, 944 ) 945 946 if err != nil { 947 return err 948 } 949 950 return clientCtx.PrintProto(res) 951 }, 952 } 953 954 flags.AddQueryFlagsToCmd(cmd) 955 flags.AddPaginationFlagsToCmd(cmd, "customgov") 956 957 return cmd 958 } 959 960 // GetCmdQueryIdentityRecordVerifyRequestsByApprover implements the command to query identity records verify requests by approver 961 func GetCmdQueryIdentityRecordVerifyRequestsByApprover() *cobra.Command { 962 cmd := &cobra.Command{ 963 Use: "identity-record-verify-requests-by-approver [addr]", 964 Args: cobra.ExactArgs(1), 965 Short: "Query identity record verify request by approver", 966 Long: strings.TrimSpace( 967 fmt.Sprintf(`Query identity record verify requests by approver. 968 969 Example: 970 $ %[1]s query gov identity-record-verify-requests-by-approver [addr] 971 `, 972 version.AppName, 973 ), 974 ), 975 RunE: func(cmd *cobra.Command, args []string) error { 976 clientCtx := client.GetClientContextFromCmd(cmd) 977 queryClient := types.NewQueryClient(clientCtx) 978 979 // validate address 980 addr, err := sdk.AccAddressFromBech32(args[0]) 981 if err != nil { 982 return err 983 } 984 985 pageReq, err := client.ReadPageRequest(cmd.Flags()) 986 if err != nil { 987 return err 988 } 989 990 res, err := queryClient.IdentityRecordVerifyRequestsByApprover( 991 context.Background(), 992 &types.QueryIdentityRecordVerifyRequestsByApprover{ 993 Approver: addr, 994 Pagination: pageReq, 995 }, 996 ) 997 998 if err != nil { 999 return err 1000 } 1001 1002 return clientCtx.PrintProto(res) 1003 }, 1004 } 1005 1006 flags.AddQueryFlagsToCmd(cmd) 1007 flags.AddPaginationFlagsToCmd(cmd, "customgov") 1008 1009 return cmd 1010 } 1011 1012 // GetCmdQueryAllIdentityRecordVerifyRequests implements the command to query all identity records verify requests 1013 func GetCmdQueryAllIdentityRecordVerifyRequests() *cobra.Command { 1014 cmd := &cobra.Command{ 1015 Use: "all-identity-record-verify-requests", 1016 Args: cobra.ExactArgs(0), 1017 Short: "Query all identity records verify requests", 1018 Long: strings.TrimSpace( 1019 fmt.Sprintf(`Query all identity records verify requests. 1020 1021 Example: 1022 $ %[1]s query gov all-identity-record-verify-requests 1023 `, 1024 version.AppName, 1025 ), 1026 ), 1027 RunE: func(cmd *cobra.Command, args []string) error { 1028 clientCtx := client.GetClientContextFromCmd(cmd) 1029 queryClient := types.NewQueryClient(clientCtx) 1030 1031 pageReq, err := client.ReadPageRequest(cmd.Flags()) 1032 if err != nil { 1033 return err 1034 } 1035 1036 res, err := queryClient.AllIdentityRecordVerifyRequests( 1037 context.Background(), 1038 &types.QueryAllIdentityRecordVerifyRequests{ 1039 Pagination: pageReq, 1040 }, 1041 ) 1042 1043 if err != nil { 1044 return err 1045 } 1046 1047 return clientCtx.PrintProto(res) 1048 }, 1049 } 1050 1051 flags.AddQueryFlagsToCmd(cmd) 1052 flags.AddPaginationFlagsToCmd(cmd, "customgov") 1053 1054 return cmd 1055 } 1056 1057 // GetCmdQueryAllDataReferenceKeys implements the command to query all data registry keys 1058 func GetCmdQueryAllDataReferenceKeys() *cobra.Command { 1059 cmd := &cobra.Command{ 1060 Use: "data-registry-keys", 1061 Args: cobra.ExactArgs(0), 1062 Short: "Query all data registry keys", 1063 Long: strings.TrimSpace( 1064 fmt.Sprintf(`Query all data registry keys. 1065 1066 Example: 1067 $ %[1]s query gov data-registry-keys 1068 `, 1069 version.AppName, 1070 ), 1071 ), 1072 RunE: func(cmd *cobra.Command, args []string) error { 1073 clientCtx := client.GetClientContextFromCmd(cmd) 1074 queryClient := types.NewQueryClient(clientCtx) 1075 1076 pageReq, err := client.ReadPageRequest(cmd.Flags()) 1077 if err != nil { 1078 return err 1079 } 1080 1081 res, err := queryClient.AllDataReferenceKeys( 1082 context.Background(), 1083 &types.QueryDataReferenceKeysRequest{ 1084 Pagination: pageReq, 1085 }, 1086 ) 1087 1088 if err != nil { 1089 return err 1090 } 1091 1092 return clientCtx.PrintProto(res) 1093 }, 1094 } 1095 1096 flags.AddQueryFlagsToCmd(cmd) 1097 flags.AddPaginationFlagsToCmd(cmd, "customgov") 1098 1099 return cmd 1100 } 1101 1102 // GetCmdQueryDataReference implements the command to query data registry by specific key 1103 func GetCmdQueryDataReference() *cobra.Command { 1104 cmd := &cobra.Command{ 1105 Use: "data-registry", 1106 Args: cobra.ExactArgs(1), 1107 Short: "Query data registry by specific key", 1108 Long: strings.TrimSpace( 1109 fmt.Sprintf(`Query data registry by key. 1110 1111 Example: 1112 $ %[1]s query gov data-registry [key] 1113 `, 1114 version.AppName, 1115 ), 1116 ), 1117 RunE: func(cmd *cobra.Command, args []string) error { 1118 clientCtx := client.GetClientContextFromCmd(cmd) 1119 queryClient := types.NewQueryClient(clientCtx) 1120 1121 res, err := queryClient.DataReferenceByKey( 1122 context.Background(), 1123 &types.QueryDataReferenceRequest{ 1124 Key: args[0], 1125 }, 1126 ) 1127 1128 if err != nil { 1129 return err 1130 } 1131 1132 return clientCtx.PrintProto(res) 1133 }, 1134 } 1135 1136 flags.AddQueryFlagsToCmd(cmd) 1137 flags.AddPaginationFlagsToCmd(cmd, "customgov") 1138 1139 return cmd 1140 } 1141 1142 // GetCmdQueryAllProposalDurations implements the command to query all proposal durations 1143 func GetCmdQueryAllProposalDurations() *cobra.Command { 1144 cmd := &cobra.Command{ 1145 Use: "all-proposal-durations", 1146 Args: cobra.ExactArgs(0), 1147 Short: "Query all proposal durations", 1148 Long: strings.TrimSpace( 1149 fmt.Sprintf(`Query all proposal durations. 1150 1151 Example: 1152 $ %[1]s query gov all-proposal-durations 1153 `, 1154 version.AppName, 1155 ), 1156 ), 1157 RunE: func(cmd *cobra.Command, args []string) error { 1158 clientCtx := client.GetClientContextFromCmd(cmd) 1159 queryClient := types.NewQueryClient(clientCtx) 1160 1161 res, err := queryClient.AllProposalDurations( 1162 context.Background(), 1163 &types.QueryAllProposalDurations{}, 1164 ) 1165 1166 if err != nil { 1167 return err 1168 } 1169 1170 return clientCtx.PrintProto(res) 1171 }, 1172 } 1173 1174 flags.AddQueryFlagsToCmd(cmd) 1175 1176 return cmd 1177 } 1178 1179 // GetCmdQueryProposalDuration implements the command to query a proposal duration 1180 func GetCmdQueryProposalDuration() *cobra.Command { 1181 cmd := &cobra.Command{ 1182 Use: "proposal-duration [proposal_type]", 1183 Args: cobra.ExactArgs(1), 1184 Short: "Query a proposal duration", 1185 Long: strings.TrimSpace( 1186 fmt.Sprintf(`Query all all proposal durations. 1187 1188 Example: 1189 $ %[1]s query gov proposal-duration SetNetworkProperty 1190 `, 1191 version.AppName, 1192 ), 1193 ), 1194 RunE: func(cmd *cobra.Command, args []string) error { 1195 clientCtx := client.GetClientContextFromCmd(cmd) 1196 queryClient := types.NewQueryClient(clientCtx) 1197 1198 res, err := queryClient.ProposalDuration( 1199 context.Background(), 1200 &types.QueryProposalDuration{ 1201 ProposalType: args[0], 1202 }, 1203 ) 1204 1205 if err != nil { 1206 return err 1207 } 1208 1209 return clientCtx.PrintProto(res) 1210 }, 1211 } 1212 1213 flags.AddQueryFlagsToCmd(cmd) 1214 1215 return cmd 1216 } 1217 1218 // GetCmdQueryCouncilors - all councilors (waiting or not), including their corresponding statuses, 1219 // ranks & abstenation counters - add sub-query to search by specific KIRA address 1220 func GetCmdQueryCouncilors() *cobra.Command { 1221 cmd := &cobra.Command{ 1222 Use: "councilors", 1223 Args: cobra.ExactArgs(0), 1224 Short: "Query councilors", 1225 Long: strings.TrimSpace( 1226 fmt.Sprintf(`Query councilors. 1227 1228 Example: 1229 $ %[1]s query gov councilors 1230 `, 1231 version.AppName, 1232 ), 1233 ), 1234 RunE: func(cmd *cobra.Command, args []string) error { 1235 clientCtx := client.GetClientContextFromCmd(cmd) 1236 queryClient := types.NewQueryClient(clientCtx) 1237 1238 res, err := queryClient.Councilors( 1239 context.Background(), 1240 &types.QueryCouncilors{}, 1241 ) 1242 1243 if err != nil { 1244 return err 1245 } 1246 1247 return clientCtx.PrintProto(res) 1248 }, 1249 } 1250 1251 flags.AddQueryFlagsToCmd(cmd) 1252 1253 return cmd 1254 } 1255 1256 // GetCmdQueryNonCouncilors - list all governance members that are NOT Councilors 1257 func GetCmdQueryNonCouncilors() *cobra.Command { 1258 cmd := &cobra.Command{ 1259 Use: "non-councilors", 1260 Args: cobra.ExactArgs(0), 1261 Short: "Query all governance members that are NOT Councilors", 1262 Long: strings.TrimSpace( 1263 fmt.Sprintf(`Query all governance members that are NOT Councilors. 1264 1265 Example: 1266 $ %[1]s query gov non-councilors 1267 `, 1268 version.AppName, 1269 ), 1270 ), 1271 RunE: func(cmd *cobra.Command, args []string) error { 1272 clientCtx := client.GetClientContextFromCmd(cmd) 1273 queryClient := types.NewQueryClient(clientCtx) 1274 1275 res, err := queryClient.NonCouncilors( 1276 context.Background(), 1277 &types.QueryNonCouncilors{}, 1278 ) 1279 1280 if err != nil { 1281 return err 1282 } 1283 1284 return clientCtx.PrintProto(res) 1285 }, 1286 } 1287 1288 flags.AddQueryFlagsToCmd(cmd) 1289 1290 return cmd 1291 } 1292 1293 // GetCmdQueryAddressesByWhitelistedPermission - list all KIRA addresses by a specific whitelisted permission (address does NOT have to be a Councilor) 1294 func GetCmdQueryAddressesByWhitelistedPermission() *cobra.Command { 1295 cmd := &cobra.Command{ 1296 Use: "whitelisted-permission-addresses [perm]", 1297 Args: cobra.ExactArgs(1), 1298 Short: "Query all KIRA addresses by a specific whitelisted permission", 1299 Long: strings.TrimSpace( 1300 fmt.Sprintf(`Query all KIRA addresses by a specific whitelisted permission. 1301 1302 Example: 1303 $ %[1]s query gov whitelisted-permission-addresses [perm] 1304 `, 1305 version.AppName, 1306 ), 1307 ), 1308 RunE: func(cmd *cobra.Command, args []string) error { 1309 clientCtx := client.GetClientContextFromCmd(cmd) 1310 queryClient := types.NewQueryClient(clientCtx) 1311 1312 perm, err := strconv.Atoi(args[0]) 1313 if err != nil { 1314 return err 1315 } 1316 1317 res, err := queryClient.AddressesByWhitelistedPermission( 1318 context.Background(), 1319 &types.QueryAddressesByWhitelistedPermission{ 1320 Permission: uint32(perm), 1321 }, 1322 ) 1323 1324 if err != nil { 1325 return err 1326 } 1327 1328 return clientCtx.PrintProto(res) 1329 }, 1330 } 1331 1332 flags.AddQueryFlagsToCmd(cmd) 1333 1334 return cmd 1335 } 1336 1337 // GetCmdQueryAddressesByBlacklistedPermission - list all KIRA addresses by a specific blacklisted permission (address does NOT have to be a Councilor) 1338 func GetCmdQueryAddressesByBlacklistedPermission() *cobra.Command { 1339 cmd := &cobra.Command{ 1340 Use: "blacklisted-permission-addresses [perm]", 1341 Args: cobra.ExactArgs(1), 1342 Short: "Query all KIRA addresses by a specific blacklisted permission", 1343 Long: strings.TrimSpace( 1344 fmt.Sprintf(`Query all KIRA addresses by a specific blacklisted permission. 1345 1346 Example: 1347 $ %[1]s query gov blacklisted-permission-addresses [perm] 1348 `, 1349 version.AppName, 1350 ), 1351 ), 1352 RunE: func(cmd *cobra.Command, args []string) error { 1353 clientCtx := client.GetClientContextFromCmd(cmd) 1354 queryClient := types.NewQueryClient(clientCtx) 1355 1356 perm, err := strconv.Atoi(args[0]) 1357 if err != nil { 1358 return err 1359 } 1360 1361 res, err := queryClient.AddressesByBlacklistedPermission( 1362 context.Background(), 1363 &types.QueryAddressesByBlacklistedPermission{ 1364 Permission: uint32(perm), 1365 }, 1366 ) 1367 1368 if err != nil { 1369 return err 1370 } 1371 1372 return clientCtx.PrintProto(res) 1373 }, 1374 } 1375 1376 flags.AddQueryFlagsToCmd(cmd) 1377 1378 return cmd 1379 } 1380 1381 // GetCmdQueryAddressesByWhitelistedRole - list all kira addresses by a specific whitelisted role (address does NOT have to be a Councilor) 1382 func GetCmdQueryAddressesByWhitelistedRole() *cobra.Command { 1383 cmd := &cobra.Command{ 1384 Use: "whitelisted-role-addresses [role]", 1385 Args: cobra.ExactArgs(1), 1386 Short: "Query all kira addresses by a specific whitelisted role (address does NOT have to be a Councilor)", 1387 Long: strings.TrimSpace( 1388 fmt.Sprintf(`Query all kira addresses by a specific whitelisted role (address does NOT have to be a Councilor). 1389 1390 Example: 1391 $ %[1]s query gov whitelisted-role-addresses [role] 1392 `, 1393 version.AppName, 1394 ), 1395 ), 1396 RunE: func(cmd *cobra.Command, args []string) error { 1397 clientCtx := client.GetClientContextFromCmd(cmd) 1398 queryClient := types.NewQueryClient(clientCtx) 1399 1400 role, err := strconv.Atoi(args[0]) 1401 if err != nil { 1402 return err 1403 } 1404 1405 res, err := queryClient.AddressesByWhitelistedRole( 1406 context.Background(), 1407 &types.QueryAddressesByWhitelistedRole{ 1408 Role: uint32(role), 1409 }, 1410 ) 1411 1412 if err != nil { 1413 return err 1414 } 1415 1416 return clientCtx.PrintProto(res) 1417 }, 1418 } 1419 1420 flags.AddQueryFlagsToCmd(cmd) 1421 1422 return cmd 1423 }