1+ use crate :: common:: NodeDetails ;
12use crate :: p2p_handler:: auth:: AuthenticationManager ;
23use crate :: p2p_handler:: message_processor:: { MessageProcessor , MessageProcessorConfig } ;
34use crate :: p2p_handler:: { Message , MessageType , Service as P2PService } ;
@@ -12,6 +13,9 @@ use tokio::task::JoinHandle;
1213use tokio_util:: sync:: CancellationToken ;
1314use url:: Url ;
1415
16+ // Add new imports for discovery functionality
17+ use shared:: discovery:: fetch_nodes_from_discovery_urls;
18+
1519/// Prime Protocol Orchestrator Client - for managing and distributing tasks
1620#[ pyclass]
1721pub struct OrchestratorClient {
@@ -24,13 +28,19 @@ pub struct OrchestratorClient {
2428 user_message_rx : Option < Arc < Mutex < Receiver < Message > > > > ,
2529 message_processor_handle : Option < JoinHandle < ( ) > > ,
2630 peer_id : Option < PeerId > ,
31+ // Discovery service URLs
32+ discovery_urls : Vec < String > ,
2733}
2834
2935#[ pymethods]
3036impl OrchestratorClient {
3137 #[ new]
32- #[ pyo3( signature = ( rpc_url, private_key=None ) ) ]
33- pub fn new ( rpc_url : String , private_key : Option < String > ) -> PyResult < Self > {
38+ #[ pyo3( signature = ( rpc_url, private_key=None , discovery_urls=vec![ "http://localhost:8089" . to_string( ) ] ) ) ]
39+ pub fn new (
40+ rpc_url : String ,
41+ private_key : Option < String > ,
42+ discovery_urls : Vec < String > ,
43+ ) -> PyResult < Self > {
3444 let runtime = tokio:: runtime:: Builder :: new_multi_thread ( )
3545 . enable_all ( )
3646 . build ( )
@@ -60,6 +70,7 @@ impl OrchestratorClient {
6070 user_message_rx : None ,
6171 message_processor_handle : None ,
6272 peer_id : None ,
73+ discovery_urls,
6374 } )
6475 }
6576
@@ -201,14 +212,28 @@ impl OrchestratorClient {
201212 Ok ( ( ) )
202213 }
203214
204- pub fn list_validated_nodes ( & self ) -> PyResult < Vec < String > > {
205- // TODO: Implement orchestrator node listing
206- Ok ( vec ! [ ] )
207- }
215+ /// List nodes for a specific compute pool
216+ pub fn list_nodes_for_pool ( & self , py : Python , pool_id : u32 ) -> PyResult < Vec < NodeDetails > > {
217+ let rt = self . get_or_create_runtime ( ) ?;
218+
219+ let wallet = self . wallet . as_ref ( ) . ok_or_else ( || {
220+ PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > (
221+ "Wallet not initialized. Provide private_key when creating client." ,
222+ )
223+ } ) ?;
224+
225+ let discovery_urls = self . discovery_urls . clone ( ) ;
226+ let route = format ! ( "/api/pool/{}" , pool_id) ;
227+
228+ let nodes = py. allow_threads ( || {
229+ rt. block_on ( async {
230+ fetch_nodes_from_discovery_urls ( & discovery_urls, & route, wallet)
231+ . await
232+ . map_err ( |e| PyErr :: new :: < pyo3:: exceptions:: PyRuntimeError , _ > ( e. to_string ( ) ) )
233+ } )
234+ } ) ?;
208235
209- pub fn list_nodes_from_chain ( & self ) -> PyResult < Vec < String > > {
210- // TODO: Implement orchestrator node listing from chain
211- Ok ( vec ! [ ] )
236+ Ok ( nodes. into_iter ( ) . map ( NodeDetails :: from) . collect ( ) )
212237 }
213238}
214239
0 commit comments