|
1 | 1 | package commands_claim |
2 | 2 |
|
3 | | -import "github.com/spf13/cobra" |
| 3 | +import ( |
| 4 | + "lbry/cli/rpc" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | +) |
4 | 8 |
|
5 | 9 | func CreateCommandClaimList() *cobra.Command { |
6 | 10 | claim_list := &cobra.Command{ |
7 | 11 | Use: "list", |
8 | 12 | Short: "List my stream and channel claims.", |
9 | | - Run: func(cmd *cobra.Command, args []string) { |
10 | | - cmd.Help() |
11 | | - }, |
| 13 | + Run: HandleCommandClaimList, |
12 | 14 | } |
13 | 15 |
|
| 16 | + claim_list.Flags().StringArray("claim_type", nil, "(str or list) claim id") |
| 17 | + claim_list.Flags().StringArray("claim_id", nil, "(str or list) claim id") |
| 18 | + claim_list.Flags().StringArray("channel_id", nil, "(str or list) claims in this channel") |
| 19 | + claim_list.Flags().StringArray("name", nil, "(str or list) claim name") |
| 20 | + claim_list.Flags().Bool("is_spent", false, "(bool) only show spent txos") |
| 21 | + claim_list.Flags().StringArray("reposted_claim_id", nil, "(str or list) reposted claim id") |
| 22 | + claim_list.Flags().String("account_id", "", "(str) id of the account to query") |
| 23 | + claim_list.Flags().String("wallet_id", "", "(str) restrict results to specific wallet") |
| 24 | + claim_list.Flags().Bool("has_source", false, "(bool) list claims containing a source field") |
| 25 | + claim_list.Flags().Bool("has_no_source", false, "(bool) list claims not containing a source field") |
| 26 | + claim_list.Flags().Int("page", -1, "(int) page to return during paginating") |
| 27 | + claim_list.Flags().Int("page_size", -1, "(int) number of items on page during pagination") |
| 28 | + claim_list.Flags().Bool("resolve", false, "(bool) resolves each claim to provide additional metadata") |
| 29 | + claim_list.Flags().String("order_by", "", "(str) field to order by: 'name', 'height', 'amount'") |
| 30 | + claim_list.Flags().Bool("no_totals", false, "(bool) do not calculate the total number of pages and items in result set (significant performance boost)") |
| 31 | + claim_list.Flags().Bool("include_received_tips", false, "(bool) calculate the amount of tips received for claim outputs") |
| 32 | + |
14 | 33 | return claim_list |
15 | 34 | } |
| 35 | + |
| 36 | +func HandleCommandClaimList(cmd *cobra.Command, args []string) { |
| 37 | + claim_type, _ := cmd.Flags().GetStringArray("claim_type") |
| 38 | + claim_id, _ := cmd.Flags().GetStringArray("claim_id") |
| 39 | + channel_id, _ := cmd.Flags().GetStringArray("channel_id") |
| 40 | + name, _ := cmd.Flags().GetStringArray("name") |
| 41 | + is_spent, _ := cmd.Flags().GetBool("is_spent") |
| 42 | + reposted_claim_id, _ := cmd.Flags().GetStringArray("reposted_claim_id") |
| 43 | + account_id, _ := cmd.Flags().GetString("account_id") |
| 44 | + wallet_id, _ := cmd.Flags().GetString("wallet_id") |
| 45 | + has_source, _ := cmd.Flags().GetBool("has_source") |
| 46 | + has_no_source, _ := cmd.Flags().GetBool("has_no_source") |
| 47 | + page, _ := cmd.Flags().GetInt("page") |
| 48 | + page_size, _ := cmd.Flags().GetInt("page_size") |
| 49 | + resolve, _ := cmd.Flags().GetBool("resolve") |
| 50 | + order_by, _ := cmd.Flags().GetString("order_by") |
| 51 | + no_totals, _ := cmd.Flags().GetBool("no_totals") |
| 52 | + include_received_tips, _ := cmd.Flags().GetBool("include_received_tips") |
| 53 | + |
| 54 | + // Check for arguments |
| 55 | + if len(args) > 0 { |
| 56 | + cmd.Help() |
| 57 | + return |
| 58 | + } |
| 59 | + |
| 60 | + // Create parameter map |
| 61 | + params := map[string]any{} |
| 62 | + if len(claim_type) > 0 { |
| 63 | + params["claim_type"] = claim_type |
| 64 | + } |
| 65 | + if len(claim_id) > 0 { |
| 66 | + params["claim_id"] = claim_id |
| 67 | + } |
| 68 | + if len(channel_id) > 0 { |
| 69 | + params["channel_id"] = channel_id |
| 70 | + } |
| 71 | + if len(name) > 0 { |
| 72 | + params["name"] = name |
| 73 | + } |
| 74 | + if is_spent { |
| 75 | + params["is_spent"] = is_spent |
| 76 | + } |
| 77 | + if len(reposted_claim_id) > 0 { |
| 78 | + params["reposted_claim_id"] = reposted_claim_id |
| 79 | + } |
| 80 | + if account_id != "" { |
| 81 | + params["account_id"] = account_id |
| 82 | + } |
| 83 | + if wallet_id != "" { |
| 84 | + params["wallet_id"] = wallet_id |
| 85 | + } |
| 86 | + if has_source { |
| 87 | + params["has_source"] = has_source |
| 88 | + } |
| 89 | + if has_no_source { |
| 90 | + params["has_no_source"] = has_no_source |
| 91 | + } |
| 92 | + if page != -1 { |
| 93 | + params["page"] = page |
| 94 | + } |
| 95 | + if page_size != -1 { |
| 96 | + params["page_size"] = page_size |
| 97 | + } |
| 98 | + if resolve { |
| 99 | + params["resolve"] = resolve |
| 100 | + } |
| 101 | + if order_by != "" { |
| 102 | + params["order_by"] = order_by |
| 103 | + } |
| 104 | + if no_totals { |
| 105 | + params["no_totals"] = no_totals |
| 106 | + } |
| 107 | + if include_received_tips { |
| 108 | + params["include_received_tips"] = include_received_tips |
| 109 | + } |
| 110 | + |
| 111 | + rpc.ExecuteRPCCommand("claim_list", params) |
| 112 | +} |
0 commit comments