ttac

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTransaction

func GenerateTransaction(ctx context.Context, from *wallet.Wallet, to string, amount, tip int64, comment string) (*tlb.ExternalMessage, error)

GenerateTransaction creates a new transaction with the specified amount and tip, including an optional comment.

This function generates a transaction from the given wallet to the specified destination address. It also includes a tip transfer message and allows adding an optional comment. The transaction is built as an external message, ready to be submitted to the blockchain.

Parameters:

  • ctx: A context.Context for controlling the request's lifecycle.
  • from: A pointer to the wallet.Wallet from which the transaction will be sent.
  • to: The destination address as a string (TON address format).
  • amount: The amount of TONs to be transferred, in nanoTON (int64).
  • tip: The tip amount to be included in the transaction, in nanoTON (int64).
  • comment: A string comment to be attached to the transaction.

Returns:

  • *tlb.ExternalMessage: A pointer to the built external message that can be submitted to the network.
  • error: An error if any part of the transaction (parsing address, building transfer, etc.) fails.

Errors:

  • Returns an error if the destination address cannot be parsed.
  • Returns an error if building the transfer message for the transaction or the tip transfer fails.
  • Returns an error if the external message cannot be built.

Example usage:

extMsg, err := GenerateTransaction(ctx, myWallet, "EQD...", 250000000, 15000000, "Test transaction")
if err != nil {
    log.Fatalf("Failed to generate transaction: %v", err)
}

func GetTipTransfer

func GetTipTransfer(from *wallet.Wallet, tip int64) (*wallet.Message, error)

GetTipTransfer creates a transfer message for a tip transaction.

This function generates a tip transaction message from the given wallet, transferring the specified amount of TONs to a hardcoded tip address.

Parameters:

  • from: A pointer to the wallet.Wallet from which the tip will be sent.
  • tip: The tip amount in nanoTON (int64).

Returns:

  • *wallet.Message: A pointer to the generated transfer message.
  • error: An error if the tip address parsing or transfer message creation fails.

Errors:

  • Returns an error if the tip address cannot be parsed or the transfer message cannot be generated.

Example usage:

msg, err := GetTipTransfer(myWallet, 15000000)
if err != nil {
    log.Fatalf("Failed to create tip transfer: %v", err)
}

func SendTransaction

func SendTransaction(ctx context.Context, endPoint, authHeader string, w *wallet.Wallet, ext *tlb.ExternalMessage) (string, error)

SendTransaction sends a signed transaction to a TON trader API instance using the specified endpoint.

This function builds a request for submitting a signed TON transaction based on the wallet type. It converts the provided external message into a format that can be sent to the TON Trader API. The function supports different wallet types and encodes the transaction into a base64 format before sending it over HTTP.

Parameters:

  • ctx: A context.Context for managing the request's lifecycle, supporting cancellation and timeouts.
  • endPoint: The API endpoint URL to which the transaction will be submitted (TON Trader API endpoint).
  • authHeader: The authorization header required for authenticating the request.
  • w: A pointer to the wallet.Wallet that holds the wallet used for this transaction.
  • ext: A pointer to the tlb.ExternalMessage that contains the signed transaction to be submitted.

Returns:

  • string: The hash of the message body (msg_body_hash) if the transaction is successfully submitted.
  • error: An error if the wallet type is unsupported, if the message fails to convert to a cell, or if the submission to the API fails.

Wallet Types Supported:

  • HighloadV2R2
  • HighloadV3
  • V4R2
  • V5R1Final

Errors:

  • Returns an error if the wallet type is unsupported (e.g., V3, V5R1Beta).
  • Returns an error if the external message cannot be converted into a cell for submission.
  • Returns an error if the HTTP submission to the TON Trader API fails.

Example usage:

hash, err := SendTransaction(ctx, "https://example.com/submit", "<authHeader>", myWallet, extMsg)
if err != nil {
    log.Fatalf("Failed to send transaction: %v", err)
}
fmt.Printf("Transaction submitted successfully, message body hash: %s\n", hash)

Types

type ErrorResponse

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

ErrorResponse represents the error response from the API.

type TTASubmitRequest

type TTASubmitRequest struct {
	Transaction struct {
		Content string `json:"content"`
	} `json:"transaction"`
	Wallet string `json:"wallet"`
}

TTASubmitRequest represents the request body for the /api/v2/submit endpoint.

type TTASubmitResponse

type TTASubmitResponse struct {
	MsgBodyHash string `json:"msg_body_hash"`
}

TTASubmitResponse represents the response from the /api/v2/submit endpoint.

Jump to

Keyboard shortcuts

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