liteapi

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 19 Imported by: 27

README

Lite client implementation.

This library implements TON lite client over ADNL protocol to communicate with TON lite servers.

TL schemas for lite server API you can find here:

Usage

Example

Documentation

Index

Constants

View Source
const (
	IntTag                             uint32 = 0xda9b50a8
	LongTag                            uint32 = 0xba6c0722
	DoubleTag                          uint32 = 0x54c11022
	StringTag                          uint32 = 0x246e28b5
	ObjectTag                          uint32 = 0xa04c7029
	FunctionTag                        uint32 = 0x97c1cb7a
	BytesTag                           uint32 = 0xd1144618
	TrueTag                            uint32 = 0x39d3ed3f
	BoolTrueTag                        uint32 = 0xb5757299
	BoolFalseTag                       uint32 = 0x379779bc
	VectorTag                          uint32 = 0x144a1a50
	Int128Tag                          uint32 = 0xb7f7cc84
	Int256Tag                          uint32 = 0x5bebed7b
	TonNodeBlockIdTag                  uint32 = 0x67b1cdb7
	TonNodeBlockIdExtTag               uint32 = 0x78eb5267
	TonNodeZeroStateIdExtTag           uint32 = 0xae35721d
	AdnlMessageQueryTag                uint32 = 0x7af98bb4
	AdnlMessageAnswerTag               uint32 = 0x1684ac0f
	LiteServerErrorTag                 uint32 = 0x48e1a9bb
	LiteServerAccountIdTag             uint32 = 0xc5e2a075
	LiteServerMasterchainInfoTag       uint32 = 0x81288385
	LiteServerMasterchainInfoExtTag    uint32 = 0xf5e0cca8
	LiteServerCurrentTimeTag           uint32 = 0xd0053e9
	LiteServerVersionTag               uint32 = 0xe591045a
	LiteServerBlockDataTag             uint32 = 0x6ced74a5
	LiteServerBlockStateTag            uint32 = 0xcdcadab
	LiteServerBlockHeaderTag           uint32 = 0x19822d75
	LiteServerSendMsgStatusTag         uint32 = 0x97e55039
	LiteServerAccountStateTag          uint32 = 0x51c77970
	LiteServerRunMethodResultTag       uint32 = 0x6b619aa3
	LiteServerShardInfoTag             uint32 = 0x84cde69f
	LiteServerAllShardsInfoTag         uint32 = 0x2de78f09
	LiteServerTransactionInfoTag       uint32 = 0x47edde0e
	LiteServerTransactionListTag       uint32 = 0x9dd72eb9
	LiteServerTransactionIdTag         uint32 = 0xaf652fb1
	LiteServerTransactionId3Tag        uint32 = 0x77da812c
	LiteServerBlockTransactionsTag     uint32 = 0x5c6c542f
	LiteServerSignatureTag             uint32 = 0x55f8dea3
	LiteServerSignatureSetTag          uint32 = 0x9755e192
	LiteServerBlockLinkBackTag         uint32 = 0xef1b7eef
	LiteServerBlockLinkForwardTag      uint32 = 0x1cce0f52
	LiteServerPartialBlockProofTag     uint32 = 0xc1d2d08e
	LiteServerConfigInfoTag            uint32 = 0x2f277bae
	LiteServerValidatorStatsTag        uint32 = 0xd896f7b9
	LiteServerDebugVerbosityTag        uint32 = 0x3347405d
	LiteServerGetMasterchainInfoTag    uint32 = 0x2ee6b589
	LiteServerGetMasterchainInfoExtTag uint32 = 0xdf71a670
	LiteServerGetTimeTag               uint32 = 0x345aad16
	LiteServerGetVersionTag            uint32 = 0xb942b23
	LiteServerGetBlockTag              uint32 = 0xdcf7763
	LiteServerGetStateTag              uint32 = 0xb62e6eba
	LiteServerGetBlockHeaderTag        uint32 = 0x9e06ec21
	LiteServerSendMessageTag           uint32 = 0x82d40a69
	LiteServerGetAccountStateTag       uint32 = 0x250e896b
	LiteServerRunSmcMethodTag          uint32 = 0xd25dc65c
	LiteServerGetShardInfoTag          uint32 = 0x25f4a246
	LiteServerGetAllShardsInfoTag      uint32 = 0x6bfdd374
	LiteServerGetOneTransactionTag     uint32 = 0xea240fd4
	LiteServerGetTransactionsTag       uint32 = 0xa1e7401c
	LiteServerLookupBlockTag           uint32 = 0x1ef7c8fa
	LiteServerListBlockTransactionsTag uint32 = 0xdac7fcad
	LiteServerGetBlockProofTag         uint32 = 0x449cea8a
	LiteServerGetConfigAllTag          uint32 = 0xb7261b91
	LiteServerGetConfigParamsTag       uint32 = 0x638df89e
	LiteServerGetValidatorStatsTag     uint32 = 0xbc581a09
	LiteServerQueryPrefixTag           uint32 = 0x86e6d372
	LiteServerQueryTag                 uint32 = 0xdf068c79
	LiteServerWaitMasterchainSeqnoTag  uint32 = 0x92b8eaba
)
View Source
const (
	LiteServerEnvName = "LITE_SERVERS"
)

Variables

View Source
var (
	// ErrAccountNotFound is returned by lite server when executing a method for an account that has not been deployed to the blockchain.
	ErrAccountNotFound = errors.New("account not found")
)
View Source
var (
	ErrOnchainContentOnly = fmt.Errorf("only onchain jetton data supported")
)

Functions

func ConvertSendMessagePayloadToMessage added in v1.4.2

func ConvertSendMessagePayloadToMessage(payload []byte) (*tlb.Message, error)

ConvertSendMessagePayloadToMessage converts the given payload to a tlb.Message. It also verifies that the message is an external message ready to be sent to the blockchain.

func VerifySendMessagePayload added in v1.0.14

func VerifySendMessagePayload(payload []byte) error

VerifySendMessagePayload verifies that the given payload is an external message ready to be sent to the blockchain.

Types

type Client

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

Client provides a convenient way to interact with TON blockchain.

By default, it uses a single connection to a lite server. But internally, it makes use of a failover pool, so it is possible to force it to use multiple connections. Take a look at WithMaxConnectionsNumber() option.

When the client is configured with several connections, two different lite servers can be used for two consequent requests. Because a blockchain is inherently a distributed system, this could lead to some inconsistencies. For example, 1. you obtain a master head with GetMasterchainInfo, 2. you get an account state with GetAccountState, the account state can be obtained from a block that is earlier in the blockchain than the master head you obtained at step 1. To avoid this, you can use WithBlock() method to specify a target block for all requests.

func NewClient

func NewClient(options ...Option) (*Client, error)

NewClient Get options and create new lite client. If no options provided - download public config for mainnet from ton.org.

func NewClientWithDefaultMainnet

func NewClientWithDefaultMainnet() (*Client, error)

func NewClientWithDefaultTestnet

func NewClientWithDefaultTestnet() (*Client, error)

func (*Client) DnsResolve

func (c *Client) DnsResolve(ctx context.Context, address ton.AccountID, domain string, category *big.Int) (int, *boc.Cell, error)

DnsResolve is deprecated. please use github.com/tonkeeper/tongo/contract/dns

func (*Client) GetAccountState

func (c *Client) GetAccountState(ctx context.Context, accountID ton.AccountID) (tlb.ShardAccount, error)

func (*Client) GetAccountStateRaw added in v1.1.2

func (c *Client) GetAccountStateRaw(ctx context.Context, accountID ton.AccountID) (liteclient.LiteServerAccountStateC, error)

func (*Client) GetAllShardsInfo

func (c *Client) GetAllShardsInfo(ctx context.Context, blockID ton.BlockIDExt) ([]ton.BlockIDExt, error)

func (*Client) GetAllShardsInfoRaw added in v1.1.2

func (c *Client) GetAllShardsInfoRaw(ctx context.Context, blockID ton.BlockIDExt) (liteclient.LiteServerAllShardsInfoC, error)

func (*Client) GetBlock

func (c *Client) GetBlock(ctx context.Context, blockID ton.BlockIDExt) (tlb.Block, error)

func (*Client) GetBlockHeader

func (c *Client) GetBlockHeader(ctx context.Context, blockID ton.BlockIDExt, mode uint32) (tlb.BlockInfo, error)

func (*Client) GetBlockHeaderRaw added in v1.1.2

func (c *Client) GetBlockHeaderRaw(ctx context.Context, blockID ton.BlockIDExt, mode uint32) (liteclient.LiteServerBlockHeaderC, error)

func (*Client) GetBlockProof

func (c *Client) GetBlockProof(
	ctx context.Context,
	knownBlock ton.BlockIDExt,
	targetBlock *ton.BlockIDExt,
) (liteclient.LiteServerPartialBlockProofC, error)

func (*Client) GetBlockProofRaw added in v1.1.2

func (c *Client) GetBlockProofRaw(ctx context.Context, knownBlock ton.BlockIDExt, targetBlock *ton.BlockIDExt) (liteclient.LiteServerPartialBlockProofC, error)

func (*Client) GetBlockRaw added in v1.1.2

func (c *Client) GetBlockRaw(ctx context.Context, blockID ton.BlockIDExt) (liteclient.LiteServerBlockDataC, error)

func (*Client) GetConfigAll

func (c *Client) GetConfigAll(ctx context.Context, mode ConfigMode) (tlb.ConfigParams, error)

GetConfigAll returns a current configuration of the blockchain.

func (*Client) GetConfigAllRaw added in v1.1.2

func (c *Client) GetConfigAllRaw(ctx context.Context, mode ConfigMode) (liteclient.LiteServerConfigInfoC, error)

func (*Client) GetConfigParams

func (c *Client) GetConfigParams(ctx context.Context, mode ConfigMode, paramList []uint32) (tlb.ConfigParams, error)

func (*Client) GetJettonBalance

func (c *Client) GetJettonBalance(ctx context.Context, jettonWallet ton.AccountID) (*big.Int, error)

GetJettonBalance TEP-74 Fungible tokens (Jettons) standard https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md

func (*Client) GetJettonData

func (c *Client) GetJettonData(ctx context.Context, master ton.AccountID) (tep64.Metadata, error)

GetJettonData TEP-74 Fungible tokens (Jettons) standard https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md

func (*Client) GetJettonWallet

func (c *Client) GetJettonWallet(ctx context.Context, master, owner ton.AccountID) (ton.AccountID, error)

GetJettonWallet TEP-74 Fungible tokens (Jettons) standard https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md

func (*Client) GetLastTransactions

func (c *Client) GetLastTransactions(ctx context.Context, a ton.AccountID, limit int) ([]ton.Transaction, error)

func (*Client) GetLibraries

func (c *Client) GetLibraries(ctx context.Context, libraryList []ton.Bits256) (map[ton.Bits256]*boc.Cell, error)

func (*Client) GetMasterchainInfo

func (c *Client) GetMasterchainInfo(ctx context.Context) (liteclient.LiteServerMasterchainInfoC, error)

func (*Client) GetMasterchainInfoExt

func (c *Client) GetMasterchainInfoExt(ctx context.Context, mode uint32) (liteclient.LiteServerMasterchainInfoExtC, error)

func (*Client) GetNetworkGlobalID added in v1.9.0

func (c *Client) GetNetworkGlobalID(ctx context.Context) (int32, error)

func (*Client) GetOneTransactionFromBlock

func (c *Client) GetOneTransactionFromBlock(
	ctx context.Context,
	accountID ton.AccountID,
	blockId ton.BlockIDExt,
	lt uint64,
) (ton.Transaction, error)

func (*Client) GetOutMsgQueueSizes added in v1.7.0

func (c *Client) GetOutMsgQueueSizes(ctx context.Context) (liteclient.LiteServerOutMsgQueueSizesC, error)

func (*Client) GetRootDNS

func (c *Client) GetRootDNS(ctx context.Context) (ton.AccountID, error)

func (*Client) GetSeqno

func (c *Client) GetSeqno(ctx context.Context, account ton.AccountID) (uint32, error)

func (*Client) GetShardBlockProof

func (c *Client) GetShardBlockProof(ctx context.Context) (liteclient.LiteServerShardBlockProofC, error)

func (*Client) GetShardBlockProofRaw added in v1.1.2

func (c *Client) GetShardBlockProofRaw(ctx context.Context) (liteclient.LiteServerShardBlockProofC, error)

func (*Client) GetShardInfo

func (c *Client) GetShardInfo(
	ctx context.Context,
	blockID ton.BlockIDExt,
	workchain uint32,
	shard uint64,
	exact bool,
) (ton.BlockIDExt, error)

func (*Client) GetShardInfoRaw added in v1.1.2

func (c *Client) GetShardInfoRaw(ctx context.Context, blockID ton.BlockIDExt, workchain uint32, shard uint64, exact bool) (liteclient.LiteServerShardInfoC, error)

func (*Client) GetState

func (c *Client) GetState(ctx context.Context, blockID ton.BlockIDExt) ([]byte, ton.Bits256, ton.Bits256, error)

func (*Client) GetStateRaw added in v1.1.2

func (c *Client) GetStateRaw(ctx context.Context, blockID ton.BlockIDExt) (liteclient.LiteServerBlockStateC, error)

func (*Client) GetTime

func (c *Client) GetTime(ctx context.Context) (uint32, error)

func (*Client) GetTransactions

func (c *Client) GetTransactions(
	ctx context.Context,
	count uint32,
	accountID ton.AccountID,
	lt uint64,
	hash ton.Bits256,
) ([]ton.Transaction, error)

func (*Client) GetTransactionsRaw added in v1.1.2

func (c *Client) GetTransactionsRaw(ctx context.Context, count uint32, accountID ton.AccountID, lt uint64, hash ton.Bits256) (liteclient.LiteServerTransactionListC, error)

func (*Client) GetValidatorStats

func (c *Client) GetValidatorStats(
	ctx context.Context,
	mode, limit uint32,
	startAfter *ton.Bits256,
	modifiedAfter *uint32,
) (*tlb.McStateExtra, error)

func (*Client) GetVersion

func (c *Client) GetVersion(ctx context.Context) (liteclient.LiteServerVersionC, error)

func (*Client) ListBlockTransactions

func (c *Client) ListBlockTransactions(
	ctx context.Context,
	blockID ton.BlockIDExt,
	mode, count uint32,
	after *liteclient.LiteServerTransactionId3C,
) ([]liteclient.LiteServerTransactionIdC, bool, error)

func (*Client) ListBlockTransactionsRaw added in v1.1.2

func (c *Client) ListBlockTransactionsRaw(ctx context.Context, blockID ton.BlockIDExt, mode, count uint32, after *liteclient.LiteServerTransactionId3C) (liteclient.LiteServerBlockTransactionsC, error)

func (*Client) LookupBlock

func (c *Client) LookupBlock(ctx context.Context, blockID ton.BlockID, mode uint32, lt *uint64, utime *uint32) (ton.BlockIDExt, tlb.BlockInfo, error)

func (*Client) RunSmcMethod

func (c *Client) RunSmcMethod(
	ctx context.Context,
	accountID ton.AccountID,
	method string,
	params tlb.VmStack,
) (uint32, tlb.VmStack, error)

func (*Client) RunSmcMethodByID

func (c *Client) RunSmcMethodByID(ctx context.Context, accountID ton.AccountID, methodID int, params tlb.VmStack) (uint32, tlb.VmStack, error)

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, payload []byte) (uint32, error)

SendMessage verifies that the given payload contains an external message and sends it to a lite server.

func (*Client) WaitMasterchainSeqno added in v1.2.1

func (c *Client) WaitMasterchainSeqno(ctx context.Context, seqno uint32, timeout time.Duration) error

WaitMasterchainSeqno waits for a masterchain block with the given seqno. If any connection in the pool becomes aware of this seqno, the function returns. If the timeout is reached, the function returns an error.

func (*Client) WithBlock

func (c *Client) WithBlock(block ton.BlockIDExt) *Client

type ConfigMode

type ConfigMode uint32
const (
	NeedStateRoot      ConfigMode = 1
	NeedLibraries      ConfigMode = 2
	NeedStateExtraRoot ConfigMode = 4
	NeedShardHashes    ConfigMode = 8
	NeedValidatorSet   ConfigMode = 16
	NeedSpecialSmc     ConfigMode = 32
	NeedAccountsRoot   ConfigMode = 64
	NeedPrevBlocks     ConfigMode = 128
	NeedWorkchainInfo  ConfigMode = 256
	NeedCapabilities   ConfigMode = 512
)

constants below are different flags for "mode" param of GetConfigAll. one needs to OR them to get different aspects of TON's configuration.

type Option

type Option func(o *Options) error

func FromEnvs added in v1.0.15

func FromEnvs() Option

FromEnvs configures a Client based on the following environment variables: LITE_SERVERS - a list of lite servers to use. FromEnvs() also sets MaxConnectionsNumber to be equal to the number of servers in LITE_SERVERS.

func FromEnvsOrMainnet added in v1.4.2

func FromEnvsOrMainnet() Option

FromEnvsOrMainnet configures a client to use lite servers from the LITE_SERVERS env variable. If LITE_SERVERS is not set, it downloads public config for mainnet from ton.org.

func FromEnvsOrTestnet added in v1.4.2

func FromEnvsOrTestnet() Option

FromEnvsOrTestnet configures a client to use lite servers from the LITE_SERVERS env variable. If LITE_SERVERS is not set, it downloads public config for testnet from ton.org.

func Mainnet added in v1.0.15

func Mainnet() Option

Mainnet configures a client to use lite servers from the mainnet.

func Testnet added in v1.0.15

func Testnet() Option

Testnet configures a client to use lite servers from the testnet.

func WithAsyncConnectionsInit added in v1.6.6

func WithAsyncConnectionsInit() Option

func WithConfigurationFile

func WithConfigurationFile(file config.GlobalConfigurationFile) Option

func WithDetectArchiveNodes added in v1.6.1

func WithDetectArchiveNodes() Option

func WithInitializationContext added in v1.4.2

func WithInitializationContext(ctx context.Context) Option

WithInitializationContext specifies a context to be used when opening a new connection to lite servers during the initialization.

func WithLiteServers

func WithLiteServers(servers []config.LiteServer) Option

func WithMaxConnectionsNumber added in v1.1.2

func WithMaxConnectionsNumber(maxConns int) Option

WithMaxConnectionsNumber specifies a number of concurrent connections to lite servers to be maintained by a connections pool. Be careful when combining WithMaxConnectionsNumber and FromEnvs() because MaxConnectionsNumber is set by FromEnvs() to the number of servers in LITE_SERVERS env variable.

func WithPoolStrategy added in v1.6.6

func WithPoolStrategy(strategy pool.Strategy) Option

func WithProofPolicy added in v1.4.2

func WithProofPolicy(policy ProofPolicy) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type Options

type Options struct {
	LiteServers []config.LiteServer
	Timeout     time.Duration
	// MaxConnections specifies a number of connections to lite servers for a connections pool.
	MaxConnections int
	// InitCtx is used when opening a new connection to lite servers during the initialization.
	InitCtx context.Context
	// ProofPolicy specifies a policy for proof checks.
	ProofPolicy ProofPolicy
	// DetectArchiveNodes specifies if a liteapi connection to a node
	// should detect if its node is an archive node.
	DetectArchiveNodes bool

	SyncConnectionsInitialization bool
	PoolStrategy                  pool.Strategy
}

Options holds parameters to configure a lite api instance.

type ProofPolicy added in v1.4.2

type ProofPolicy uint32

ProofPolicy specifies a policy for proof checks. This feature is experimental and can be changed or removed in the future.

const (
	// ProofPolicyUnsafe disables proof checks.
	ProofPolicyUnsafe ProofPolicy = iota
	ProofPolicyFast
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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