Αναφορά Rust API

Το crate surfpool-sdk εκθέτει μια μικρή επιφάνεια με επίκεντρο τη δομή Surfnet. Αυτή η σελίδα καταγράφει κάθε δημόσιο στοιχείο· για αφηγηματική χρήση, δείτε τους οδηγούς ξεκινώντας με Επισκόπηση.

Εξαγωγές Ρίζας Crate

ΣτοιχείοΤύποςΣημειώσεις
SurfnetstructΕκτελούμενη παρουσία Surfnet — τελικά σημεία RPC/WS, payer, cheatcodes
SurfnetBuilderstructFluent builder που χρησιμοποιείται από το Surfnet::builder()
Cheatcodes<'_>structΒοηθός cheatcode με δανεισμό που επιστρέφεται από το Surfnet::cheatcodes()
SurfnetErrorenumΌλες οι παραλλαγές σφαλμάτων που επιστρέφει το SDK
SurfnetResult<T>ψευδώνυμο τύπουResult<T, SurfnetError>
Keypairre-exportsolana_keypair::Keypair
Pubkeyre-exportsolana_pubkey::Pubkey
Signerre-exportsolana_signer::Signer
RpcClientre-exportsolana_rpc_client::rpc_client::RpcClient
BlockProductionModere-exportsurfpool_types::BlockProductionMode
SimnetCommandre-exportsurfpool_types::SimnetCommand
SimnetEventre-exportsurfpool_types::SimnetEvent
SvmFeatureConfigre-exportsurfpool_types::SvmFeatureConfig

Surfnet

pub struct Surfnet { /* private */ }

Κατασκευαστές

impl Surfnet {
pub async fn start() -> SurfnetResult<Self>;
pub fn builder() -> SurfnetBuilder;
}

Προσπελαστές

impl Surfnet {
pub fn rpc_url(&self) -> &str;
pub fn ws_url(&self) -> &str;
pub fn payer(&self) -> &Keypair;
pub fn instance_id(&self) -> &str;
pub fn rpc_client(&self) -> RpcClient;
pub fn cheatcodes(&self) -> Cheatcodes<'_>;
pub fn events(&self) -> &crossbeam_channel::Receiver<SimnetEvent>;
pub fn send_command(&self, cmd: SimnetCommand) -> SurfnetResult<()>;
}

Κύκλος Ζωής

impl Surfnet {
pub fn stop(&mut self) -> SurfnetResult<()>;
}
impl Drop for Surfnet { /* calls stop() if not already stopped */ }

Το stop αναμένει έως πέντε δευτερόλεπτα για να αποδεσμεύσει το runtime τις θύρες του. Η αποτυχία κατά τη διάρκεια του Drop είναι σιωπηλή· η αποτυχία κατά τη διάρκεια ενός ρητού stop επιστρέφει ένα SurfnetError::Runtime.

SurfnetBuilder

pub struct SurfnetBuilder { /* private */ }

Κάθε setter επιστρέφει Self, επομένως οι κλήσεις μπορούν να αλυσιδωθούν. Η τελική κλήση είναι start().await.

impl SurfnetBuilder {
pub fn offline(self, offline: bool) -> Self;
pub fn remote_rpc_url(self, url: impl Into<String>) -> Self;
pub fn block_production_mode(self, mode: BlockProductionMode) -> Self;
pub fn slot_time_ms(self, ms: u64) -> Self;
pub fn airdrop_addresses(self, addrs: Vec<Pubkey>) -> Self;
pub fn airdrop_sol(self, lamports: u64) -> Self;
pub fn skip_blockhash_check(self, skip: bool) -> Self;
pub fn payer(self, payer: Keypair) -> Self;
pub fn enable_feature(self, feature_id: Pubkey) -> Self;
pub fn disable_feature(self, feature_id: Pubkey) -> Self;
pub fn feature_config(self, config: SvmFeatureConfig) -> Self;
pub async fn start(self) -> SurfnetResult<Surfnet>;
}

Cheatcodes

pub struct Cheatcodes<'a> { /* private */ }

Χρηματοδότηση SOL

impl<'a> Cheatcodes<'a> {
pub fn fund_sol(&self, address: &Pubkey, lamports: u64) -> SurfnetResult<()>;
pub fn fund_sol_many(&self, accounts: &[(&Pubkey, u64)]) -> SurfnetResult<()>;
}

Χρηματοδότηση Token

impl<'a> Cheatcodes<'a> {
pub fn fund_token(
&self,
owner: &Pubkey,
mint: &Pubkey,
amount: u64,
token_program: Option<&Pubkey>,
) -> SurfnetResult<()>;
pub fn fund_token_many(
&self,
owners: &[&Pubkey],
mint: &Pubkey,
amount: u64,
token_program: Option<&Pubkey>,
) -> SurfnetResult<()>;
pub fn set_token_balance(
&self,
owner: &Pubkey,
mint: &Pubkey,
amount: u64,
token_program: Option<&Pubkey>,
) -> SurfnetResult<()>;
pub fn get_ata(
&self,
owner: &Pubkey,
mint: &Pubkey,
token_program: Option<&Pubkey>,
) -> Pubkey;
}

Μετάλλαξη Λογαριασμού

impl<'a> Cheatcodes<'a> {
pub fn set_account(
&self,
address: &Pubkey,
lamports: u64,
data: &[u8],
owner: &Pubkey,
) -> SurfnetResult<()>;
pub fn execute<B: CheatcodeBuilder>(&self, builder: B) -> SurfnetResult<()>;
}

Ταξίδι στο Χρόνο

impl<'a> Cheatcodes<'a> {
pub fn time_travel_to_slot(&self, slot: u64) -> SurfnetResult<EpochInfo>;
pub fn time_travel_to_epoch(&self, epoch: u64) -> SurfnetResult<EpochInfo>;
pub fn time_travel_to_timestamp(&self, timestamp_ms: u64) -> SurfnetResult<EpochInfo>;
}

Ανάπτυξη Προγράμματος

impl<'a> Cheatcodes<'a> {
pub fn deploy_program(&self, program_name: &str) -> SurfnetResult<Pubkey>;
pub fn deploy(&self, builder: DeployProgram) -> SurfnetResult<Pubkey>;
}

Χαρακτηριστικό CheatcodeBuilder

pub trait CheatcodeBuilder {
const METHOD: &'static str;
fn build(self) -> serde_json::Value;
}

Υλοποιήστε αυτό για προσαρμοσμένα cheatcodes JSON-RPC που δεν έχουν ακόμη αναδιπλωθεί από έναν typed builder.

Builders

Όλοι οι builders βρίσκονται στο surfpool_sdk::cheatcodes::builders.

SetAccount

pub struct SetAccount { /* private */ }
impl SetAccount {
pub fn new(address: Pubkey) -> Self;
pub fn lamports(self, lamports: u64) -> Self;
pub fn data(self, data: Vec<u8>) -> Self;
pub fn owner(self, owner: Pubkey) -> Self;
pub fn rent_epoch(self, epoch: u64) -> Self;
pub fn executable(self, executable: bool) -> Self;
}

SetTokenAccount

pub struct SetTokenAccount { /* private */ }
impl SetTokenAccount {
pub fn new(owner: Pubkey, mint: Pubkey) -> Self;
pub fn amount(self, amount: u64) -> Self;
pub fn delegate(self, delegate: Pubkey) -> Self;
pub fn clear_delegate(self) -> Self;
pub fn state(self, state: impl Into<String>) -> Self;
pub fn delegated_amount(self, amount: u64) -> Self;
pub fn close_authority(self, authority: Pubkey) -> Self;
pub fn clear_close_authority(self) -> Self;
pub fn token_program(self, program: Pubkey) -> Self;
}

ResetAccount

pub struct ResetAccount { /* private */ }
impl ResetAccount {
pub fn new(address: Pubkey) -> Self;
pub fn include_owned_accounts(self, include: bool) -> Self;
}

StreamAccount

pub struct StreamAccount { /* private */ }
impl StreamAccount {
pub fn new(address: Pubkey) -> Self;
pub fn include_owned_accounts(self, include: bool) -> Self;
}

DeployProgram

pub struct DeployProgram { /* private */ }
impl DeployProgram {
pub fn new(program_id: Pubkey) -> Self;
pub fn from_keypair_path(path: impl AsRef<Path>) -> SurfnetResult<Self>;
pub fn so_path(self, path: impl Into<PathBuf>) -> Self;
pub fn so_bytes(self, bytes: Vec<u8>) -> Self;
pub fn idl_path(self, path: impl Into<PathBuf>) -> Self;
}

SurfnetError

#[derive(Debug)]
pub enum SurfnetError {
PortAllocation(String),
Startup(String),
Runtime(String),
Cheatcode(String),
Aborted(String),
}
ΠαραλλαγήΑιτία
PortAllocationΔεν ήταν δυνατή η δέσμευση σε ελεύθερη θύρα για RPC ή WebSocket.
StartupΑποτυχία αρχικοποίησης του runtime.
RuntimeΤο νήμα runtime πανικοβλήθηκε ή τερματίστηκε απροσδόκητα.
CheatcodeΜια κλήση JSON-RPC cheatcode επέστρεψε σφάλμα.
AbortedΤο runtime τερματίστηκε ή ακυρώθηκε κατά την εκκίνηση.

Το crate υλοποιεί std::error::Error και Display στο SurfnetError, οπότε λειτουργεί με ? και anyhow χωρίς πρόσθετη ρύθμιση.

Is this page helpful?

© 2026 Ίδρυμα Solana. Με επιφύλαξη παντός δικαιώματος.