2019-04-03 15:11:08 -06:00
|
|
|
//! 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;
|
2019-04-03 16:36:10 -06:00
|
|
|
use crate::signature::{Keypair, Signature};
|
2019-04-03 15:11:08 -06:00
|
|
|
use crate::transaction::TransactionError;
|
|
|
|
|
|
|
|
|
|
pub trait SyncClient {
|
|
|
|
|
/// Create a transaction from the given message, and send it to the
|
|
|
|
|
/// server, retrying as-needed.
|
2019-04-03 16:36:10 -06:00
|
|
|
fn send_message(
|
|
|
|
|
&self,
|
|
|
|
|
keypairs: &[&Keypair],
|
|
|
|
|
message: Message,
|
|
|
|
|
) -> Result<Signature, TransactionError>;
|
2019-04-03 15:11:08 -06:00
|
|
|
|
|
|
|
|
/// 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,
|
2019-04-03 16:36:10 -06:00
|
|
|
) -> Result<Signature, TransactionError>;
|
2019-04-03 15:11:08 -06:00
|
|
|
|
|
|
|
|
/// Transfer lamports from `keypair` to `pubkey`, retrying until the
|
|
|
|
|
/// transfer completes or produces and error.
|
|
|
|
|
fn transfer(
|
|
|
|
|
&self,
|
|
|
|
|
lamports: u64,
|
|
|
|
|
keypair: &Keypair,
|
|
|
|
|
pubkey: &Pubkey,
|
2019-04-03 16:36:10 -06:00
|
|
|
) -> Result<Signature, TransactionError>;
|
|
|
|
|
|
|
|
|
|
/// Get an account or None if not found.
|
|
|
|
|
fn get_account_data(&self, pubkey: &Pubkey) -> Option<Vec<u8>>;
|
|
|
|
|
|
|
|
|
|
/// Get account balance or 0 if not found.
|
|
|
|
|
fn get_balance(&self, pubkey: &Pubkey) -> u64;
|
2019-04-03 15:11:08 -06:00
|
|
|
}
|