rialo_s_client_traits/
lib.rs1use rialo_hash::Hash;
11use rialo_s_account::Account;
12use rialo_s_commitment_config::CommitmentConfig;
13use rialo_s_epoch_info::EpochInfo;
14use rialo_s_instruction::Instruction;
15use rialo_s_keypair::Keypair;
16use rialo_s_message::Message;
17use rialo_s_pubkey::Pubkey;
18use rialo_s_signature::Signature;
19use rialo_s_signer::{signers::Signers, Signer};
20use rialo_s_system_interface::instruction::transfer;
21use rialo_s_transaction::{versioned::VersionedTransaction, Transaction};
22use rialo_s_transaction_error::{TransactionResult, TransportResult as Result};
23
24pub trait Client: SyncClient + AsyncClient {
25 fn tpu_addr(&self) -> String;
26}
27
28pub trait SyncClient {
29 fn send_and_confirm_message<T: Signers + ?Sized>(
32 &self,
33 keypairs: &T,
34 message: Message,
35 ) -> Result<Signature>;
36
37 fn send_and_confirm_instruction(
40 &self,
41 keypair: &Keypair,
42 instruction: Instruction,
43 ) -> Result<Signature>;
44
45 fn transfer_and_confirm(
48 &self,
49 kelvins: u64,
50 keypair: &Keypair,
51 pubkey: &Pubkey,
52 ) -> Result<Signature>;
53
54 fn get_account_data(&self, pubkey: &Pubkey) -> Result<Option<Vec<u8>>>;
56
57 fn get_account(&self, pubkey: &Pubkey) -> Result<Option<Account>>;
59
60 fn get_account_with_commitment(
62 &self,
63 pubkey: &Pubkey,
64 commitment_config: CommitmentConfig,
65 ) -> Result<Option<Account>>;
66
67 fn get_balance(&self, pubkey: &Pubkey) -> Result<u64>;
69
70 fn get_balance_with_commitment(
72 &self,
73 pubkey: &Pubkey,
74 commitment_config: CommitmentConfig,
75 ) -> Result<u64>;
76
77 fn get_minimum_balance_for_rent_exemption(&self, data_len: usize) -> Result<u64>;
78
79 fn get_signature_status(&self, signature: &Signature) -> Result<Option<TransactionResult<()>>>;
81
82 fn get_signature_status_with_commitment(
84 &self,
85 signature: &Signature,
86 commitment_config: CommitmentConfig,
87 ) -> Result<Option<TransactionResult<()>>>;
88
89 fn get_slot(&self) -> Result<u64>;
91
92 fn get_slot_with_commitment(&self, commitment_config: CommitmentConfig) -> Result<u64>;
94
95 fn get_transaction_count(&self) -> Result<u64>;
97
98 fn get_transaction_count_with_commitment(
100 &self,
101 commitment_config: CommitmentConfig,
102 ) -> Result<u64>;
103
104 fn get_epoch_info(&self) -> Result<EpochInfo>;
105
106 fn poll_for_signature_confirmation(
108 &self,
109 signature: &Signature,
110 min_confirmed_blocks: usize,
111 ) -> Result<usize>;
112
113 fn poll_for_signature(&self, signature: &Signature) -> Result<()>;
115
116 fn get_bank_time(&self) -> Result<i64>;
118
119 fn is_blockhash_valid(&self, blockhash: &Hash, commitment: CommitmentConfig) -> Result<bool>;
121
122 fn get_fee_for_message(&self, message: &Message) -> Result<u64>;
124}
125
126pub trait AsyncClient {
127 fn async_send_transaction(&self, transaction: Transaction) -> Result<Signature> {
129 self.async_send_versioned_transaction(transaction.into())
130 }
131
132 fn async_send_batch(&self, transactions: Vec<Transaction>) -> Result<()> {
134 let transactions = transactions.into_iter().map(Into::into).collect();
135 self.async_send_versioned_transaction_batch(transactions)
136 }
137
138 fn async_send_versioned_transaction(
140 &self,
141 transaction: VersionedTransaction,
142 ) -> Result<Signature>;
143
144 fn async_send_versioned_transaction_batch(
146 &self,
147 transactions: Vec<VersionedTransaction>,
148 ) -> Result<()> {
149 for t in transactions {
150 self.async_send_versioned_transaction(t)?;
151 }
152 Ok(())
153 }
154
155 fn async_send_message<T: Signers + ?Sized>(
158 &self,
159 keypairs: &T,
160 message: Message,
161 valid_from: i64,
162 ) -> Result<Signature> {
163 let transaction = Transaction::new(keypairs, message, valid_from);
164 self.async_send_transaction(transaction)
165 }
166
167 fn async_send_instruction(
170 &self,
171 keypair: &Keypair,
172 instruction: Instruction,
173 valid_from: i64,
174 ) -> Result<Signature> {
175 let message = Message::new(&[instruction], Some(&keypair.pubkey()));
176 self.async_send_message(&[keypair], message, valid_from)
177 }
178
179 fn async_transfer(
181 &self,
182 kelvins: u64,
183 keypair: &Keypair,
184 pubkey: &Pubkey,
185 valid_from: i64,
186 ) -> Result<Signature> {
187 let transfer_instruction = transfer(&keypair.pubkey(), pubkey, kelvins);
188 self.async_send_instruction(keypair, transfer_instruction, valid_from)
189 }
190}