tron

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 31 Imported by: 0

README

Tron

Resources

Below you will find some useful links that explain how to estimate bandwidth and energy for transactions.

Documentation

Index

Constants

View Source
const (
	BlackHoleAddress = "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb"
)
View Source
const TrxAssetIdentifier = "trx"

Variables

View Source
var ResourceCoefficient = decimal.NewFromFloat(1.007)

Functions

func AddressPublic

func AddressPublic(address string, mnemonic string, passphrase string, sequence uint32) (string, error)

func AddressSecret

func AddressSecret(address string, mnemonic string, passphrase string, sequence uint32) (string, error)

func AddressWallet

func AddressWallet(mnemonic string, passphrase string, sequence uint32) (string, error)

func CreateFakeCreateAccountTransaction

func CreateFakeCreateAccountTransaction(fromAddress, toAddress string) (*core.Transaction, error)

func CreateFakeResourceTransaction

func CreateFakeResourceTransaction(fromAddress, toAddress string, amount int64, resourceType core.ResourceCode, reclaim bool) (*core.Transaction, error)

CreateFakeResourceTransaction creates a fake resource transaction.

func PrepareStreamInterceptor

func PrepareStreamInterceptor(kv ...string) grpc.StreamClientInterceptor

func PrepareUnaryInterceptor

func PrepareUnaryInterceptor(kv ...string) grpc.UnaryClientInterceptor

func ValidateAddress

func ValidateAddress(address string) bool

func WalletFromPrivateKeyBytes

func WalletFromPrivateKeyBytes(privateKey []byte) (string, *btcec.PrivateKey, *btcec.PublicKey)

func WalletPubKeyHash

func WalletPubKeyHash(mnemonic string, passphrase string, sequence uint32) (string, *btcec.PrivateKey, *btcec.PublicKey, error)

Types

type AccountResourceInfoData

type AccountResourceInfoData struct {
	EnergyAvailableForUse    decimal.Decimal `json:"energy_available_for_use"`
	BandwidthAvailableForUse decimal.Decimal `json:"bandwidth_available_for_use"`
	TotalEnergy              decimal.Decimal `json:"total_energy"`
	TotalBandwidth           decimal.Decimal `json:"total_bandwidth"`
	TotalStackedTRX          decimal.Decimal `json:"total_stacked_trx"`
	StackedEnergyTRX         decimal.Decimal `json:"stacked_energy_trx"`
	StackedBandwidthTRX      decimal.Decimal `json:"stacked_bandwidth_trx"`
	StackedEnergy            decimal.Decimal `json:"stacked_energy"`
	StackedBandwidth         decimal.Decimal `json:"stacked_bandwidth"`
	TotalUsedEnergy          decimal.Decimal `json:"total_used_energy"`
	TotalUsedBandwidth       decimal.Decimal `json:"total_used_bandwidth"`
	TotalAvailableEnergy     decimal.Decimal `json:"total_available_energy"`
	TotalAvailableBandwidth  decimal.Decimal `json:"total_available_bandwidth"`
}

type ActivationResources

type ActivationResources struct {
	Energy    decimal.Decimal `json:"energy"`
	Bandwidth decimal.Decimal `json:"bandwidth"`
	Trx       decimal.Decimal `json:"trx"`
}

type Bandwidth

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

func NewBandwidth

func NewBandwidth(value decimal.Decimal) Bandwidth

func (Bandwidth) ToDecimal

func (b Bandwidth) ToDecimal() decimal.Decimal

ToDecimal converts Bandwidth to decimal.

func (Bandwidth) ToTRX

func (b Bandwidth) ToTRX(transactionFee int64) TRX

ToTRX converts Bandwidth to TRX.

type ChainParams

type ChainParams struct {
	EnergyFee                           int64
	TransactionFee                      int64
	TotalEnergyCurrentLimit             int64
	FreeNetLimit                        int64
	CreateNewAccountFeeInSystemContract int64
	CreateAccountFee                    int64
}

type Config

type Config struct {
	NodeAddr                  string
	UseTLS                    bool
	ActivationContractAddress string
	UseBurnTRXActivation      bool
	GRPCOptions               []grpc.DialOption
}

type Energy

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

func NewEnergy

func NewEnergy(value decimal.Decimal) Energy

func (Energy) ToDecimal

func (e Energy) ToDecimal() decimal.Decimal

ToDecimal converts Energy to decimal.

func (Energy) ToTRX

func (e Energy) ToTRX(energyFee int64) TRX

ToTRX converts Energy to TRX.

type EstimateSystemActivationResourcesResult

type EstimateSystemActivationResourcesResult struct {
	Bandwidth decimal.Decimal `json:"bandwidth"`
	TRX       decimal.Decimal `json:"trx"`
}

EstimateSystemActivationResourcesResult

Bandwidth - amount of bandwidth required for activation contract call

TRX - amount of TRX required for activation contract call (burning trx for bandwidth and fixed activation fee)

type EstimateTransferResourcesResult

type EstimateTransferResourcesResult struct {
	Energy    decimal.Decimal `json:"energy"`
	Bandwidth decimal.Decimal `json:"bandwidth"`
	Trx       decimal.Decimal `json:"trx"`
}

type EstimateTransferWithDelegateResourcesRequest

type EstimateTransferWithDelegateResourcesRequest struct {
	ProcessingAddress string `json:"processing_address"`
	HotWalletAddress  string `json:"hot_wallet_address"`

	ProcessingResources Resources `json:"processing_resources"`
	HotResources        Resources `json:"hot_resources"`

	Estimate EstimateTransferResourcesResult `json:"estimate"`
}

EstimateTransferWithDelegateResourcesRequest is the request for EstimateTransferWithDelegateResources.

All fields are required.

type EstimateTransferWithDelegateResourcesResponse

type EstimateTransferWithDelegateResourcesResponse struct {
	NeedToDelegate                    Resources       `json:"need_to_delegate"`
	NeedBandwidthFromProcessingWallet decimal.Decimal `json:"need_bandwidth_from_processing_wallet"`
}

type EstimateTransferWithExternalDelegateResourcesRequest

type EstimateTransferWithExternalDelegateResourcesRequest struct {
	HotWalletAddress string `json:"hot_wallet_address"`

	HotResources Resources `json:"hot_resources"`

	Estimate EstimateTransferResourcesResult `json:"estimate"`
}

func (*EstimateTransferWithExternalDelegateResourcesRequest) Validate

type EstimateTransferWithExternalDelegateResourcesResponse

type EstimateTransferWithExternalDelegateResourcesResponse struct {
	NeedResourcesToTransfer Resources           `json:"need_resources_to_transfer"`
	NeedSystemResources     SystemResources     `json:"need_system_resources"`
	NeedResourcesToActivate ActivationResources `json:"need_resources_to_activate"`
	NeedToActivate          bool                `json:"need_to_activate"`
}

type MethodSignature

type MethodSignature string
const (
	ActivatorActivateMethodSignature MethodSignature = "1c5a9d9c"
)

func (MethodSignature) String

func (o MethodSignature) String() string

type ReclaimResourceParams

type ReclaimResourceParams struct {
	FromAddress  string
	FromSequence uint32
	Mnemonic     string
	PassPhrase   string
	ToAddress    string
	ResourceType core.ResourceCode
}

func (ReclaimResourceParams) Validate

func (p ReclaimResourceParams) Validate() error

Validate

type Resources

type Resources struct {
	Energy         decimal.Decimal `json:"energy"`
	Bandwidth      decimal.Decimal `json:"bandwidth"`
	TotalEnergy    decimal.Decimal `json:"total_energy"`
	TotalBandwidth decimal.Decimal `json:"total_bandwidth"`
}

type SystemResources

type SystemResources struct {
	NeedForEnergyDelegation    decimal.Decimal `json:"need_for_energy_delegation"`
	NeedForEnergyReclaim       decimal.Decimal `json:"need_for_energy_reclaim"`
	NeedForBandwidthDelegation decimal.Decimal `json:"need_for_bandwidth_delegation"`
	NeedForBandwidthReclaim    decimal.Decimal `json:"need_for_bandwidth_reclaim"`
}

type TRX

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

func NewTRX

func NewTRX(value decimal.Decimal) TRX

func (TRX) ToBandwidth

func (t TRX) ToBandwidth(transactionFee int64) decimal.Decimal

ToBandwidth converts TRX to Bandwidth.

func (TRX) ToDecimal

func (t TRX) ToDecimal() decimal.Decimal

ToDecimal converts TRX to decimal.

func (TRX) ToEnergy

func (t TRX) ToEnergy(energyFee int64) decimal.Decimal

ToEnergy converts TRX to Energy.

func (TRX) ToSUN

func (t TRX) ToSUN() decimal.Decimal

ToSUN converts TRX decimal.Decimal SUN.

type Tron

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

func NewTron

func NewTron(conf Config) (*Tron, error)

func (*Tron) AccountResourceInfo

func (t *Tron) AccountResourceInfo(ctx context.Context, addr string) (*AccountResourceInfoData, error)

func (*Tron) AvailableBandwidth

func (t *Tron) AvailableBandwidth(res *api.AccountResourceMessage) decimal.Decimal

AvailableBandwidth calculates the available bandwidth.

func (*Tron) AvailableBandwidthWithoutFree

func (t *Tron) AvailableBandwidthWithoutFree(res *api.AccountResourceMessage) decimal.Decimal

func (*Tron) AvailableEnergy

func (t *Tron) AvailableEnergy(res *api.AccountResourceMessage) decimal.Decimal

AvailableEnergy calculates the available energy.

func (*Tron) AvailableForDelegateResources

func (t *Tron) AvailableForDelegateResources(ctx context.Context, addr string) (*Resources, error)

AvailableForDelegateResources calculates the available energy and bandwidth for delegate to another account.

func (*Tron) ChainParam

func (t *Tron) ChainParam(ctx context.Context, paramKey string) (*core.ChainParameters_ChainParameter, error)

ChainParam get chain parameters

func (*Tron) ChainParams

func (t *Tron) ChainParams(ctx context.Context) (*ChainParams, error)

func (*Tron) CheckIsWalletActivated

func (t *Tron) CheckIsWalletActivated(address string) (bool, error)

CheckIsWalletActivated checks if the wallet is activated

func (*Tron) ConvertBandwidthToStackedTRX

func (t *Tron) ConvertBandwidthToStackedTRX(totalNetWeight, totalNetLimit int64, bandwidth decimal.Decimal) decimal.Decimal

ConvertBandwidthToStackedTRX converts bandwidth to stacked TRX. Returns value in SUN.

func (*Tron) ConvertEnergyToStackedTRX

func (t *Tron) ConvertEnergyToStackedTRX(totalEnergyCurrentLimit, totalEnergyWeight int64, energy decimal.Decimal) decimal.Decimal

ConvertEnergyToStackedTRX converts energy to stacked TRX. Returns value in SUN.

func (*Tron) ConvertStackedTRXToBandwidth

func (t *Tron) ConvertStackedTRXToBandwidth(totalNetWeight, totalNetLimit, stackedTrx int64) decimal.Decimal

ConvertStackedTRXToBandwidth converts stacked TRX to bandwidth.

func (*Tron) ConvertStackedTRXToEnergy

func (t *Tron) ConvertStackedTRXToEnergy(totalEnergyCurrentLimit, totalEnergyWeight, stackedTrx int64) decimal.Decimal

ConvertStackedTRXToEnergy converts stacked TRX to energy.

func (*Tron) CreateUnsignedActivationTransaction

func (t *Tron) CreateUnsignedActivationTransaction(ctx context.Context, caller string, receiver string, constant bool) (*api.TransactionExtention, error)

func (*Tron) EstimateActivationFee

func (t *Tron) EstimateActivationFee(ctx context.Context, fromAddress, toAddress string) (*ActivationResources, error)

EstimateActivationFee estimates the activation fee for a Tron address. It checks the available bandwidth and adds the activation fee accordingly. The fee is returned in TRX (1 TRX = 1_000_000 SUN). We assume that fromAddress is ALWAYS activated, being it processing address. Simple swap of arg to BlackHoleAddress on fakeTx creation will always return valid tx.

func (*Tron) EstimateBandwidth

func (t *Tron) EstimateBandwidth(tx *core.Transaction) (decimal.Decimal, error)

EstimateBandwidth calculates the estimated bandwidth.

func (*Tron) EstimateExternalContractActivation

func (t *Tron) EstimateExternalContractActivation(ctx context.Context, caller, receiver string) (*ActivationResources, error)

func (*Tron) EstimateSystemContractActivation

func (t *Tron) EstimateSystemContractActivation(ctx context.Context, caller string, receiver string) (*ActivationResources, error)

func (*Tron) EstimateTransferResources

func (t *Tron) EstimateTransferResources(
	ctx context.Context, fromAddress, toAddress, contractAddress string, amount decimal.Decimal, decimals int64,
) (*EstimateTransferResourcesResult, error)

EstimateTransferResources calculates the estimated transfer resources.

func (*Tron) GetMaxOperationsCount

func (t *Tron) GetMaxOperationsCount(availableEnergy, availableBandwidth int64) uint32

GetMaxOperationsCount calculates the maximum operations count based on the available energy and bandwidth.

func (*Tron) Name

func (t *Tron) Name() string

Name returns the service name

func (*Tron) Node

func (t *Tron) Node() *client.GrpcClient

Node returns the grpc client

func (*Tron) ReclaimResource

func (t *Tron) ReclaimResource(ctx context.Context, params ReclaimResourceParams) (*api.TransactionExtention, error)

func (*Tron) SignTransaction

func (t *Tron) SignTransaction(tx *core.Transaction, privateKey *ecdsa.PrivateKey) error

SignTransaction signs the transaction with the given private key

func (*Tron) StakedResources

func (t *Tron) StakedResources(ctx context.Context, addr string) (*api.AccountResourceMessage, []account.FrozenResource, error)

func (*Tron) Start

func (t *Tron) Start(_ context.Context) error

Start

func (*Tron) Stop

func (t *Tron) Stop(_ context.Context) error

Stop

func (*Tron) TotalAvailableResources

func (t *Tron) TotalAvailableResources(addr string) (*Resources, error)

TotalAvailableResources calculates the total available resources for the account.

func (*Tron) TotalBandwidthLimit

func (t *Tron) TotalBandwidthLimit(res *api.AccountResourceMessage) decimal.Decimal

func (*Tron) TotalEnergyLimit

func (t *Tron) TotalEnergyLimit(res *api.AccountResourceMessage) decimal.Decimal

type WalletSDK

type WalletSDK struct{}

func NewWalletSDK

func NewWalletSDK() *WalletSDK

NewWalletSDK creates a new WalletSDK instance.

func (WalletSDK) ValidateAddress

func (s WalletSDK) ValidateAddress(address string) bool

Jump to

Keyboard shortcuts

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