Add SyncClient and use from BankClient

This commit is contained in:
Greg Fitzgerald
2019-04-03 15:11:08 -06:00
parent acbc261891
commit 5cd7bccdf3
13 changed files with 108 additions and 60 deletions

View File

@ -13,6 +13,7 @@ pub mod pubkey;
pub mod rpc_port;
pub mod short_vec;
pub mod signature;
pub mod sync_client;
pub mod system_instruction;
pub mod system_program;
pub mod system_transaction;

33
sdk/src/sync_client.rs Normal file
View File

@ -0,0 +1,33 @@
//! Defines a trait for blocking (synchronous) communication with a Solana server.
//! Implementations are expected to create tranasctions, sign them, and send
//! them with multiple retries, updating blockhashes and resigning as-needed.
use crate::instruction::Instruction;
use crate::message::Message;
use crate::pubkey::Pubkey;
use crate::signature::Keypair;
use crate::transaction::TransactionError;
pub trait SyncClient {
/// Create a transaction from the given message, and send it to the
/// server, retrying as-needed.
fn send_message(&self, keypairs: &[&Keypair], message: Message)
-> Result<(), TransactionError>;
/// Create a transaction from a single instruction that only requires
/// a single signer. Then send it to the server, retrying as-needed.
fn send_instruction(
&self,
keypair: &Keypair,
instruction: Instruction,
) -> Result<(), TransactionError>;
/// Transfer lamports from `keypair` to `pubkey`, retrying until the
/// transfer completes or produces and error.
fn transfer(
&self,
lamports: u64,
keypair: &Keypair,
pubkey: &Pubkey,
) -> Result<(), TransactionError>;
}