-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
89,602 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/paradigmxyz/mesc/go/pkg/mesc" | ||
"github.com/paradigmxyz/mesc/go/pkg/mesc/endpoint/io/serialization" | ||
) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
|
||
var queryType string | ||
flag.StringVar(&queryType, "query-type", "", "the type of query to execute") | ||
|
||
flag.Parse() | ||
|
||
switch queryType { | ||
case "get_default_endpoint": | ||
endpoint, err := mesc.GetDefaultEndpoint(ctx) | ||
if err != nil { | ||
printFailure(fmt.Errorf("failed to get default endpoint: %w", err)) | ||
return | ||
} | ||
|
||
jsonModel, err := serialization.SerializeEndpointMetadataJSON(endpoint) | ||
if err != nil { | ||
printFailure(fmt.Errorf("failed to serialize endpoint metadata to JSON: %w", err)) | ||
return | ||
} | ||
|
||
_, _ = io.Copy(os.Stdout, jsonModel) | ||
|
||
return | ||
} | ||
} | ||
|
||
func printFailure(e error) { | ||
fmt.Printf("FAIL: %v\n", e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
import json | ||
import os | ||
import subprocess | ||
import typing | ||
from typing import cast | ||
|
||
if typing.TYPE_CHECKING: | ||
from mesc.types import MescQuery | ||
|
||
|
||
def run_query(query: MescQuery) -> str: | ||
if query["query_type"] == "default_endpoint": | ||
cmd: list[str] = ["go", "run", "../go/cmd/cli.go", "--query-type", "get_default_endpoint"] | ||
# elif query["query_type"] == "endpoint_by_name": | ||
# name = cast(str, query["fields"]["name"]) # type: ignore | ||
# cmd = ["mesc", "endpoint", "--json", "--name", name] | ||
# elif query["query_type"] == "endpoint_by_network": | ||
# chain_id = query["fields"]["chain_id"] | ||
# if isinstance(chain_id, int): | ||
# chain_id = str(chain_id) | ||
# cmd = ["mesc", "endpoint", "--json", "--network", chain_id] | ||
# elif query["query_type"] == "user_input": | ||
# user_input = query["fields"]["user_input"] # type: ignore | ||
# cmd = ["mesc", "endpoint", user_input, "--json"] | ||
# elif query["query_type"] == "multi_endpoint": | ||
# cmd = ["mesc", "ls", "--json"] | ||
# if query["fields"].get('name_contains') is not None: | ||
# cmd.append('--name') | ||
# cmd.append(query['fields']['name_contains']) | ||
# if query["fields"].get('url_contains') is not None: | ||
# cmd.append('--url') | ||
# cmd.append(query['fields']['url_contains']) | ||
# if query["fields"].get('chain_id') is not None: | ||
# cmd.append('--network') | ||
# chain_id = query["fields"]["chain_id"] | ||
# if isinstance(chain_id, int): | ||
# chain_id = str(chain_id) | ||
# cmd.append(chain_id) | ||
# elif query['query_type'] == 'global_metadata': | ||
# cmd = ["mesc", "metadata"] | ||
else: | ||
raise Exception("invalid query query_type: " + str(query["query_type"])) | ||
|
||
if query["fields"].get("profile") is not None: | ||
cmd.append("--profile") | ||
cmd.append(query["fields"]["profile"]) # type: ignore | ||
|
||
raw_output = subprocess.check_output(cmd, env=dict(os.environ), stderr=subprocess.DEVNULL) | ||
output = raw_output.decode("utf-8").strip() | ||
if output == "": | ||
output = "null" | ||
|
||
return output | ||
|
||
|
||
if __name__ == "__main__": | ||
# load test | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("test") | ||
args = parser.parse_args() | ||
test = json.loads(args.test) | ||
|
||
# run test | ||
try: | ||
raw_output = run_query(test) | ||
try: | ||
result = json.loads(raw_output) | ||
print(json.dumps(result, indent=4, sort_keys=True)) | ||
except Exception as e: | ||
print("FAIL") | ||
print(e) | ||
print('RAW_OUTPUT:', raw_output) | ||
except Exception as e: | ||
print("FAIL") | ||
print(e) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
go 1.21.3 | ||
|
||
// Needed so that 'go run' works from this directory | ||
use ../go |
Oops, something went wrong.