33# To experiment with this script and make them available in your shell, run:
44# source ./e2e/scripts/shannon_preliminary_services_helpers.sh
55
6+ #! /bin/bash
7+
8+ # =====================
9+ # HELP COMMAND for shannon_preliminary_services_helpers.sh
10+ # =====================
11+ function help() {
12+ echo " =========================================="
13+ echo " Shannon Preliminary Services Query Utilities"
14+ echo " =========================================="
15+ echo " "
16+ echo " Available commands:"
17+ echo " shannon_query_services_by_owner - List all services owned by a given address"
18+ echo " shannon_query_service_tlds_by_id - Aggregate service endpoint TLDs by service ID"
19+ echo " "
20+ echo " Quick start examples:"
21+ echo " shannon_query_services_by_owner main"
22+ echo " shannon_query_services_by_owner main pokt1lf0kekv9zcv9v3wy4v6jx2wh7v4665s8e0sl9s"
23+ echo " shannon_query_service_tlds_by_id main"
24+ echo " shannon_query_service_tlds_by_id main --structured"
25+ echo " shannon_query_service_tlds_by_id main --service-id eth"
26+ echo " "
27+ echo " ====================================================="
28+ echo " Use --help with any command for detailed information"
29+ echo " ====================================================="
30+ echo " "
31+ echo " NETWORK ENVIRONMENTS:"
32+ echo " alpha, beta, main - Pocket Network Shannon environments"
33+ echo " "
34+ echo " TIPS:"
35+ echo " You can inspect available service and supplier fields in the raw JSON files:"
36+ echo " /tmp/shannon_all_services_<env>.json (created by shannon_query_services_by_owner)"
37+ echo " /tmp/shannon_supplier_dump_<env>.json (created by shannon_query_service_tlds_by_id)"
38+ echo " "
39+ echo " Default owner address: pokt1lf0kekv9zcv9v3wy4v6jx2wh7v4665s8e0sl9s"
40+ echo " Alternative owner: pokt100ea839pz5e9zuhtjxvtyyzuv4evhmq95682zw"
41+ echo " "
42+ echo " Requires 'pocketd' CLI to be installed and configured with ~/.pocket home directory"
43+ }
44+ help
45+
646# Run with --help for usage info.
747function shannon_query_services_by_owner() {
848 if [[ -z " $1 " || " $1 " == " --help" || " $1 " == " -h" ]]; then
9- echo " shannon_query_services_by_owner - List all services owned by a given address."
49+ echo " shannon_query_services_by_owner: List all services owned by a given address."
1050 echo " "
11- echo " DESCRIPTION:"
12- echo " - Queries all services from the specified Pocket Network Shannon environment ('alpha', 'beta', or 'main')"
13- echo " - Filters them to show only services owned by a specific address"
14- echo " - Outputs a formatted list"
51+ echo " EXAMPLES:"
52+ echo " # List all services for the default owner in mainnet:"
53+ echo " shannon_query_services_by_owner main"
1554 echo " "
16- echo " REQUIREMENTS:"
17- echo " - Writes the raw JSON response to /tmp/shannon_all_services_<env>.json for debugging."
55+ echo " # List all services for a specific owner address in beta for first owner"
56+ echo " shannon_query_services_by_owner main pokt1lf0kekv9zcv9v3wy4v6jx2wh7v4665s8e0sl9s"
57+ echo " "
58+ echo " # List all services for a specific owner address in beta for second owner"
59+ echo " shannon_query_services_by_owner main pokt100ea839pz5e9zuhtjxvtyyzuv4evhmq95682zw"
1860 echo " "
1961 echo " USAGE:"
2062 echo " shannon_query_services_by_owner <env> [owner_address]"
@@ -24,25 +66,20 @@ function shannon_query_services_by_owner() {
2466 echo " [owner_address] Optional. Owner address to filter services by."
2567 echo " Defaults to pokt1lf0kekv9zcv9v3wy4v6jx2wh7v4665s8e0sl9s if not provided."
2668 echo " "
69+ echo " DESCRIPTION:"
70+ echo " - Queries all services from the specified Pocket Network Shannon environment ('alpha', 'beta', or 'main')"
71+ echo " - Filters them to show only services owned by a specific address"
72+ echo " - Outputs a formatted list"
73+ echo " "
2774 echo " OUTPUT:"
2875 echo " - Outputs a list of services owned by the specified address in the format:"
29- echo " - <service_id>: <service_name>"
76+ echo " - <service_id>: <service_name>" s
3077 echo " - Raw query response is saved to /tmp/shannon_all_services_<env>.json."
3178 echo " "
3279 echo " SIDE EFFECTS:"
3380 echo " - Creates/overwrites /tmp/shannon_all_services_<env>.json with the full service list."
3481 echo " - Prints info and errors to standard output."
3582 echo " "
36- echo " EXAMPLES:"
37- echo " # List all services for the default owner in mainnet:"
38- echo " shannon_query_services_by_owner main"
39- echo " "
40- echo " # List all services for a specific owner address in beta for first owner"
41- echo " shannon_query_services_by_owner beta pokt1lf0kekv9zcv9v3wy4v6jx2wh7v4665s8e0sl9s"
42- echo " "
43- echo " # List all services for a specific owner address in beta for second owner"
44- echo " shannon_query_services_by_owner beta pokt100ea839pz5e9zuhtjxvtyyzuv4evhmq95682zw"
45- echo " "
4683 return 0
4784 fi
4885
@@ -56,7 +93,7 @@ function shannon_query_services_by_owner() {
5693 local DUMP_FILE=" /tmp/shannon_all_services_${ENV} .json"
5794
5895 echo " Querying services from network: $ENV "
59- if ! pocketd query service all-services --network=" $ENV " --grpc-insecure=false -o json --page-limit=100000000 > " $DUMP_FILE " ; then
96+ if ! pocketd query service all-services --network=" $ENV " --grpc-insecure=false -o json --page-limit=1000000 > " $DUMP_FILE " ; then
6097 echo " ❌ Failed to query service list"
6198 return 1
6299 fi
@@ -71,24 +108,35 @@ function shannon_query_services_by_owner() {
71108 ' " $DUMP_FILE "
72109}
73110
74- # Run with --help for usage info.
75111function shannon_query_service_tlds_by_id() {
76112 if [[ -z " $1 " || " $1 " == " --help" || " $1 " == " -h" ]]; then
77113 echo " shannon_query_service_tlds_by_id - Query and aggregate service endpoint TLDs by service ID from a Pocket Network Shannon environment."
78114 echo " "
115+ echo " EXAMPLES:"
116+ echo " shannon_query_service_tlds_by_id main"
117+ echo " shannon_query_service_tlds_by_id main --structured"
118+ echo " shannon_query_service_tlds_by_id main --service-id eth"
119+ echo " shannon_query_service_tlds_by_id main --service-id bsc --structured"
120+ echo " shannon_query_service_tlds_by_id main --structured --service-id polygon"
121+ echo " "
122+ echo " USAGE:"
123+ echo " shannon_query_service_tlds_by_id <env> [--structured] [--service-id <service_id>]"
124+ echo " "
79125 echo " DESCRIPTION:"
80- echo " • Queries all suppliers from the specified Shannon environment ('alpha', 'beta', or 'main')."
81- echo " • Aggregates the 2nd-level TLDs (e.g. 'nodefleet.net') for each service ID, and displays the results."
82- echo " • Used in shannon_preliminary_services_test.sh to populate the SERVICE_TLDS associative array."
83- echo " • Maps service IDs to their comma-separated TLD lists for reporting."
126+ echo " - Queries all suppliers from the specified Shannon environment ('alpha', 'beta', or 'main')."
127+ echo " - Aggregates the 2nd-level TLDs (e.g. 'nodefleet.net') for each service ID, and displays the results."
128+ echo " - Used in shannon_preliminary_services_test.sh to populate the SERVICE_TLDS associative array."
129+ echo " - Maps service IDs to their comma-separated TLD lists for reporting."
84130 echo " "
85131 echo " PARAMETERS:"
86- echo " <env> Required. Network environment - must be one of: alpha, beta, main."
87- echo " [--structured] Optional. Output raw JSON only (no log output); otherwise, human-readable output."
132+ echo " <env> Required. Network environment - must be one of: alpha, beta, main."
133+ echo " [--structured] Optional. Output raw JSON only (no log output); otherwise, human-readable output."
134+ echo " [--service-id ID] Optional. Filter results to only show TLDs for the specified service ID."
88135 echo " "
89136 echo " OUTPUT:"
90137 echo " Without --structured: Human-readable list showing colored service IDs and their TLDs."
91138 echo " With --structured: Raw JSON object mapping service IDs to arrays of unique TLDs."
139+ echo " With --service-id: Results filtered to only the specified service ID."
92140 echo " "
93141 echo " SIDE EFFECTS:"
94142 echo " - Writes raw JSON response to /tmp/shannon_supplier_dump_<env>.json for debugging."
@@ -98,25 +146,56 @@ function shannon_query_service_tlds_by_id() {
98146 echo " EXAMPLE JSON OUTPUT (with --structured):"
99147 echo " {\" eth\" : [\" nodefleet.net\" , \" grove.city\" ], \" bsc\" : [\" ankr.com\" , \" quicknode.com\" ]}"
100148 echo " "
101- echo " USAGE:"
102- echo " shannon_query_service_tlds_by_id <env> [--structured]"
103- echo " "
104- echo " EXAMPLES:"
105- echo " shannon_query_service_tlds_by_id beta"
106- echo " shannon_query_service_tlds_by_id main --structured"
149+ echo " EXAMPLE JSON OUTPUT (with --structured --service-id eth):"
150+ echo " {\" eth\" : [\" nodefleet.net\" , \" grove.city\" ]}"
107151 return 0
108152 fi
109153
110- local ENV=" $1 "
111- local STRUCTURED=" $2 "
154+ # Parse arguments
155+ local ENV=" "
156+ local STRUCTURED=" "
157+ local SERVICE_ID=" "
158+
159+ while [[ $# -gt 0 ]]; do
160+ case $1 in
161+ --structured)
162+ STRUCTURED=" --structured"
163+ shift
164+ ;;
165+ --service-id)
166+ SERVICE_ID=" $2 "
167+ shift 2
168+ ;;
169+ * )
170+ if [[ -z " $ENV " ]]; then
171+ ENV=" $1 "
172+ else
173+ echo " ❌ Unexpected argument: $1 "
174+ return 1
175+ fi
176+ shift
177+ ;;
178+ esac
179+ done
180+
181+ # Validate required environment parameter
182+ if [[ -z " $ENV " ]]; then
183+ echo " ❌ Environment parameter is required. Use one of: alpha, beta, main"
184+ return 1
185+ fi
186+
112187 local HOME_DIR=" $HOME /.pocket"
113188 local DUMP_FILE=" /tmp/shannon_supplier_dump_${ENV} .json"
114189
115190 if [[ " $STRUCTURED " != " --structured" ]]; then
116- echo " Querying suppliers from network: $ENV "
191+ if [[ -n " $SERVICE_ID " ]]; then
192+ echo " Querying suppliers from network: $ENV (filtering for service ID: $SERVICE_ID )"
193+ else
194+ echo " Querying suppliers from network: $ENV "
195+ fi
117196 fi
118197
119- if ! pocketd query supplier list-suppliers --network=" $ENV " --home=" $HOME_DIR " --grpc-insecure=false -o json > " $DUMP_FILE " ; then
198+ if ! pocketd query supplier list-suppliers --network=" $ENV " --home=" $HOME_DIR " --grpc-insecure=false -o json --page-limit=1000 --dehydrated > " $DUMP_FILE " ; then
120199 if [[ " $STRUCTURED " != " --structured" ]]; then
121200 echo " ❌ Failed to query supplier list. Is the node running? Did you specify the right --home?"
122201 echo " Expected path: $HOME_DIR "
@@ -129,6 +208,7 @@ function shannon_query_service_tlds_by_id() {
129208 echo " 🔍 Parsing TLDs..."
130209 fi
131210
211+ # Build jq filter with optional service ID filtering
132212 local JQ_FILTER='
133213 reduce .supplier[] as $s (
134214 {};
@@ -146,8 +226,12 @@ function shannon_query_service_tlds_by_id() {
146226 .[$svc.service_id] += $tlds
147227 )
148228 )
149- | with_entries(.value |= unique | .value |= sort)
150- '
229+ | with_entries(.value |= unique | .value |= sort)'
230+
231+ # Add service ID filter if specified
232+ if [[ -n " $SERVICE_ID " ]]; then
233+ JQ_FILTER=" $JQ_FILTER | {\" $SERVICE_ID \" : .\" $SERVICE_ID \" } | with_entries(select(.value != null))"
234+ fi
151235
152236 if [[ " $STRUCTURED " == " --structured" ]]; then
153237 jq " $JQ_FILTER " " $DUMP_FILE "
0 commit comments