Documentation ¶
Overview ¶
Package ton provider bindings for TON blockchain including Gateway contract wrapper.
Index ¶
- Constants
- Variables
- func Coins(amount uint64) math.Uint
- func ErrCollect(errs ...error) error
- func FilterInbounds(tx *Transaction) bool
- func FormatCoins(v math.Uint) string
- func GatewayCode() *boc.Cell
- func GatewayStateInit(authority ton.AccountID, tss eth.Address, depositsEnabled bool) *boc.Cell
- func GramsToUint(g tlb.Grams) math.Uint
- func MarshalSnakeCell(data []byte) (*boc.Cell, error)
- func MarshalTLB(v tlb.MarshalerTLB) (*boc.Cell, error)
- func UintToCoins(v math.Uint) tlb.Coins
- func UnmarshalEVMAddress(cell *boc.Cell) (eth.Address, error)
- func UnmarshalSnakeCell(cell *boc.Cell) ([]byte, error)
- func UnmarshalTLB(t tlb.UnmarshalerTLB, cell *boc.Cell) error
- type Client
- type Deposit
- type DepositAndCall
- type Donation
- type ExitCode
- type ExternalMsg
- type Filter
- type Gateway
- func (gw *Gateway) AccountID() ton.AccountID
- func (gw *Gateway) GetTxFee(ctx context.Context, client MethodRunner, op Op) (math.Uint, error)
- func (gw *Gateway) ParseAndFilter(tx ton.Transaction, filter Filter) (*Transaction, bool, error)
- func (gw *Gateway) ParseAndFilterMany(txs []ton.Transaction, filter Filter) []*Transaction
- func (gw *Gateway) ParseTransaction(tx ton.Transaction) (*Transaction, error)
- func (gw *Gateway) SendDeposit(ctx context.Context, s Sender, amount math.Uint, zevmRecipient eth.Address, ...) error
- func (gw *Gateway) SendDepositAndCall(ctx context.Context, s Sender, amount math.Uint, zevmRecipient eth.Address, ...) error
- func (gw *Gateway) SendExternalMessage(ctx context.Context, s Client, msg ExternalMsg) (uint32, error)
- type MethodRunner
- type Op
- type Sender
- type Transaction
- func (tx *Transaction) Deposit() (Deposit, error)
- func (tx *Transaction) DepositAndCall() (DepositAndCall, error)
- func (tx *Transaction) Donation() (Donation, error)
- func (tx *Transaction) GasUsed() math.Uint
- func (tx *Transaction) IsInbound() bool
- func (tx *Transaction) IsOutbound() bool
- func (tx *Transaction) Withdrawal() (Withdrawal, error)
- type Withdrawal
Constants ¶
const ( SendFlagSeparateFees = uint8(1) SendFlagIgnoreErrors = uint8(2) )
see https://docs.ton.org/develop/smart-contracts/messages#message-modes
Variables ¶
Functions ¶
func Coins ¶
Coins takes amount in TON and returns it in nano tons. Example Coins(5) return math.Uint(5 * 10^9) nano tons.
func ErrCollect ¶
func FilterInbounds ¶
func FilterInbounds(tx *Transaction) bool
FilterInbounds filters transactions with deposit operations
func FormatCoins ¶
func GatewayStateInit ¶
GatewayStateInit returns Gateway's stateInit as cell
func MarshalSnakeCell ¶
MarshalSnakeCell encodes []byte to TLB using snake-cell encoding
func MarshalTLB ¶
func MarshalTLB(v tlb.MarshalerTLB) (*boc.Cell, error)
MarshalTLB encodes entity to BOC
func UnmarshalEVMAddress ¶
UnmarshalEVMAddress decodes eth.Address from BOC
func UnmarshalSnakeCell ¶
UnmarshalSnakeCell decodes TLB cell to []byte using snake-cell encoding
func UnmarshalTLB ¶
func UnmarshalTLB(t tlb.UnmarshalerTLB, cell *boc.Cell) error
UnmarshalTLB decodes entity from BOC
Types ¶
type Client ¶
Client represents a sender that allows sending an arbitrary external message to the network.
type Deposit ¶
Deposit represents a deposit operation
type DepositAndCall ¶
DepositAndCall represents a deposit and call operation
func (DepositAndCall) AsBody ¶
func (d DepositAndCall) AsBody() (*boc.Cell, error)
AsBody casts struct to internal message body.
func (DepositAndCall) Memo ¶
func (d DepositAndCall) Memo() []byte
Memo casts deposit to call to memo bytes
type ExitCode ¶
type ExitCode uint32
ExitCode represents an error code. Might be TVM or custom. TVM: https://docs.ton.org/v3/documentation/tvm/tvm-exit-codes Zeta: https://github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/common/errors.fc
const (
ExitCodeInvalidSeqno ExitCode = 109
)
type ExternalMsg ¶
type Filter ¶
type Filter func(*Transaction) bool
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway represents bindings for Zeta Gateway contract on TON
Gateway.ParseTransaction parses Gateway transaction. The parser reads tx body cell and decodes it based on Operation code (op)
- inbound transactions: deposit, donate, depositAndCall
- outbound transactions: not implemented yet
- errors for all other transactions
`Send*` methods work the same way by constructing (& signing) tx body cell that is expected by the contract
@see https://github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/gateway.fc
func (*Gateway) GetTxFee ¶
GetTxFee returns maximum transaction fee for the given operation. Real fee may be lower.
func (*Gateway) ParseAndFilter ¶
func (gw *Gateway) ParseAndFilter(tx ton.Transaction, filter Filter) (*Transaction, bool, error)
ParseAndFilter parses transaction and applies filter to it. Returns (tx, skip?, error) If parse fails due to known error, skip is set to true
func (*Gateway) ParseAndFilterMany ¶
func (gw *Gateway) ParseAndFilterMany(txs []ton.Transaction, filter Filter) []*Transaction
ParseAndFilterMany parses and filters many txs.
func (*Gateway) ParseTransaction ¶
func (gw *Gateway) ParseTransaction(tx ton.Transaction) (*Transaction, error)
ParseTransaction parses transaction to Transaction
func (*Gateway) SendDeposit ¶
func (gw *Gateway) SendDeposit( ctx context.Context, s Sender, amount math.Uint, zevmRecipient eth.Address, sendMode uint8, ) error
SendDeposit sends a deposit operation to the gateway on behalf of the sender.
func (*Gateway) SendDepositAndCall ¶
func (gw *Gateway) SendDepositAndCall( ctx context.Context, s Sender, amount math.Uint, zevmRecipient eth.Address, callData []byte, sendMode uint8, ) error
SendDepositAndCall sends a deposit operation to the gateway on behalf of the sender with a callData to the recipient.
func (*Gateway) SendExternalMessage ¶
func (gw *Gateway) SendExternalMessage(ctx context.Context, s Client, msg ExternalMsg) (uint32, error)
SendExternalMessage sends an external message to the Gateway.
type MethodRunner ¶
type Op ¶
type Op uint32
Op operation code
github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/gateway.fc Inbound operations
const OpWithdraw Op = 200
type Transaction ¶
type Transaction struct { ton.Transaction Operation Op ExitCode int32 // contains filtered or unexported fields }
Transaction represents a Gateway transaction.
func (*Transaction) Deposit ¶
func (tx *Transaction) Deposit() (Deposit, error)
Deposit casts the transaction content to a Deposit.
func (*Transaction) DepositAndCall ¶
func (tx *Transaction) DepositAndCall() (DepositAndCall, error)
DepositAndCall casts the transaction content to a DepositAndCall.
func (*Transaction) Donation ¶
func (tx *Transaction) Donation() (Donation, error)
Donation casts the transaction content to a Donation.
func (*Transaction) GasUsed ¶
func (tx *Transaction) GasUsed() math.Uint
GasUsed returns the amount of gas used by the transaction.
func (*Transaction) IsInbound ¶
func (tx *Transaction) IsInbound() bool
IsInbound returns true if the transaction is inbound.
func (*Transaction) IsOutbound ¶
func (tx *Transaction) IsOutbound() bool
IsOutbound returns true if the transaction is outbound.
func (*Transaction) Withdrawal ¶
func (tx *Transaction) Withdrawal() (Withdrawal, error)
Withdrawal casts the transaction content to a Withdrawal.
type Withdrawal ¶
Withdrawal represents a withdrawal external message
func (*Withdrawal) Hash ¶
func (w *Withdrawal) Hash() ([32]byte, error)
Hash returns hash of the withdrawal message. (used for signing)
func (*Withdrawal) SetSignature ¶
func (w *Withdrawal) SetSignature(sig [65]byte)
SetSignature sets signature to the withdrawal message. Note that signature has the following order: [R, S, V (recovery ID)]