솔라나 문서SDK
surfpool-sdk 크레이트는 Surfnet 구조체를 중심으로 한 간결한 인터페이스를
제공합니다. 이 페이지에서는 모든 공개 항목을 나열합니다. 사용 방법에 대한 설명은
개요부터 시작하는 가이드를 참고하세요.
크레이트 루트 내보내기
| 항목 | 종류 | 설명 |
|---|---|---|
Surfnet | 구조체 | 실행 중인 Surfnet 인스턴스 — RPC/WS 엔드포인트, 페이어, 치트코드 |
SurfnetBuilder | 구조체 | Surfnet::builder()에서 사용하는 플루언트 빌더 |
Cheatcodes<'_> | 구조체 | Surfnet::cheatcodes()에서 반환되는 빌린 치트코드 헬퍼 |
SurfnetError | 열거형 | SDK가 반환하는 모든 오류 변형 |
SurfnetResult<T> | 타입 별칭 | Result<T, SurfnetError> |
Keypair | 재내보내기 | solana_keypair::Keypair |
Pubkey | 재내보내기 | solana_pubkey::Pubkey |
Signer | 재내보내기 | solana_signer::Signer |
RpcClient | 재내보내기 | solana_rpc_client::rpc_client::RpcClient |
BlockProductionMode | 재내보내기 | surfpool_types::BlockProductionMode |
SimnetCommand | 재내보내기 | surfpool_types::SimnetCommand |
SimnetEvent | 재내보내기 | surfpool_types::SimnetEvent |
SvmFeatureConfig | 재내보내기 | surfpool_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는 런타임이 포트를 해제할 때까지 최대 5초 동안 대기합니다. Drop 중
발생한 오류는 무시되며, 명시적 stop 중 발생한 오류는 SurfnetError::Runtime를
반환합니다.
SurfnetBuilder
pub struct SurfnetBuilder { /* private */ }
모든 세터는 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>;}
치트코드
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<()>;}
토큰 펀딩
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;}
타입 빌더로 아직 래핑되지 않은 커스텀 JSON-RPC 치트코드에 대해 이를 구현하세요.
빌더
모든 빌더는 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 | 런타임 스레드가 패닉 상태가 되었거나 예기치 않게 종료되었습니다. |
Cheatcode | 치트코드 JSON-RPC 호출에서 오류가 반환되었습니다. |
Aborted | 런타임이 시작 중에 종료되거나 취소되었습니다. |
이 크레이트는 SurfnetError에 std::error::Error 및 Display를 구현하므로 ?
및 anyhow와 즉시 사용할 수 있습니다.
Is this page helpful?