Wrap all client errors with TransportError
This commit is contained in:
@ -19,6 +19,7 @@ pub mod system_program;
|
||||
pub mod system_transaction;
|
||||
pub mod timing;
|
||||
pub mod transaction;
|
||||
pub mod transport;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
@ -6,37 +6,24 @@ use crate::instruction::Instruction;
|
||||
use crate::message::Message;
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::signature::{Keypair, Signature};
|
||||
use crate::transaction::TransactionError;
|
||||
use crate::transport::Result;
|
||||
|
||||
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<Signature, TransactionError>;
|
||||
fn send_message(&self, keypairs: &[&Keypair], message: Message) -> Result<Signature>;
|
||||
|
||||
/// 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<Signature, TransactionError>;
|
||||
fn send_instruction(&self, keypair: &Keypair, instruction: Instruction) -> Result<Signature>;
|
||||
|
||||
/// 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<Signature, TransactionError>;
|
||||
fn transfer(&self, lamports: u64, keypair: &Keypair, pubkey: &Pubkey) -> Result<Signature>;
|
||||
|
||||
/// Get an account or None if not found.
|
||||
fn get_account_data(&self, pubkey: &Pubkey) -> Option<Vec<u8>>;
|
||||
fn get_account_data(&self, pubkey: &Pubkey) -> Result<Option<Vec<u8>>>;
|
||||
|
||||
/// Get account balance or 0 if not found.
|
||||
fn get_balance(&self, pubkey: &Pubkey) -> u64;
|
||||
fn get_balance(&self, pubkey: &Pubkey) -> Result<u64>;
|
||||
}
|
||||
|
32
sdk/src/transport.rs
Normal file
32
sdk/src/transport.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use crate::transaction::TransactionError;
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum TransportError {
|
||||
IoError(io::Error),
|
||||
TransactionError(TransactionError),
|
||||
}
|
||||
|
||||
impl TransportError {
|
||||
pub fn unwrap(&self) -> TransactionError {
|
||||
if let TransportError::TransactionError(err) = self {
|
||||
err.clone()
|
||||
} else {
|
||||
panic!("unexpected transport error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for TransportError {
|
||||
fn from(err: io::Error) -> TransportError {
|
||||
TransportError::IoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TransactionError> for TransportError {
|
||||
fn from(err: TransactionError) -> TransportError {
|
||||
TransportError::TransactionError(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, TransportError>;
|
Reference in New Issue
Block a user