solana

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HealthOk      = "ok"
	HealthBehind  = "behind"
	HealthUnknown = "unknown"
)
View Source
const ChainName = "Solana"
View Source
const (
	MaxBlockRange = 1000
)

Variables

This section is empty.

Functions

func AddressFromPubKey

func AddressFromPubKey(publicKey solana.PublicKey) string

func GenerateNewKeypair

func GenerateNewKeypair() (*solana.PrivateKey, solana.PublicKey)

func GetSuggestedPriorityFee

func GetSuggestedPriorityFee(fees []PrioritizationFee) uint64

func NewChainAdaptor

func NewChainAdaptor(conf *config.Config) (chain.IChainAdaptor, error)

func PrivateKeyFromBase58

func PrivateKeyFromBase58(privateKeyBase58 string) (*solana.PrivateKey, error)

func PrivateKeyFromByteList

func PrivateKeyFromByteList(privateKeyByteList []byte) (*solana.PrivateKey, error)

func PrivateKeyFromHex

func PrivateKeyFromHex(privateKeyHex string) (*solana.PrivateKey, error)

func PrivateKeyHexToPrivateKey

func PrivateKeyHexToPrivateKey(privateKeyHex string) (*ed25519.PrivateKey, error)

func PrivateKeyHexToPubKey

func PrivateKeyHexToPubKey(privateKeyHex string) (*ed25519.PublicKey, error)

func PrivateKeyToBase58

func PrivateKeyToBase58(privateKey *solana.PrivateKey) string

func PrivateKeyToPubKey

func PrivateKeyToPubKey(privateKey *ed25519.PrivateKey) (*ed25519.PublicKey, error)

func PubKeyHexToAddress

func PubKeyHexToAddress(publicKeyHex string) (string, error)

func PubKeyHexToPubKey

func PubKeyHexToPubKey(publicKeyHex string) (*ed25519.PublicKey, error)

func PubKeyToAddress

func PubKeyToAddress(publicKey *ed25519.PublicKey) (string, error)

func PubKeyToPubKeyHex

func PubKeyToPubKeyHex(publicKey *ed25519.PublicKey) (string, error)

func PublicKeyFromBase58

func PublicKeyFromBase58(publicKeyBase58 string) (solana.PublicKey, error)

func PublicKeyFromPrivateKey

func PublicKeyFromPrivateKey(privateKey *solana.PrivateKey) solana.PublicKey

func PublicKeyToBase58

func PublicKeyToBase58(publicKey solana.PublicKey) string

Types

type AccountInfo

type AccountInfo struct {
	// account now balance
	Lamports uint64 `json:"lamports"`
	Owner    string `json:"owner"`
	// slice index = 0, data
	// slice index = 1, encode = base58, and other
	Data       []string `json:"data"`
	Executable bool     `json:"executable"`
	RentEpoch  uint64   `json:"rentEpoch"`
	Space      uint64   `json:"space"`
}

type AccountsInfo

type AccountsInfo struct {
	Addresses []string `json:"addresses"`
	Encoding  string   `json:"encoding,omitempty"`
}

type BlockHeightResponse

type BlockHeightResponse struct {
	JsonRPC string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Error   *RPCError `json:"error,omitempty"`
	// block height
	Result uint64 `json:"result"`
}

type BlockResult

type BlockResult struct {
	ParentSlot        uint64              `json:"parentSlot"`
	BlockTime         int64               `json:"blockTime"`
	BlockHeight       uint64              `json:"blockHeight"`
	BlockHash         string              `json:"blockhash"`
	PreviousBlockhash string              `json:"previousBlockhash"`
	Signatures        []string            `json:"signatures"`
	Transactions      []TransactionDetail `json:"transactions"`
}

type ChainAdaptor

type ChainAdaptor struct {
	// contains filtered or unexported fields
}

func (ChainAdaptor) BuildSignedTransaction

func (*ChainAdaptor) ConvertAddress

func (*ChainAdaptor) CreateUnSignTransaction

func (*ChainAdaptor) DecodeTransaction

func (*ChainAdaptor) GetAccount

func (*ChainAdaptor) GetBlockByHash

func (c *ChainAdaptor) GetBlockByHash(req *account.BlockHashRequest) (*account.BlockResponse, error)

func (*ChainAdaptor) GetBlockByNumber

func (c *ChainAdaptor) GetBlockByNumber(req *account.BlockNumberRequest) (*account.BlockResponse, error)

func (*ChainAdaptor) GetBlockByRange

func (*ChainAdaptor) GetBlockHeaderByHash

func (c *ChainAdaptor) GetBlockHeaderByHash(req *account.BlockHeaderHashRequest) (*account.BlockHeaderResponse, error)

func (*ChainAdaptor) GetBlockHeaderByNumber

func (c *ChainAdaptor) GetBlockHeaderByNumber(req *account.BlockHeaderNumberRequest) (*account.BlockHeaderResponse, error)

func (*ChainAdaptor) GetExtraData

func (*ChainAdaptor) GetFee

func (*ChainAdaptor) GetSupportChains

func (*ChainAdaptor) GetTxByAddress

func (*ChainAdaptor) GetTxByHash

func (c *ChainAdaptor) GetTxByHash(req *account.TxHashRequest) (*account.TxHashResponse, error)

func (*ChainAdaptor) SendTx

func (*ChainAdaptor) ValidAddress

func (*ChainAdaptor) VerifySignedTransaction

type CommitmentType

type CommitmentType string
const (
	// Finalized Confirmed Processed
	// Finalized wait 32 slot
	Finalized CommitmentType = "finalized"
	// Confirmed wait 2-3 slot
	Confirmed CommitmentType = "confirmed"
	// Processed wait 0 slot
	Processed CommitmentType = "processed"
)

type CreateNonceAccountRequest

type CreateNonceAccountRequest struct {
	// payer privateKey
	Payer solana.PrivateKey
	// nonce account Auth, PublicKey
	Authority solana.PublicKey
}

type CreateNonceAccountResponse

type CreateNonceAccountResponse struct {
	// nonce account PublicKey
	NonceAccount solana.PublicKey
	// nonce
	Nonce string
	// nonce
	Signature string
}

type GetAccountInfoResponse

type GetAccountInfoResponse struct {
	JsonRPC string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Error   *RPCError `json:"error,omitempty"`
	Result  struct {
		Context struct {
			// now slot
			Slot uint64 `json:"slot"`
		} `json:"context"`
		Value AccountInfo `json:"value"`
	} `json:"result"`
}

type GetBalanceResponse

type GetBalanceResponse struct {
	JsonRPC string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Error   *RPCError `json:"error,omitempty"`
	Result  struct {
		Context struct {
			Slot uint64 `json:"slot"`
		} `json:"context"`
		Value uint64 `json:"value"`
	} `json:"result"`
}

type GetBlockRequest

type GetBlockRequest struct {
	// slot status
	// Finalized Confirmed Processed
	Commitment CommitmentType `json:"commitment,omitempty"`
	// "json", "jsonParsed", "base58", "base64"
	Encoding string `json:"encoding"`
	// max version
	// Legacy = 0, no other version
	MaxSupportedTransactionVersion int `json:"maxSupportedTransactionVersion"`
	// "full", "accounts", "signatures", "none"
	TransactionDetails string `json:"transactionDetails"`
	// contain rewards
	Rewards bool `json:"rewards"`
}

type GetBlockResponse

type GetBlockResponse struct {
	JsonRPC string      `json:"jsonrpc"`
	ID      int         `json:"id"`
	Error   *RPCError   `json:"error,omitempty"`
	Result  BlockResult `json:"result"`
}

type GetBlocksWithLimitResponse

type GetBlocksWithLimitResponse struct {
	JsonRPC string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Error   *RPCError `json:"error,omitempty"`
	Result  []uint64  `json:"result"`
}

GetBlocksWithLimitResponse represents the response structure

type GetFeeForMessageRequest

type GetFeeForMessageRequest struct {
	Commitment     string `json:"commitment,omitempty"`
	MinContextSlot uint64 `json:"minContextSlot,omitempty"`
}

type GetFeeForMessageResponse

type GetFeeForMessageResponse struct {
	Jsonrpc string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Error   *RPCError `json:"error,omitempty"`
	Result  struct {
		Context struct {
			Slot uint64 `json:"slot"`
		} `json:"context"`
		Value *uint64 `json:"value"`
	} `json:"result"`
}

type GetHealthResponse

type GetHealthResponse struct {
	Jsonrpc string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Result  string    `json:"result"`
	Error   *RPCError `json:"error,omitempty"`
}

type GetLatestBlockhashResponse

type GetLatestBlockhashResponse struct {
	JsonRPC string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Error   *RPCError `json:"error,omitempty"`
	Result  struct {
		Context struct {
			Slot uint64 `json:"slot"`
		} `json:"context"`
		Value struct {
			Blockhash            string `json:"blockhash"`
			LastValidBlockHeight uint64 `json:"lastValidBlockHeight"`
		} `json:"value"`
	} `json:"result"`
}

type GetSignaturesRequest

type GetSignaturesRequest struct {
	Commitment     string `json:"commitment,omitempty"`
	MinContextSlot uint64 `json:"minContextSlot,omitempty"`
	Limit          uint64 `json:"limit,omitempty"`
	Before         string `json:"before,omitempty"`
	Until          string `json:"until,omitempty"`
}

type GetSignaturesResponse

type GetSignaturesResponse struct {
	Jsonrpc string          `json:"jsonrpc"`
	ID      int             `json:"id"`
	Error   *RPCError       `json:"error,omitempty"`
	Result  []SignatureInfo `json:"result"`
}

type GetSlotRequest

type GetSlotRequest struct {
	Commitment CommitmentType `json:"commitment,omitempty"`
}

type GetSlotResponse

type GetSlotResponse struct {
	JsonRPC string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Error   *RPCError `json:"error,omitempty"`
	// slot
	Result uint64 `json:"result"`
}

type GetTransactionResponse

type GetTransactionResponse struct {
	Jsonrpc string            `json:"jsonrpc"`
	ID      int               `json:"id"`
	Error   *RPCError         `json:"error,omitempty"`
	Result  TransactionResult `json:"result"`
}

type Instruction

type Instruction struct {
	Accounts       []int       `json:"accounts"`
	Data           string      `json:"data"`
	ProgramIdIndex int         `json:"programIdIndex"`
	StackHeight    interface{} `json:"stackHeight"`
}

type LoadedAddresses

type LoadedAddresses struct {
	Readonly []string `json:"readonly"`
	Writable []string `json:"writable"`
}

type PrioritizationFee

type PrioritizationFee struct {
	Slot              uint64 `json:"slot"`
	PrioritizationFee uint64 `json:"prioritizationFee"`
}

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type SendTransactionRequest

type SendTransactionRequest struct {
	Encoding            string `json:"encoding,omitempty"`
	Commitment          string `json:"commitment,omitempty"`
	SkipPreflight       bool   `json:"skipPreflight,omitempty"`
	PreflightCommitment string `json:"preflightCommitment,omitempty"`
	MaxRetries          uint64 `json:"maxRetries,omitempty"`
	MinContextSlot      uint64 `json:"minContextSlot,omitempty"`
}

type SendTransactionResponse

type SendTransactionResponse struct {
	Jsonrpc string    `json:"jsonrpc"`
	ID      int       `json:"id"`
	Result  string    `json:"result"`
	Error   *RPCError `json:"error,omitempty"`
}

type SignatureInfo

type SignatureInfo struct {
	Signature          string      `json:"signature"`
	Slot               uint64      `json:"slot"`
	Error              interface{} `json:"err"`
	Memo               *string     `json:"memo"`
	BlockTime          *int64      `json:"blockTime"`
	ConfirmationStatus *string     `json:"confirmationStatus"`
}

type SimulateRequest

type SimulateRequest struct {
	Commitment             string        `json:"commitment,omitempty"`
	SigVerify              bool          `json:"sigVerify,omitempty"`
	ReplaceRecentBlockhash bool          `json:"replaceRecentBlockhash,omitempty"`
	MinContextSlot         uint64        `json:"minContextSlot,omitempty"`
	Encoding               string        `json:"encoding,omitempty"`
	Accounts               *AccountsInfo `json:"accounts,omitempty"`
}

type SimulateResult

type SimulateResult struct {
	Err           interface{} `json:"err"`
	Logs          []string    `json:"logs"`
	UnitsConsumed uint64      `json:"unitsConsumed"`
	Accounts      []struct {
		Executable bool     `json:"executable"`
		Lamports   uint64   `json:"lamports"`
		Owner      string   `json:"owner"`
		RentEpoch  uint64   `json:"rentEpoch"`
		Data       []string `json:"data"`
	} `json:"accounts,omitempty"`
	ReturnData *struct {
		ProgramId string   `json:"programId"`
		Data      []string `json:"data"`
	} `json:"returnData,omitempty"`
	InnerInstructions []struct {
		Index        uint16 `json:"index"`
		Instructions []struct {
			ProgramIdIndex uint8   `json:"programIdIndex"`
			Accounts       []uint8 `json:"accounts"`
			Data           string  `json:"data"`
		} `json:"instructions"`
	} `json:"innerInstructions,omitempty"`
}

type SimulateTransactionResponse

type SimulateTransactionResponse struct {
	Jsonrpc string         `json:"jsonrpc"`
	ID      int            `json:"id"`
	Error   *RPCError      `json:"error,omitempty"`
	Result  SimulateResult `json:"result"`
}

type SolClient

type SolClient interface {
	GetHealth() (string, error)

	GetAccountInfo(inputAddr string) (*AccountInfo, error)
	GetBalance(inputAddr string) (uint64, error)
	GetLatestBlockhash(commitmentType CommitmentType) (string, error)
	SendTransaction(
		signedTx string,
		config *SendTransactionRequest,
	) (string, error)
	SimulateTransaction(
		signedTx string,
		config *SimulateRequest,
	) (*SimulateResult, error)

	GetFeeForMessage(message string) (uint64, error)
	GetRecentPrioritizationFees() ([]PrioritizationFee, error)

	GetSlot(commitment CommitmentType) (uint64, error)
	GetBlocksWithLimit(startSlot uint64, limit uint64) ([]uint64, error)
	GetBlockBySlot(slot uint64, detailType TransactionDetailsType) (*BlockResult, error)

	GetTransaction(signature string) (*TransactionResult, error)
	GetTransactionRange(signatures []string) ([]*TransactionResult, error)
	GetTxForAddress(
		address string,
		commitment CommitmentType,
		limit uint64,
		beforeSignature string,
		untilSignature string,
	) ([]SignatureInfo, error)
}

func NewSolHttpClient

func NewSolHttpClient(baseUrl string) (SolClient, error)

func NewSolHttpClientAll

func NewSolHttpClientAll(baseUrl string, withDebug bool) (SolClient, error)

type SolData

type SolData struct {
	SolDataCli *solscan.ChainExplorerAdaptor
}

func NewSolScanClient

func NewSolScanClient(baseUrl, apiKey string, timeout time.Duration) (*SolData, error)

func (*SolData) GetTxByAddress

func (ss *SolData) GetTxByAddress(page, pagesize uint64, address string, action account.ActionType) (*account.TransactionResponse[account.AccountTxResponse], error)

type Status

type Status struct {
	Ok interface{} `json:"Ok"`
}

type Transaction

type Transaction struct {
	Message    TransactionMessage `json:"message"`
	Signatures []string           `json:"signatures"`
}

type TransactionDetail

type TransactionDetail struct {
	Signature string           `json:"signature"`
	Slot      uint64           `json:"slot"`
	BlockTime int64            `json:"blockTime"`
	Meta      *TransactionMeta `json:"meta"`
	// "version": "legacy"   or   "version": 0
	Version         any         `json:"version"`
	Message         interface{} `json:"message"` // 使用 interface{} 因为可能为 null
	RecentBlockhash string      `json:"recentBlockhash"`
}

type TransactionDetailsType

type TransactionDetailsType string
const (
	Full       TransactionDetailsType = "full"
	Accounts   TransactionDetailsType = "accounts"
	Signatures TransactionDetailsType = "signatures"
	None       TransactionDetailsType = "none"
)

type TransactionHeader

type TransactionHeader struct {
	NumReadonlySignedAccounts   int `json:"numReadonlySignedAccounts"`
	NumReadonlyUnsignedAccounts int `json:"numReadonlyUnsignedAccounts"`
	NumRequiredSignatures       int `json:"numRequiredSignatures"`
}

type TransactionMessage

type TransactionMessage struct {
	AccountKeys         []string          `json:"accountKeys"`
	AddressTableLookups []interface{}     `json:"addressTableLookups"`
	Header              TransactionHeader `json:"header"`
	Instructions        []Instruction     `json:"instructions"`
	RecentBlockhash     string            `json:"recentBlockhash"`
}

type TransactionMeta

type TransactionMeta struct {
	Err               interface{}     `json:"err"`
	Fee               uint64          `json:"fee"`
	PreBalances       []uint64        `json:"preBalances"`
	PostBalances      []uint64        `json:"postBalances"`
	InnerInstructions []interface{}   `json:"innerInstructions"`
	PreTokenBalances  []interface{}   `json:"preTokenBalances"`
	PostTokenBalances []interface{}   `json:"postTokenBalances"`
	LogMessages       []string        `json:"logMessages"`
	LoadedAddresses   LoadedAddresses `json:"loadedAddresses"`
	Status            struct {
		Ok interface{} `json:"Ok"`
	} `json:"status"`
	Rewards              interface{} `json:"rewards"`
	ComputeUnitsConsumed uint64      `json:"computeUnitsConsumed"`
}

type TransactionResult

type TransactionResult struct {
	Slot        uint64          `json:"slot"`
	Version     any             `json:"version"`
	BlockTime   *int64          `json:"blockTime"`
	Transaction Transaction     `json:"transaction"`
	Meta        TransactionMeta `json:"meta"`
}

type TransactionVersion

type TransactionVersion struct {
	// contains filtered or unexported fields
}

type TxStructure

type TxStructure struct {
	Nonce           string `json:"nonce"`
	GasPrice        string `json:"gas_price"`
	GasTipCap       string `json:"gas_tip_cap"`
	GasFeeCap       string `json:"gas_fee_cap"`
	Gas             uint64 `json:"gas"`
	ContractAddress string `json:"contract_address"`
	FromAddress     string `json:"from_address"`
	ToAddress       string `json:"to_address"`
	TokenId         string `json:"token_id"`
	Value           string `json:"value"`
	FromPrivateKey  string `json:"from_privatekey"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL