trongrid

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResponse = errors.New("error response")
	ErrNotFound = errors.New("transaction not found")
)

Functions

This section is empty.

Types

type BroadcastResponse

type BroadcastResponse struct {
	Result            bool   `json:"result"`
	Code              string `json:"code"`
	Message           string `json:"message"`
	TransactionHashID string `json:"txid"`
}

BroadcastResponse. Examples:

{
  "code": "CONTRACT_VALIDATE_ERROR",
  "txid": "50d52436163be5c38af269bbdee0a7e258e94cfa9cc05f975e543b98c6994f2e",
  "message": "Contract validate error : account [TDVEJbSyEtk8L4htanm8h5mp2sNutRm5ou] does not exist"
}
{
  "code": "DUP_TRANSACTION_ERROR",
  "txid": "fbb158948b240f88b188c65f5a623b562fe4d7a9a90eecef4495146acf87a484",
  "message": "Dup transaction."
}
{
  "result": true,
  "txid": "fbb158948b240f88b188c65f5a623b562fe4d7a9a90eecef4495146acf87a484"
}

type CallResponse

type CallResponse struct {
	Result      CallResponseResult
	Transaction Transaction `json:"transaction"`
}

CallResponse represents response when calling /wallet/triggersmartcontract.

type CallResponseResult

type CallResponseResult struct {
	Result  bool   `json:"result"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

type Config

type Config struct {
	MainnetBaseURL string `yaml:"mainnet_url" env:"TRONGRID_MAINNET_URL" env-default:"https://api.trongrid.io" env-description:"Trongrid API base path"`
	TestnetBaseURL string `` /* 148-byte string literal not displayed */
	APIKey         string `yaml:"api_key" env:"TRONGRID_API_KEY" env-description:"Trongrid API Key"`
}

type ContractCallRequest

type ContractCallRequest struct {
	OwnerAddress     string `json:"owner_address"`
	ContractAddress  string `json:"contract_address"`
	FunctionSelector string `json:"function_selector"`
	Parameter        string `json:"parameter"`
	FeeLimit         uint64 `json:"fee_limit"`
	CallValue        uint64 `json:"call_value"`
	Visible          bool   `json:"visible"`
}

type Provider

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

func New

func New(cfg Config, logger *zerolog.Logger) *Provider

func (*Provider) BroadcastTransaction

func (p *Provider) BroadcastTransaction(ctx context.Context, rawTX []byte, isTest bool) (string, error)

BroadcastTransaction broadcasts tx and return tx hash id.

func (*Provider) CallContract

func (p *Provider) CallContract(
	ctx context.Context,
	payload ContractCallRequest,
	isTest bool,
) (Transaction, error)

func (*Provider) CreateTransaction

func (p *Provider) CreateTransaction(
	ctx context.Context, payload TransactionRequest, isTest bool,
) (Transaction, error)

CreateTransaction fcking TRON makes offline tx creation so hard so they basically implemented endpoint for unsigned tx creation

func (*Provider) GetTransactionReceipt

func (p *Provider) GetTransactionReceipt(
	ctx context.Context,
	txID string,
	isTest bool,
) (*TransactionReceipt, error)

type Transaction

type Transaction struct {
	TxID       string          `json:"txID,omitempty"`
	RawDataHex string          `json:"raw_data_hex,omitempty"`
	RawData    json.RawMessage `json:"raw_data,omitempty"`
	Visible    bool            `json:"visible"`

	Signature []string `json:"signature,omitempty"`

	Error string `json:"Error,omitempty"`
}

type TransactionReceipt

type TransactionReceipt struct {
	Fee           uint64
	Hash          string
	Sender        string
	Recipient     string
	Confirmations int64
	IsConfirmed   bool
	Success       bool
}

type TransactionRequest

type TransactionRequest struct {
	OwnerAddress string `json:"owner_address"`
	ToAddress    string `json:"to_address"`
	Amount       uint64 `json:"amount"`
	ExtraData    string `json:"extra_data"`
	Visible      bool   `json:"visible"`
}

TransactionRequest transaction request. Address format: 410fe47f49fd91f0edb7fa2b94a3c45d9c2231709c See https://developers.tron.network/reference/createtransaction

Jump to

Keyboard shortcuts

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