tongo

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 5 Imported by: 0

README

GoDoc

TON GO

Library provides a set of tools for working with TON blockchain.

TON Center Client

Tasks
Example
package main

import (
	"log"

	tongo "github.com/bored-ton/ton-go"
	"github.com/shopspring/decimal"
)

func main() {
	client := tongo.NewTonCenterAnonimousClient("https://toncenter.com/api/v2/")
	balance, err := client.Balance("EQCi7s7EYcPzzCrmPlQHck5FerXojlPt32f5vRsbjIPtOLkM")
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("balance: %s", balance.Div(decimal.NewFromFloat(1e9)).String())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressInformation

type AddressInformation struct {
	Type              string          `json:"@type"`
	Balance           decimal.Decimal `json:"balance"`
	Code              string          `json:"code"`
	Data              string          `json:"data"`
	LastTransactionID TonID           `json:"last_transaction_id"`
	BlockID           BlockID         `json:"block_id"`
	FrozenHash        string          `json:"frozen_hash"`
	SyncUtime         int64           `json:"sync_utime"`
	Extra             string          `json:"@extra"`
	State             string          `json:"state"`
}

AddressInformation

type BlockHeader

type BlockHeader struct {
	Type                   string    `json:"@type"`
	ID                     BlockID   `json:"id"`
	GlobalID               int64     `json:"global_id"`
	Version                int64     `json:"version"`
	AfterMerge             bool      `json:"after_merge"`
	AfterSplit             bool      `json:"after_split"`
	BeforeSplit            bool      `json:"before_split"`
	WantMerge              bool      `json:"want_merge"`
	WantSplit              bool      `json:"want_split"`
	ValidatorListHashShort int64     `json:"validator_list_hash_short"`
	CatchainSeqNo          int64     `json:"catchain_seqno"`
	MinRefMcSeqNo          int64     `json:"min_ref_mc_seqno"`
	IsKeyBlock             bool      `json:"is_key_block"`
	PrevKeyBlockSeqNo      int64     `json:"prev_key_block_seqno"`
	StartLt                string    `json:"start_lt"`
	EndLt                  string    `json:"end_lt"`
	VertSeqNo              int64     `json:"vert_seqno"`
	PrevBlocks             []BlockID `json:"prev_blocks"`
	Extra                  string    `json:"@extra"`
}

BlockHeader information

type BlockHeaderRequestParameters

type BlockHeaderRequestParameters struct {
	RootHash string
	FileHash string
}

BlockHeaderRequestParameters

type BlockID

type BlockID struct {
	Type       string `json:"@type"`
	Workchaing int32  `json:"workchain"`
	Shard      string `json:"shard"`
	SeqNo      int64  `json:"seqno"`
	RootHash   string `json:"root_hash"`
	FileHash   string `json:"file_hash"`
}

BlockID

type BlockTransactionsRequestParameters

type BlockTransactionsRequestParameters struct {
	RootHash  string
	FileHash  string
	AfterLt   int64
	AfterHash string
	Count     int32
}

BlockTransactionsRequestParameters

type ExtendedAccountState

type ExtendedAccountState struct {
	Type     string `json:"@type"`
	WalledID string `json:"walled_id"`
	SeqNo    int64  `json:"seqno"`
}

ExtendedAccountState

type ExtendedAddress

type ExtendedAddress struct {
	Type    string `json:"@type"`
	Address string `json:"address"`
}

ExtendedAddress

type ExtendedAddressInformation

type ExtendedAddressInformation struct {
	Type              string               `json:"@type"`
	Address           ExtendedAddress      `json:"address"`
	Balance           decimal.Decimal      `json:"balance"`
	LastTransactionID TonID                `json:"last_transaction_id"`
	BlockID           BlockID              `json:"block_id"`
	SyncUtime         int64                `json:"sync_utime"`
	AccountState      ExtendedAccountState `json:"account_state"`
	Revision          int64                `json:"revision"`
	Extra             string               `json:"@extra"`
}

ExtendedAddressInformation

type LookupBlockRequestParameters

type LookupBlockRequestParameters struct {
	SeqNo    *int64
	Lt       int64
	UnixTime int64
}

LookupBlockRequestParameters

type MasterchainInfo

type MasterchainInfo struct {
	Type          string  `json:"@type"`
	LastBlockID   BlockID `json:"last"`
	StateRootHash string  `json:"state_root_hash"`
	InitBlockID   BlockID `json:"init"`
	Extra         string  `json:"@extra"`
}

MasterchainInfo

type Message

type Message struct {
	Source      string          `json:"source"`
	Destination string          `json:"destination"`
	Value       decimal.Decimal `json:"value"`
	ForwardFee  decimal.Decimal `json:"fwd_fee"`
	IhrFee      decimal.Decimal `json:"ihr_fee"`
	CreatedLt   string          `json:"created_lt"`
	BodyHash    string          `json:"body_hash"`
	Message     string          `json:"message"`
	MessageData MessageData     `json:"msg_data"`
}

Message describes transaction message

type MessageData

type MessageData struct {
	Body      string `json:"body"`
	InitState string `json:"init_state"`
}

MessageData

type RunMethodRequest

type RunMethodRequest struct {
	Address string     `json:"address"`
	Method  string     `json:"method"`
	Stack   [][]string `json:"stack"`
}

RunMethodRequest contains parameters for run method request

type TonCenterClient

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

TonCenterClient is the client for toncenter.com HTTP API

func NewTonCenterAnonimousClient

func NewTonCenterAnonimousClient(url string) *TonCenterClient

NewTonCenterAnonimousClient creates new anonymous toncenter HTTP client

func NewTonCenterClient

func NewTonCenterClient(url string, token string) *TonCenterClient

NewTonCenterClient creates new toncenter HTTP client

func (*TonCenterClient) AddressInformation

func (t *TonCenterClient) AddressInformation(address string) (AddressInformation, error)

AddressInformation gets basic information about the address: balance, code, data, last_transaction_id.

func (*TonCenterClient) AddressState

func (t *TonCenterClient) AddressState(address string) (string, error)

AddressState represents the state of an address

func (*TonCenterClient) Balance

func (t *TonCenterClient) Balance(address string) (balance decimal.Decimal, err error)

Balance returns a wallet balance in nanotons

func (*TonCenterClient) BlockHeader

func (t *TonCenterClient) BlockHeader(
	workchain int64,
	shard int64,
	seqno int64,
	parameters BlockHeaderRequestParameters,
) (BlockHeader, error)

BlockHeader returns metadata of a given block

func (*TonCenterClient) BlockTransactions

func (t *TonCenterClient) BlockTransactions(
	workchain int64,
	shard int64,
	seqno int64,
	parameters BlockTransactionsRequestParameters,
) ([]BlockID, error)

BlockTransactions returns transactions of the given block

func (*TonCenterClient) ConsensusBlock

func (t *TonCenterClient) ConsensusBlock() (consensusBlock int64, timestamp float64, err error)

ConsensusBlock consensus block and its update timestamp

func (*TonCenterClient) ExtendedAddressInformation

func (t *TonCenterClient) ExtendedAddressInformation(address string) (ExtendedAddressInformation, error)

ExtendedAddressInformation is similar to previous one (AddressInformation) but tries to parse additional information for known contract types. This method is based on tonlib's function getAccountState. For detecting wallets we recommend to use getWalletInformation.

func (*TonCenterClient) LookupBlock

func (t *TonCenterClient) LookupBlock(
	workchain int32,
	shard int64,
	options LookupBlockRequestParameters,
) (BlockID, error)

LookupBlock by either seqno, lt or unix time

func (*TonCenterClient) MasterchainInfo

func (t *TonCenterClient) MasterchainInfo() (MasterchainInfo, error)

MasterchainInfo returns up-to-date masterchain state

func (*TonCenterClient) PackAddress

func (t *TonCenterClient) PackAddress(address string) (string, error)

PackAddress converts an address from raw to human-readable format

func (*TonCenterClient) RunGetMethod

func (t *TonCenterClient) RunGetMethod(request RunMethodRequest) (map[string]interface{}, error)

func (*TonCenterClient) Shards

func (t *TonCenterClient) Shards(seqno int64) ([]BlockID, error)

Shards returns shards information

func (*TonCenterClient) Transactions

func (t *TonCenterClient) Transactions(address string, parameters TransactionsRequestOptions) ([]Transaction, error)

Transactions gets transaction history of a given address

func (*TonCenterClient) TryLocateSourceTx

func (t *TonCenterClient) TryLocateSourceTx(source string, destination string, createdLt int64) (Transaction, error)

TryLocateSourceTx needs to locate incoming transaction of source address by outcoming message.

func (*TonCenterClient) TryLocateTx

func (t *TonCenterClient) TryLocateTx(source string, destination string, createdLt int64) (Transaction, error)

TryLocateTx needs to locate outcoming transaction of destination address by incoming message

func (*TonCenterClient) UnpackAddress

func (t *TonCenterClient) UnpackAddress(address string) (string, error)

UnpackAddress converts an address from human-readable to raw format

func (*TonCenterClient) WalletInformation

func (t *TonCenterClient) WalletInformation(address string) (WalletInformation, error)

WalletInformation retrieves wallet information. This method parses contract state and currently supports more wallet types than getExtendedAddressInformation: simple wallet, standart wallet, v3 wallet, v4 wallet.

type TonID

type TonID struct {
	Type string `json:"@type"`
	Hash string `json:"hash"`
	Lt   string `json:"lt"`
}

TonID

type Transaction

type Transaction struct {
	Address       string            `json:"address"`
	Utime         int64             `json:"utime"`
	Data          string            `json:"data"`
	TransactionID TonID             `json:"transaction_id"`
	InMessage     Message           `json:"in_msg"`
	OurMessages   []Message         `json:"out_msgs"`
	Fee           decimal.Decimal   `json:"fee"`
	StorageFee    decimal.Decimal   `json:"storage_fee"`
	OtherFees     []decimal.Decimal `json:"other_fees"`
}

Transaction

type TransactionsRequestOptions

type TransactionsRequestOptions struct {
	// Maximum number of transactions in response
	Limit int32
	// Logical time of transaction to start with, must be sent with hash
	Lt int64
	// Logical time of transaction to finish with (to get tx from lt to to_lt).
	ToLt int64
	// Hash of transaction to start with, in base64 or hex encoding , must be sent with lt
	Hash string
	// By default a request is processed by any available liteserver.
	// If archival=true only liteservers with full history are used
	Archival bool
}

TransactionsRequestOptions contains options for transactions request

type WalletInformation

type WalletInformation struct {
	Wallet            bool            `json:"wallet"`
	Balance           decimal.Decimal `json:"balance"`
	AccountState      string          `json:"account_state"`
	WalletType        string          `json:"wallet_type"`
	SeqNo             int64           `json:"seqno"`
	LastTransactionID TonID           `json:"last_transaction_id"`
	WalletID          uint64          `json:"wallet_id"`
}

WalletInformation

Jump to

Keyboard shortcuts

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