Skip to main content

solana_sdk/
example_mocks.rs

1//! Mock types for use in examples.
2//!
3//! These represent APIs from crates that themselves depend on this crate, and
4//! which are useful for illustrating the examples for APIs in this crate.
5//!
6//! Directly depending on these crates though would cause problematic circular
7//! dependencies, so instead they are mocked out here in a way that allows
8//! examples to appear to use crates that this crate must not depend on.
9//!
10//! Each mod here has the name of a crate, so that examples can be structured to
11//! appear to import from that crate.
12
13#![doc(hidden)]
14#![cfg(feature = "full")]
15
16pub mod solana_rpc_client {
17    pub mod rpc_client {
18        use {
19            super::super::solana_rpc_client_api::client_error::Result as ClientResult,
20            crate::{hash::Hash, signature::Signature, transaction::Transaction},
21        };
22
23        pub struct RpcClient;
24
25        impl RpcClient {
26            pub fn new(_url: String) -> Self {
27                RpcClient
28            }
29            pub fn get_latest_blockhash(&self) -> ClientResult<Hash> {
30                Ok(Hash::default())
31            }
32            pub fn send_and_confirm_transaction(
33                &self,
34                _transaction: &Transaction,
35            ) -> ClientResult<Signature> {
36                Ok(Signature::default())
37            }
38        }
39    }
40}
41
42pub mod solana_rpc_client_api {
43    pub mod client_error {
44        use thiserror::Error;
45
46        #[derive(Error, Debug)]
47        #[error("mock-error")]
48        pub struct ClientError;
49        pub type Result<T> = std::result::Result<T, ClientError>;
50    }
51}