mucelium client needs to be in wrapper #10
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_lib_rhai#10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
/Volumes/T7/code0/hero_lib/crates/clients/src/mycelium
do with factory
client = mycelium_client_factory()
default is to the local mycelium
when client cannot connect it gives error
put all features in nice format in a rhai wrapper
put in /Volumes/T7/code0/hero_lib_rhai/crates/clients_rhai/src
Implementation Spec for Issue #10 — Mycelium Client Rhai Wrapper (Factory Pattern)
Objective
Rewrite
crates/clients_rhai/src/mycelium.rsto follow the factory pattern used byacp.rsandmqtt.rs: expose amycelium_client_factory()function that returns aMyceliumClientstruct. The client connects to the local Mycelium node by default (http://localhost:8990). Connection failure produces a clear Rhai runtime error. All API surface from the typedMyceliumJSONRPCAPIClient(the OpenRPC-generated client) is wrapped, including the REST-layer functions fromclient.rsthat have no JSON-RPC equivalent (send_message,receive_messages).Requirements
MyceliumClientstruct registered as a Rhai custom type.mycelium_client_factory()(no args — connects tohttp://localhost:8990) andmycelium_client_factory(url)(one-arg overload) as the entry points.get_info,get_peers,add_peer,delete_peer,get_selected_routes,get_fallback_routes,get_public_key_from_ip,get_proxies,connect_proxy,disconnect_proxy.send_messageandreceive_messages.Mapfor structured objects,ArrayofMapfor lists.# Exampleblock in Rhai syntax.thread_local!+Arc<Runtime>for the Tokio runtime.MYCELIUM_URLstatic). URL lives on theMyceliumClientstruct.Files to Modify
crates/clients_rhai/src/mycelium.rscrates/clients_rhai/src/lib.rscrates/clients_rhai/Cargo.tomlImplementation Plan
Step 1: Rewrite
mycelium.rs— struct, factory, and thread-local runtimeMyceliumClientstruct withArc<TokioMutex<MyceliumJSONRPCAPIClient>>andrest_url: Stringmycelium_client_factory()(no-args, defaults tohttp://localhost:8990)mycelium_client_factory(url: String)(custom URL overload)thread_local!runtime helperStep 2: Implement node info and peer methods
get_info()→ Map withnode_pubkey,node_subnetget_peers()→ Array of Mapsadd_peer(endpoint: String)→ booldelete_peer(endpoint: String)→ boolStep 3: Implement route and proxy methods
get_selected_routes()→ Arrayget_fallback_routes()→ Arrayget_public_key_from_ip(ip: String)→ Stringget_proxies()→ Arrayconnect_proxy(remote: String)→ Stringdisconnect_proxy()→ boolStep 4: Implement REST messaging methods
send_message(dst, topic, msg, deadline_secs)→ Dynamicreceive_messages(topic, deadline_secs)→ DynamicStep 5: Implement
register_mycelium_moduleand register all methodsAcceptance Criteria
mycelium_client_factory()(no args) connects tohttp://localhost:8990mycelium_client_factory(url)connects to custom URLsend_messageandreceive_messageswrapped via REST client# Exampleblock--features myceliumand--features fulllib.rsandCargo.tomlremain unchangedRhai Usage Example
Test Results
herolib_clients_rhaicrateWorkspace (full
cargo test)herolib_crypt_rhai, 1 inherolib_vault_rhai)All crates that have tests passed:
herolib_core— 10 passedherolib_crypt— 2 passedherolib_crypt_rhai— 11 passedherolib_os— 3 passedherolib_clients— 8 passedherolib_vault— 7 passedherolib_vault_rhai— 1 passedherolib_do— 29 passedherolib_tools_rhai— 8 passedherolib_do(doc-test) — 29 passed + 1 passedNo failures or regressions detected in the workspace.
Build status: ✅ SUCCESS
Implementation Complete ✅
Changes Made
File modified:
crates/clients_rhai/src/mycelium.rs(complete rewrite)The Mycelium client Rhai wrapper has been rewritten to follow the factory pattern.
Key changes:
MyceliumClientstruct (holdsArc<TokioMutex<MyceliumJSONRPCAPIClient>>+rest_url)mycelium_client_factory()(no args, defaults tohttp://localhost:8990) andmycelium_client_factory(url)(custom URL overload)MYCELIUM_URLstatic)get_info,get_peers,add_peer,delete_peer,get_selected_routes,get_fallback_routes,get_public_key_from_ip,get_proxies,connect_proxy,disconnect_proxysend_message,receive_messages# Exampleblockslib.rsandCargo.tomlunchanged — no new dependenciesFiles unchanged:
lib.rs,Cargo.tomlTest Results
herolib_clients_rhaicrate: builds cleanly, 0 failuresRhai Usage
Implementation committed:
b4790daBrowse:
b4790da