|
1 |
| -use block::GraphQLBlock; |
2 |
| -use juniper::{graphql_value, FieldError}; |
3 |
| -use juniper::{EmptySubscription, GraphQLEnum, RootNode}; |
| 1 | +use block::{GraphQLBlock, GraphQLUserCommands}; |
| 2 | +use juniper::{graphql_value, EmptySubscription, FieldError, GraphQLEnum, RootNode}; |
4 | 3 | use ledger::Account;
|
5 |
| -use mina_p2p_messages::v2::MinaBaseSignedCommandStableV2; |
6 |
| -use mina_p2p_messages::v2::MinaBaseUserCommandStableV2; |
7 |
| -use mina_p2p_messages::v2::MinaBaseZkappCommandTStableV1WireStableV1; |
8 |
| -use mina_p2p_messages::v2::TokenIdKeyHash; |
9 |
| -use node::rpc::RpcTransactionInjectResponse; |
10 |
| -use node::rpc::{GetBlockQuery, RpcGetBlockResponse, RpcTransactionStatusGetResponse}; |
| 4 | +use mina_p2p_messages::v2::{ |
| 5 | + conv, MinaBaseSignedCommandStableV2, MinaBaseUserCommandStableV2, |
| 6 | + MinaBaseZkappCommandTStableV1WireStableV1, TokenIdKeyHash, TransactionHash, |
| 7 | +}; |
11 | 8 | use node::{
|
12 | 9 | account::AccountPublicKey,
|
13 |
| - rpc::{AccountQuery, RpcRequest, RpcSyncStatsGetResponse, SyncStatsQuery}, |
| 10 | + rpc::{ |
| 11 | + AccountQuery, GetBlockQuery, PooledCommandsQuery, RpcGetBlockResponse, |
| 12 | + RpcPooledUserCommandsResponse, RpcPooledZkappCommandsResponse, RpcRequest, |
| 13 | + RpcSyncStatsGetResponse, RpcTransactionInjectResponse, RpcTransactionStatusGetResponse, |
| 14 | + SyncStatsQuery, |
| 15 | + }, |
14 | 16 | stats::sync::SyncKind,
|
15 | 17 | };
|
16 | 18 | use o1_utils::field_helpers::FieldHelpersError;
|
17 |
| -use openmina_core::block::AppliedBlock; |
18 |
| -use openmina_core::consensus::ConsensusConstants; |
19 |
| -use openmina_core::constants::constraint_constants; |
| 19 | +use openmina_core::{ |
| 20 | + block::AppliedBlock, consensus::ConsensusConstants, constants::constraint_constants, |
| 21 | +}; |
20 | 22 | use openmina_node_common::rpc::RpcSender;
|
21 | 23 | use std::str::FromStr;
|
22 | 24 | use transaction::GraphQLTransactionStatus;
|
23 | 25 | use warp::{Filter, Rejection, Reply};
|
| 26 | +use zkapp::GraphQLZkapp; |
24 | 27 |
|
25 | 28 | pub mod account;
|
26 | 29 | pub mod block;
|
@@ -51,6 +54,8 @@ pub enum ConversionError {
|
51 | 54 | SerdeJson(#[from] serde_json::Error),
|
52 | 55 | #[error("Base58Check: {0}")]
|
53 | 56 | Base58Check(#[from] mina_p2p_messages::b58::FromBase58CheckError),
|
| 57 | + #[error("Base58 error: {0}")] |
| 58 | + Base58(#[from] bs58::decode::Error), |
54 | 59 | #[error(transparent)]
|
55 | 60 | InvalidDecimalNumber(#[from] mina_p2p_messages::bigint::InvalidDecimalNumber),
|
56 | 61 | #[error("Invalid bigint")]
|
@@ -319,6 +324,73 @@ impl Query {
|
319 | 324 | Some(Some(block)) => Ok(GraphQLBlock::try_from(block)?),
|
320 | 325 | }
|
321 | 326 | }
|
| 327 | + |
| 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`] |
| 336 | + async fn pooled_user_commands( |
| 337 | + &self, |
| 338 | + public_key: Option<String>, |
| 339 | + hashes: Option<Vec<String>>, |
| 340 | + ids: Option<Vec<String>>, |
| 341 | + context: &Context, |
| 342 | + ) -> juniper::FieldResult<Vec<GraphQLUserCommands>> { |
| 343 | + let query = parse_pooled_commands_query( |
| 344 | + public_key, |
| 345 | + hashes, |
| 346 | + ids, |
| 347 | + MinaBaseSignedCommandStableV2::from_base64, |
| 348 | + )?; |
| 349 | + |
| 350 | + let res: RpcPooledUserCommandsResponse = context |
| 351 | + .0 |
| 352 | + .oneshot_request(RpcRequest::PooledUserCommands(query)) |
| 353 | + .await |
| 354 | + .ok_or(Error::StateMachineEmptyResponse)?; |
| 355 | + |
| 356 | + Ok(res |
| 357 | + .into_iter() |
| 358 | + .map(GraphQLUserCommands::try_from) |
| 359 | + .collect::<Result<Vec<_>, _>>()?) |
| 360 | + } |
| 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 | + } |
322 | 394 | }
|
323 | 395 |
|
324 | 396 | async fn inject_tx<R>(
|
@@ -371,6 +443,7 @@ where
|
371 | 443 | }
|
372 | 444 | }
|
373 | 445 | }
|
| 446 | + |
374 | 447 | #[derive(Clone, Debug)]
|
375 | 448 | struct Mutation;
|
376 | 449 |
|
@@ -488,3 +561,44 @@ pub fn routes(
|
488 | 561 | // )))
|
489 | 562 | // .or(homepage)
|
490 | 563 | // .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