@@ -2,16 +2,16 @@ use block::{GraphQLBlock, GraphQLUserCommands};
22use juniper:: { graphql_value, EmptySubscription , FieldError , GraphQLEnum , RootNode } ;
33use ledger:: Account ;
44use mina_p2p_messages:: v2:: {
5- MinaBaseSignedCommandStableV2 , MinaBaseUserCommandStableV2 ,
5+ conv , MinaBaseSignedCommandStableV2 , MinaBaseUserCommandStableV2 ,
66 MinaBaseZkappCommandTStableV1WireStableV1 , TokenIdKeyHash , TransactionHash ,
77} ;
88use node:: {
99 account:: AccountPublicKey ,
1010 rpc:: {
11- AccountQuery , GetBlockQuery , PooledUserCommandsQuery , RpcGetBlockResponse ,
12- RpcPooledUserCommandsResponse , RpcRequest , RpcSyncStatsGetResponse ,
13- RpcTransactionInjectResponse ,
14- RpcTransactionStatusGetResponse , SyncStatsQuery ,
11+ AccountQuery , GetBlockQuery , PooledCommandsQuery , RpcGetBlockResponse ,
12+ RpcPooledUserCommandsResponse , RpcPooledZkappCommandsResponse , RpcRequest ,
13+ RpcSyncStatsGetResponse , RpcTransactionInjectResponse , RpcTransactionStatusGetResponse ,
14+ SyncStatsQuery ,
1515 } ,
1616 stats:: sync:: SyncKind ,
1717} ;
@@ -23,6 +23,7 @@ use openmina_node_common::rpc::RpcSender;
2323use std:: str:: FromStr ;
2424use transaction:: GraphQLTransactionStatus ;
2525use warp:: { Filter , Rejection , Reply } ;
26+ use zkapp:: GraphQLZkapp ;
2627
2728pub mod account;
2829pub mod block;
@@ -53,6 +54,8 @@ pub enum ConversionError {
5354 SerdeJson ( #[ from] serde_json:: Error ) ,
5455 #[ error( "Base58Check: {0}" ) ]
5556 Base58Check ( #[ from] mina_p2p_messages:: b58:: FromBase58CheckError ) ,
57+ #[ error( "Base58 error: {0}" ) ]
58+ Base58 ( #[ from] bs58:: decode:: Error ) ,
5659 #[ error( transparent) ]
5760 InvalidDecimalNumber ( #[ from] mina_p2p_messages:: bigint:: InvalidDecimalNumber ) ,
5861 #[ error( "Invalid bigint" ) ]
@@ -322,42 +325,27 @@ impl Query {
322325 }
323326 }
324327
328+ /// Retrieve all the scheduled user commands for a specified sender that
329+ /// the current daemon sees in its transaction pool. All scheduled
330+ /// commands are queried if no sender is specified
331+ ///
332+ /// Arguments:
333+ /// - `public_key`: base58 encoded [`AccountPublicKey`]
334+ /// - `hashes`: list of base58 encoded [`TransactionHash`]es
335+ /// - `ids`: list of base64 encoded [`MinaBaseZkappCommandTStableV1WireStableV1`]
325336 async fn pooled_user_commands (
326337 & self ,
327338 public_key : Option < String > ,
328339 hashes : Option < Vec < String > > ,
329340 ids : Option < Vec < String > > ,
330341 context : & Context ,
331342 ) -> juniper:: FieldResult < Vec < GraphQLUserCommands > > {
332- let public_key = match public_key {
333- Some ( public_key) => Some ( AccountPublicKey :: from_str ( & public_key) ?) ,
334- None => None ,
335- } ;
336-
337- let hashes = match hashes {
338- Some ( hashes) => Some (
339- hashes
340- . into_iter ( )
341- . map ( |tx| TransactionHash :: from_str ( tx. as_str ( ) ) )
342- . collect :: < Result < Vec < _ > , _ > > ( ) ?,
343- ) ,
344- None => None ,
345- } ;
346-
347- let ids = match ids {
348- Some ( ids) => Some (
349- ids. into_iter ( )
350- . map ( |id| MinaBaseSignedCommandStableV2 :: from_base64 ( id. as_str ( ) ) )
351- . collect :: < Result < Vec < _ > , _ > > ( ) ?,
352- ) ,
353- None => None ,
354- } ;
355-
356- let query = PooledUserCommandsQuery {
343+ let query = parse_pooled_commands_query (
357344 public_key,
358345 hashes,
359346 ids,
360- } ;
347+ MinaBaseSignedCommandStableV2 :: from_base64,
348+ ) ?;
361349
362350 let res: RpcPooledUserCommandsResponse = context
363351 . 0
@@ -370,6 +358,39 @@ impl Query {
370358 . map ( GraphQLUserCommands :: try_from)
371359 . collect :: < Result < Vec < _ > , _ > > ( ) ?)
372360 }
361+
362+ /// Retrieve all the scheduled zkApp commands for a specified sender that
363+ /// the current daemon sees in its transaction pool. All scheduled
364+ /// commands are queried if no sender is specified
365+ ///
366+ /// Arguments:
367+ /// - `public_key`: base58 encoded [`AccountPublicKey`]
368+ /// - `hashes`: list of base58 encoded [`TransactionHash`]es
369+ /// - `ids`: list of base64 encoded [`MinaBaseZkappCommandTStableV1WireStableV1`]
370+ async fn pooled_zkapp_commands (
371+ public_key : Option < String > ,
372+ hashes : Option < Vec < String > > ,
373+ ids : Option < Vec < String > > ,
374+ context : & Context ,
375+ ) -> juniper:: FieldResult < Vec < GraphQLZkapp > > {
376+ let query = parse_pooled_commands_query (
377+ public_key,
378+ hashes,
379+ ids,
380+ MinaBaseZkappCommandTStableV1WireStableV1 :: from_base64,
381+ ) ?;
382+
383+ let res: RpcPooledZkappCommandsResponse = context
384+ . 0
385+ . oneshot_request ( RpcRequest :: PooledZkappCommands ( query) )
386+ . await
387+ . ok_or ( Error :: StateMachineEmptyResponse ) ?;
388+
389+ Ok ( res
390+ . into_iter ( )
391+ . map ( GraphQLZkapp :: try_from)
392+ . collect :: < Result < Vec < _ > , _ > > ( ) ?)
393+ }
373394}
374395
375396async fn inject_tx < R > (
@@ -540,3 +561,44 @@ pub fn routes(
540561// )))
541562// .or(homepage)
542563// .with(log);
564+
565+ /// Helper function used by [`Query::pooled_user_commands`] and [`Query::pooled_zkapp_commands`] to parse public key, transaction hashes and command ids
566+ fn parse_pooled_commands_query < ID , F > (
567+ public_key : Option < String > ,
568+ hashes : Option < Vec < String > > ,
569+ ids : Option < Vec < String > > ,
570+ id_map_fn : F ,
571+ ) -> Result < PooledCommandsQuery < ID > , ConversionError >
572+ where
573+ F : Fn ( & str ) -> Result < ID , conv:: Error > ,
574+ {
575+ let public_key = match public_key {
576+ Some ( public_key) => Some ( AccountPublicKey :: from_str ( & public_key) ?) ,
577+ None => None ,
578+ } ;
579+
580+ let hashes = match hashes {
581+ Some ( hashes) => Some (
582+ hashes
583+ . into_iter ( )
584+ . map ( |tx| TransactionHash :: from_str ( tx. as_str ( ) ) )
585+ . collect :: < Result < Vec < _ > , _ > > ( ) ?,
586+ ) ,
587+ None => None ,
588+ } ;
589+
590+ let ids = match ids {
591+ Some ( ids) => Some (
592+ ids. into_iter ( )
593+ . map ( |id| id_map_fn ( id. as_str ( ) ) )
594+ . collect :: < Result < Vec < _ > , _ > > ( ) ?,
595+ ) ,
596+ None => None ,
597+ } ;
598+
599+ Ok ( PooledCommandsQuery {
600+ public_key,
601+ hashes,
602+ ids,
603+ } )
604+ }
0 commit comments