-
Notifications
You must be signed in to change notification settings - Fork 19
Dw/prov mgmt scripts #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Dw/prov mgmt scripts #799
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2d628f4
get and remove…
dolled-possum 81454b1
…add-provider first iteration
dolled-possum 6f0db38
add-provider second
dolled-possum 7c80cbc
removing debug logging
dolled-possum 9c2b7b6
style and text fixes
dolled-possum 334fdd0
final touches on provider management scripts
dolled-possum f9d0bba
Format Rust code using rustfmt
github-actions[bot] b5594db
Make provider serialization consistent w/init load
dolled-possum 6b6689a
Merge branch 'dw/prov-mgmt-scripts' of https://github.com/hyperware-a…
dolled-possum 85b9ab6
disabling adding node providers
dolled-possum c80e3a6
splits add-provider into node and rpcurl flavors
dolled-possum d3ef2a0
better handling of unexpected add responses
dolled-possum ca52be0
workflow call dynamically uses blue/green
dolled-possum 32a15df
Merge branch 'develop' into dw/prov-mgmt-scripts
dolled-possum 58a614d
Merge branch 'develop' into dw/prov-mgmt-scripts
dolled-possum a24082f
Merge branch 'develop' into dw/prov-mgmt-scripts
dolled-possum 32974f1
small fixes
dolled-possum 2d11dae
Format Rust code using rustfmt
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,20 @@ | ||
| [package] | ||
| name = "add-node-provider" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [features] | ||
| simulation-mode = [] | ||
|
|
||
| [dependencies] | ||
| hyperware_process_lib = "2.0.0" | ||
| rmp-serde = "1.1.2" | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| serde_json = "1.0.140" | ||
| wit-bindgen = "0.42.1" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [package.metadata.component] | ||
| package = "hyperware:process" | ||
115 changes: 115 additions & 0 deletions
115
hyperdrive/packages/terminal/add-node-provider/src/lib.rs
This file contains hidden or 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,115 @@ | ||
| // add-node-provider/lib.rs | ||
| use hyperware_process_lib::{script, Address, Message, Request}; | ||
| use serde_json::{json, Value}; | ||
| use std::collections::HashMap; | ||
|
|
||
| wit_bindgen::generate!({ | ||
| path: "../target/wit", | ||
| world: "process-v1", | ||
| }); | ||
|
|
||
| script!(init); | ||
| fn init(_our: Address, args: String) -> String { | ||
| // Parse arguments: <chain-id> <node-name> <public-key> <ip-address> <ws-port> [--trusted <true|false>] | ||
| let parts: Vec<&str> = args.trim().split_whitespace().collect(); | ||
|
|
||
| if parts.len() < 5 { | ||
| return "Usage: add-node-provider <chain-id> <node-name> <public-key> <ip-address> <ws-port> [--trusted <true|false>]\n Examples:\n add-node-provider 8453 other-node.hypr abc123pubkey 192.168.1.1 9000 (defaults to trusted=false)\n add-node-provider 1 other-node.hypr abc123pubkey 192.168.1.1 9000 --trusted true".to_string(); | ||
| } | ||
|
|
||
| let chain_id = match parts[0].parse::<u64>() { | ||
| Ok(id) => id, | ||
| Err(_) => return format!("Invalid chain ID: {}. Must be a number.", parts[0]), | ||
| }; | ||
|
|
||
| let node_name = parts[1]; | ||
| let public_key = parts[2]; | ||
| let ip_address = parts[3]; | ||
| let ws_port = match parts[4].parse::<u16>() { | ||
| Ok(port) => port, | ||
| Err(_) => return format!("Invalid WebSocket port: {}. Must be a number.", parts[4]), | ||
| }; | ||
|
|
||
| // Parse trusted flag (default to false for node providers) | ||
| let trusted = parse_flag_bool(&parts[5..], "--trusted", false); | ||
|
|
||
| // Create ports map with WebSocket port | ||
| let mut ports = HashMap::new(); | ||
| ports.insert("ws".to_string(), ws_port); | ||
|
|
||
| // Create the HNS update object | ||
| let hns_update = json!({ | ||
| "name": node_name, | ||
| "public_key": public_key, | ||
| "ips": [ip_address], | ||
| "ports": ports, | ||
| "routers": [] | ||
| }); | ||
|
|
||
| // Create the provider configuration | ||
| let provider_config = json!({ | ||
| "chain_id": chain_id, | ||
| "provider": { | ||
| "Node": { | ||
| "hns_update": hns_update, | ||
| "use_as_provider": true | ||
| } | ||
| }, | ||
| "trusted": trusted | ||
| }); | ||
|
|
||
| // Create AddProvider request | ||
| let request_body = json!({ | ||
| "AddProvider": provider_config | ||
| }); | ||
|
|
||
| let Ok(Ok(Message::Response { body, .. })) = Request::to(("our", "eth", "distro", "sys")) | ||
| .body(serde_json::to_vec(&request_body).unwrap()) | ||
| .send_and_await_response(60) | ||
| else { | ||
| return "Failed to communicate with eth module".to_string(); | ||
| }; | ||
|
|
||
| // Parse the response | ||
| if let Ok(json_value) = serde_json::from_slice::<Value>(&body) { | ||
| if let Some(response) = json_value.as_str() { | ||
| match response { | ||
| "Ok" => { | ||
| format!( | ||
| "Successfully added node provider: {} ({}:{}) on chain {} with trusted={}", | ||
| node_name, ip_address, ws_port, chain_id, trusted | ||
| ) | ||
| } | ||
| "PermissionDenied" => "Permission denied: insufficient privileges".to_string(), | ||
| other => format!("Error: {}", other), | ||
| } | ||
| } else { | ||
| // Handle any other response types with better formatting | ||
| format!( | ||
| "Unexpected response: {}", | ||
| serde_json::to_string_pretty(&json_value) | ||
| .unwrap_or_else(|_| "Failed to format response".to_string()) | ||
| ) | ||
| } | ||
| } else { | ||
| format!( | ||
| "Failed to parse response as JSON\nRaw response: {}", | ||
| String::from_utf8_lossy(&body) | ||
| ) | ||
| } | ||
| } | ||
| fn parse_flag_bool(args: &[&str], flag: &str, default: bool) -> bool { | ||
| let mut i = 0; | ||
| while i < args.len() { | ||
| if args[i] == flag { | ||
| if i + 1 < args.len() { | ||
| if let Ok(value) = args[i + 1].parse::<bool>() { | ||
| return value; | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| i += 1; | ||
| } | ||
| default | ||
| } |
20 changes: 20 additions & 0 deletions
20
hyperdrive/packages/terminal/add-rpcurl-provider/Cargo.toml
This file contains hidden or 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,20 @@ | ||
| [package] | ||
| name = "add-rpcurl-provider" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [features] | ||
| simulation-mode = [] | ||
|
|
||
| [dependencies] | ||
| hyperware_process_lib = "2.0.0" | ||
| rmp-serde = "1.1.2" | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| serde_json = "1.0.140" | ||
| wit-bindgen = "0.42.1" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [package.metadata.component] | ||
| package = "hyperware:process" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.