mycelium-rhai #9
@ -7,8 +7,8 @@ let api_url = "http://localhost:8989";
|
||||
print("Getting node information:");
|
||||
try {
|
||||
let node_info = mycelium_get_node_info(api_url);
|
||||
print(`Node subnet: ${node_info.subnet}`);
|
||||
print(`Node public key: ${node_info.publicKey}`);
|
||||
print(`Node subnet: ${node_info.nodeSubnet}`);
|
||||
print(`Node public key: ${node_info.nodePubkey}`);
|
||||
} catch(err) {
|
||||
print(`Error getting node info: ${err}`);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::time::Duration;
|
||||
use serde_json::Value;
|
||||
use reqwest::Client;
|
||||
use base64::encode;
|
||||
|
||||
/// Get information about the Mycelium node
|
||||
///
|
||||
@ -45,7 +46,7 @@ pub async fn get_node_info(api_url: &str) -> Result<Value, String> {
|
||||
/// * `Result<Value, String>` - The list of peers as a JSON value, or an error message
|
||||
pub async fn list_peers(api_url: &str) -> Result<Value, String> {
|
||||
let client = Client::new();
|
||||
let url = format!("{}/api/v1/peers", api_url);
|
||||
let url = format!("{}/api/v1/admin/peers", api_url);
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
@ -78,7 +79,7 @@ pub async fn list_peers(api_url: &str) -> Result<Value, String> {
|
||||
/// * `Result<Value, String>` - The result of the operation as a JSON value, or an error message
|
||||
pub async fn add_peer(api_url: &str, peer_address: &str) -> Result<Value, String> {
|
||||
let client = Client::new();
|
||||
let url = format!("{}/api/v1/peers", api_url);
|
||||
let url = format!("{}/api/v1/admin/peers", api_url);
|
||||
|
||||
let response = client
|
||||
.post(&url)
|
||||
@ -114,7 +115,7 @@ pub async fn add_peer(api_url: &str, peer_address: &str) -> Result<Value, String
|
||||
/// * `Result<Value, String>` - The result of the operation as a JSON value, or an error message
|
||||
pub async fn remove_peer(api_url: &str, peer_id: &str) -> Result<Value, String> {
|
||||
let client = Client::new();
|
||||
let url = format!("{}/api/v1/peers/{}", api_url, peer_id);
|
||||
let url = format!("{}/api/v1/admin/peers/{}", api_url, peer_id);
|
||||
|
||||
let response = client
|
||||
.delete(&url)
|
||||
@ -146,7 +147,7 @@ pub async fn remove_peer(api_url: &str, peer_id: &str) -> Result<Value, String>
|
||||
/// * `Result<Value, String>` - The list of selected routes as a JSON value, or an error message
|
||||
pub async fn list_selected_routes(api_url: &str) -> Result<Value, String> {
|
||||
let client = Client::new();
|
||||
let url = format!("{}/api/v1/routes/selected", api_url);
|
||||
let url = format!("{}/api/v1/admin/routes/selected", api_url);
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
@ -178,7 +179,7 @@ pub async fn list_selected_routes(api_url: &str) -> Result<Value, String> {
|
||||
/// * `Result<Value, String>` - The list of fallback routes as a JSON value, or an error message
|
||||
pub async fn list_fallback_routes(api_url: &str) -> Result<Value, String> {
|
||||
let client = Client::new();
|
||||
let url = format!("{}/api/v1/routes/fallback", api_url);
|
||||
let url = format!("{}/api/v1/admin/routes/fallback", api_url);
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
@ -257,11 +258,11 @@ pub async fn send_message(api_url: &str, destination: &str, topic: &str, message
|
||||
/// * `Result<Value, String>` - The received messages as a JSON value, or an error message
|
||||
pub async fn receive_messages(api_url: &str, topic: &str, count: u32) -> Result<Value, String> {
|
||||
let client = Client::new();
|
||||
let url = format!("{}/api/v1/messages/{}", api_url, topic);
|
||||
let url = format!("{}/api/v1/messages", api_url);
|
||||
|
||||
let response = client
|
||||
.get(&url)
|
||||
.query(&[("count", count)])
|
||||
.query(&[("topic", encode(topic)), ("count", count.to_string())])
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Failed to send request: {}", e))?;
|
||||
|
Loading…
Reference in New Issue
Block a user