@ -21,7 +21,6 @@ use crate::{
|
||||
transaction,
|
||||
transport::Result,
|
||||
};
|
||||
use std::io;
|
||||
|
||||
pub trait Client: SyncClient + AsyncClient {
|
||||
fn tpu_addr(&self) -> String;
|
||||
@ -122,10 +121,7 @@ pub trait SyncClient {
|
||||
|
||||
pub trait AsyncClient {
|
||||
/// Send a signed transaction, but don't wait to see if the server accepted it.
|
||||
fn async_send_transaction(
|
||||
&self,
|
||||
transaction: transaction::Transaction,
|
||||
) -> io::Result<Signature>;
|
||||
fn async_send_transaction(&self, transaction: transaction::Transaction) -> Result<Signature>;
|
||||
|
||||
/// Create a transaction from the given message, and send it to the
|
||||
/// server, but don't wait for to see if the server accepted it.
|
||||
@ -134,7 +130,7 @@ pub trait AsyncClient {
|
||||
keypairs: &T,
|
||||
message: Message,
|
||||
recent_blockhash: Hash,
|
||||
) -> io::Result<Signature>;
|
||||
) -> Result<Signature>;
|
||||
|
||||
/// Create a transaction from a single instruction that only requires
|
||||
/// a single signer. Then send it to the server, but don't wait for a reply.
|
||||
@ -143,7 +139,7 @@ pub trait AsyncClient {
|
||||
keypair: &Keypair,
|
||||
instruction: Instruction,
|
||||
recent_blockhash: Hash,
|
||||
) -> io::Result<Signature>;
|
||||
) -> Result<Signature>;
|
||||
|
||||
/// Attempt to transfer lamports from `keypair` to `pubkey`, but don't wait to confirm.
|
||||
fn async_transfer(
|
||||
@ -152,5 +148,5 @@ pub trait AsyncClient {
|
||||
keypair: &Keypair,
|
||||
pubkey: &Pubkey,
|
||||
recent_blockhash: Hash,
|
||||
) -> io::Result<Signature>;
|
||||
) -> Result<Signature>;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{convert::TryFrom, fmt, mem, str::FromStr};
|
||||
use thiserror::Error;
|
||||
|
||||
pub const HASH_BYTES: usize = 32;
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
@ -47,9 +48,11 @@ impl fmt::Display for Hash {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
pub enum ParseHashError {
|
||||
#[error("string decoded to wrong size for hash")]
|
||||
WrongSize,
|
||||
#[error("failed to decoded string to hash")]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
|
@ -3,96 +3,124 @@
|
||||
use crate::{pubkey::Pubkey, short_vec, system_instruction::SystemError};
|
||||
use bincode::serialize;
|
||||
use serde::Serialize;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Reasons the runtime might have rejected an instruction.
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Serialize, Deserialize, Debug, Error, PartialEq, Eq, Clone)]
|
||||
pub enum InstructionError {
|
||||
/// Deprecated! Use CustomError instead!
|
||||
/// The program instruction returned an error
|
||||
#[error("generic instruction error")]
|
||||
GenericError,
|
||||
|
||||
/// The arguments provided to a program instruction where invalid
|
||||
/// The arguments provided to a program were invalid
|
||||
#[error("invalid program argument")]
|
||||
InvalidArgument,
|
||||
|
||||
/// An instruction's data contents was invalid
|
||||
/// An instruction's data contents were invalid
|
||||
#[error("invalid instruction data")]
|
||||
InvalidInstructionData,
|
||||
|
||||
/// An account's data contents was invalid
|
||||
#[error("invalid account data for instruction")]
|
||||
InvalidAccountData,
|
||||
|
||||
/// An account's data was too small
|
||||
#[error("account data too small for instruction")]
|
||||
AccountDataTooSmall,
|
||||
|
||||
/// An account's balance was too small to complete the instruction
|
||||
#[error("insufficient funds for instruction")]
|
||||
InsufficientFunds,
|
||||
|
||||
/// The account did not have the expected program id
|
||||
#[error("incorrect program id for instruction")]
|
||||
IncorrectProgramId,
|
||||
|
||||
/// A signature was required but not found
|
||||
#[error("missing required signature for instruction")]
|
||||
MissingRequiredSignature,
|
||||
|
||||
/// An initialize instruction was sent to an account that has already been initialized.
|
||||
#[error("instruction requires an uninitialized account")]
|
||||
AccountAlreadyInitialized,
|
||||
|
||||
/// An attempt to operate on an account that hasn't been initialized.
|
||||
#[error("instruction requires an initialized account")]
|
||||
UninitializedAccount,
|
||||
|
||||
/// Program's instruction lamport balance does not equal the balance after the instruction
|
||||
#[error("sum of account balances before and after instruction do not match")]
|
||||
UnbalancedInstruction,
|
||||
|
||||
/// Program modified an account's program id
|
||||
#[error("instruction modified the program id of an account")]
|
||||
ModifiedProgramId,
|
||||
|
||||
/// Program spent the lamports of an account that doesn't belong to it
|
||||
#[error("instruction spent from the balance of an account it does not own")]
|
||||
ExternalAccountLamportSpend,
|
||||
|
||||
/// Program modified the data of an account that doesn't belong to it
|
||||
#[error("instruction modified data of an account it does not own")]
|
||||
ExternalAccountDataModified,
|
||||
|
||||
/// Read-only account modified lamports
|
||||
#[error("instruction changed balance of a read-only account")]
|
||||
ReadonlyLamportChange,
|
||||
|
||||
/// Read-only account modified data
|
||||
#[error("instruction modified data of a read-only account")]
|
||||
ReadonlyDataModified,
|
||||
|
||||
/// An account was referenced more than once in a single instruction
|
||||
// Deprecated, instructions can now contain duplicate accounts
|
||||
#[error("instruction contains duplicate accounts")]
|
||||
DuplicateAccountIndex,
|
||||
|
||||
/// Executable bit on account changed, but shouldn't have
|
||||
#[error("instruction changed executable bit of an account")]
|
||||
ExecutableModified,
|
||||
|
||||
/// Rent_epoch account changed, but shouldn't have
|
||||
#[error("instruction modified rent epoch of an account")]
|
||||
RentEpochModified,
|
||||
|
||||
/// The instruction expected additional account keys
|
||||
#[error("insufficient account key count for instruction")]
|
||||
NotEnoughAccountKeys,
|
||||
|
||||
/// A non-system program changed the size of the account data
|
||||
#[error("non-system instruction changed account size")]
|
||||
AccountDataSizeChanged,
|
||||
|
||||
/// The instruction expected an executable account
|
||||
#[error("instruction expected an executable account")]
|
||||
AccountNotExecutable,
|
||||
|
||||
/// Failed to borrow a reference to account data, already borrowed
|
||||
#[error("instruction tries to borrow reference for an account which is already borrowed")]
|
||||
AccountBorrowFailed,
|
||||
|
||||
/// Account data has an outstanding reference after a program's execution
|
||||
#[error("instruction left account with an outstanding reference borrowed")]
|
||||
AccountBorrowOutstanding,
|
||||
|
||||
/// The same account was multiply passed to an on-chain program's entrypoint, but the program
|
||||
/// modified them differently. A program can only modify one instance of the account because
|
||||
/// the runtime cannot determine which changes to pick or how to merge them if both are modified
|
||||
#[error("instruction modifications of multiply-passed account differ")]
|
||||
DuplicateAccountOutOfSync,
|
||||
|
||||
/// Allows on-chain programs to implement program-specific error types and see them returned
|
||||
/// by the Solana runtime. A program-specific error may be any type that is represented as
|
||||
/// or serialized to a u32 integer.
|
||||
#[error("program error: {0}")]
|
||||
CustomError(u32),
|
||||
|
||||
/// The return value from the program was invalid. Valid errors are either a defined builtin
|
||||
/// error value or a user-defined error in the lower 32 bits.
|
||||
#[error("program returned invalid error code")]
|
||||
InvalidError,
|
||||
}
|
||||
|
||||
|
@ -107,9 +107,11 @@ impl Into<[u8; 64]> for Signature {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error)]
|
||||
pub enum ParseSignatureError {
|
||||
#[error("string decoded to wrong size for signature")]
|
||||
WrongSize,
|
||||
#[error("failed to decode string to signature")]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,15 @@
|
||||
use crate::transaction::TransactionError;
|
||||
use std::{error, fmt, io};
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum TransportError {
|
||||
IoError(io::Error),
|
||||
TransactionError(TransactionError),
|
||||
}
|
||||
|
||||
impl error::Error for TransportError {}
|
||||
impl fmt::Display for TransportError {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
TransportError::IoError(err) => write!(formatter, "{:?}", err),
|
||||
TransportError::TransactionError(err) => write!(formatter, "{:?}", err),
|
||||
}
|
||||
}
|
||||
#[error("transport io error: {0}")]
|
||||
IoError(#[from] io::Error),
|
||||
#[error("transport transaction error: {0}")]
|
||||
TransactionError(#[from] TransactionError),
|
||||
#[error("transport custom error: {0}")]
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
impl TransportError {
|
||||
@ -27,16 +22,4 @@ impl TransportError {
|
||||
}
|
||||
}
|
||||
|
||||
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