1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Mock types for use in examples.
//!
//! These represent APIs from crates that themselves depend on this crate, and
//! which are useful for illustrating the examples for APIs in this crate.
//!
//! Directly depending on these crates though would cause problematic circular
//! dependencies, so instead they are mocked out here in a way that allows
//! examples to appear to use crates that this crate must not depend on.
//!
//! Each mod here has the name of a crate, so that examples can be structured to
//! appear to import from that crate.
#![doc(hidden)]
#![allow(clippy::new_without_default)]
pub mod solana_client {
pub mod client_error {
use thiserror::Error;
#[derive(Error, Debug)]
#[error("mock-error")]
pub struct ClientError;
pub type Result<T> = std::result::Result<T, ClientError>;
}
pub mod rpc_client {
use super::{
super::solana_sdk::{hash::Hash, signature::Signature, transaction::Transaction},
client_error::Result as ClientResult,
};
pub struct RpcClient;
impl RpcClient {
pub fn new(_url: String) -> Self {
RpcClient
}
pub fn get_latest_blockhash(&self) -> ClientResult<Hash> {
Ok(Hash::default())
}
pub fn send_and_confirm_transaction(
&self,
_transaction: &Transaction,
) -> ClientResult<Signature> {
Ok(Signature::default())
}
pub fn get_minimum_balance_for_rent_exemption(
&self,
_data_len: usize,
) -> ClientResult<u64> {
Ok(0)
}
}
}
}
/// Re-exports and mocks of solana-program modules that mirror those from
/// solana-program.
///
/// This lets examples in solana-program appear to be written as client
/// programs.
pub mod solana_sdk {
pub use crate::{hash, instruction, message, nonce, pubkey, system_instruction};
pub mod signature {
use crate::pubkey::Pubkey;
#[derive(Default)]
pub struct Signature;
pub struct Keypair;
impl Keypair {
pub fn new() -> Keypair {
Keypair
}
pub fn pubkey(&self) -> Pubkey {
Pubkey::default()
}
}
impl Signer for Keypair {}
pub trait Signer {}
}
pub mod signers {
use super::signature::Signer;
pub trait Signers {}
impl<T: Signer> Signers for [&T; 1] {}
impl<T: Signer> Signers for [&T; 2] {}
}
pub mod transaction {
use {
super::signers::Signers,
crate::{hash::Hash, instruction::Instruction, message::Message, pubkey::Pubkey},
};
pub struct Transaction {
pub message: Message,
}
impl Transaction {
pub fn new<T: Signers>(
_from_keypairs: &T,
_message: Message,
_recent_blockhash: Hash,
) -> Transaction {
Transaction {
message: Message::new(&[], None),
}
}
pub fn new_unsigned(_message: Message) -> Self {
Transaction {
message: Message::new(&[], None),
}
}
pub fn new_with_payer(_instructions: &[Instruction], _payer: Option<&Pubkey>) -> Self {
Transaction {
message: Message::new(&[], None),
}
}
pub fn sign<T: Signers>(&mut self, _keypairs: &T, _recent_blockhash: Hash) {}
}
}
}