Chuyển đến nội dung
Tài liệu API đầy đủ cho litesvm-go v0.3.0 trở lên. Tên phương thức phản chiếu builder LiteSVM của Rust khi có thể; các cặp getter / setter dùng cùng quy ước Go (Clock / SetClock, Rent / SetRent, …). Tài khoản là các giá trị *solana.Account thuần và sysvar là các kiểu từ github.com/gagliardetto/solana-go/sysvar.

​Các phần của API

​Tham khảo nhanh

​Thiết lập Handle

​Quản lý tài khoản

Phương thứcMô tả
Airdrop(pubkey, lamports) errorNạp tiền cho một tài khoản
Balance(pubkey) (uint64, bool, error)Số dư SOL; bool cho biết tài khoản có tồn tại hay không
GetAccount(pubkey) *solana.AccountBản sao của tài khoản (nil nếu không có)
SetAccount(pubkey, *solana.Account) errorLưu trực tiếp trạng thái tài khoản
MinimumBalanceForRentExemption(dataLen int) (uint64, error)Tính số dư tối thiểu để được miễn rent
NewAccount(lamports, data, owner, executable, rentEpoch) (*solana.Account, error)Tạo một tài khoản để dùng cho SetAccount (có thể dùng literal &solana.Account{...})

​Quản lý chương trình

Phương thứcMô tả
AddProgram(programID, bytes) errorTải chương trình từ bytes
AddProgramFromFile(programID, path) errorTải chương trình từ tệp .so
AddProgramWithLoader(programID, bytes, loaderID) errorTải bằng một loader cụ thể (nâng cao)

​Giao dịch

Phương thứcMô tả
SendLegacyTransaction(txBytes) (*TxOutcome, error)Thực thi một giao dịch legacy
SendVersionedTransaction(txBytes) (*TxOutcome, error)Thực thi một giao dịch v0+
SimulateLegacyTransaction(txBytes) (*TxOutcome, error)Mô phỏng mà không thay đổi trạng thái
SimulateVersionedTransaction(txBytes) (*TxOutcome, error)Mô phỏng giao dịch v0+ mà không thay đổi trạng thái
LatestBlockhash() (solana.Hash, error)Blockhash hiện tại
ExpireBlockhash() errorChuyển sang blockhash mới
GetTransaction(signature) *TxOutcomeTra cứu giao dịch trong lịch sử (nil nếu không có)
litesvm.BuildTransferTx(payerSeed, to, lamports, blockhash) ([]byte, error)Hàm hỗ trợ kiểm thử để tạo giao dịch chuyển tiền legacy đã ký mà không cần kéo theo solana-go

​Cấu hình

Phương thứcMô tả
SetSigverify(bool) errorBật / tắt xác minh chữ ký
Sigverify() (bool, error)Đọc thiết lập hiện tại
SetBlockhashCheck(bool) errorBật / tắt xác thực blockhash
SetTransactionHistory(int) errorDung lượng lịch sử giao dịch trong bộ nhớ (0 là tắt)
SetLogBytesLimit(int) errorGiới hạn byte log cho mỗi giao dịch (số âm = không giới hạn)
SetLamports(uint64) errorĐặt lại số dư của pool airdrop
SetSysvars() errorĐặt lại các sysvar về mặc định
SetBuiltins() errorTải lại các chương trình tích hợp sẵn
SetDefaultPrograms() errorTải lại SPL Token, Memo, v.v.
SetPrecompiles() errorBật các precompile ed25519 / secp256k1
WithNativeMints() errorKhởi tạo mint wrapped-SOL
SetFeatureSet(*FeatureSet) errorCài đặt một tập feature gate
SetComputeBudget(ComputeBudget) errorÁp dụng compute budget
ComputeBudget() (ComputeBudget, bool, error)Đọc budget hiện tại (bool cho biết “đã được đặt tường minh”)

​Thời gian và Sysvar

Phương thứcMô tả
WarpToSlot(slot uint64) errorNhảy tới một slot cụ thể
Clock() (*sysvar.Clock, error)Đọc sysvar Clock
SetClock(*sysvar.Clock) errorGhi đè sysvar Clock
Rent() (*sysvar.Rent, error)Đọc sysvar Rent
SetRent(*sysvar.Rent) errorGhi đè sysvar Rent
EpochSchedule() (*sysvar.EpochSchedule, error)Đọc sysvar EpochSchedule
SetEpochSchedule(*sysvar.EpochSchedule) errorGhi đè sysvar EpochSchedule
EpochRewards() (*sysvar.EpochRewards, error)Đọc sysvar EpochRewards
SetEpochRewards(*sysvar.EpochRewards) errorGhi đè sysvar EpochRewards
LastRestartSlot() (*sysvar.LastRestartSlot, error)Đọc last-restart-slot
SetLastRestartSlot(*sysvar.LastRestartSlot) errorĐặt last-restart-slot
SlotHashes() (sysvar.SlotHashes, error)Đọc sysvar SlotHashes
SetSlotHashes(sysvar.SlotHashes) errorGhi đè sysvar SlotHashes
SlotHistory() (*sysvar.SlotHistory, error)Đọc sysvar SlotHistory
SetSlotHistory(*sysvar.SlotHistory) errorGhi đè sysvar SlotHistory
StakeHistory() (sysvar.StakeHistory, error)Đọc sysvar StakeHistory
SetStakeHistory(sysvar.StakeHistory) errorGhi đè sysvar StakeHistory

​Tiện ích

Phương thứcMô tả
litesvm.Version() stringMô tả engine (litesvm-go (mithril svm, pure go))