tron

package
v0.0.0-...-088215f Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainName  = "Tron"
	TronSymbol = "TRX"
)
View Source
const (
	AddressPrefix = "41"
)

Variables

This section is empty.

Functions

func Base58ToHex

func Base58ToHex(base58Address string) (string, error)

Base58ToHex Convert TRON address from base58 to hexadecimal

func NewChainAdaptor

func NewChainAdaptor(conf *config.Config) (chain.IChainAdaptor, error)

func PadLeftZero

func PadLeftZero(hexStr string, length int) string

PadLeftZero Fill the left side of the hexadecimal string with zero to the specified length

func ParseTRC20TransferData

func ParseTRC20TransferData(data string) (string, *big.Int)

ParseTRC20TransferData Extract the 'to' address and 'amount' from ABI encoded data`

Types

type Account

type Account struct {
	Address             string                `json:"address"`
	Balance             int                   `json:"balance"`
	CreateTime          int64                 `json:"create_time"`
	LatestConsumeTime   int64                 `json:"latest_consume_time"`
	NetWindowSize       int                   `json:"net_window_size"`
	NetWindowOptimized  bool                  `json:"net_window_optimized"`
	AccountResource     AccountResource       `json:"account_resource"`
	OwnerPermission     OwnerPermission       `json:"owner_permission"`
	ActivePermission    []ActivePermission    `json:"active_permission"`
	FrozenV2            []FrozenV2            `json:"frozenV2"`
	AssetV2             []AssetV2             `json:"assetV2"`
	FreeAssetNetUsageV2 []FreeAssetNetUsageV2 `json:"free_asset_net_usageV2"`
	AssetOptimized      bool                  `json:"asset_optimized"`
}

type AccountResource

type AccountResource struct {
	LatestConsumeTimeForEnergy                int64 `json:"latest_consume_time_for_energy"`
	EnergyWindowSize                          int   `json:"energy_window_size"`
	AcquiredDelegatedFrozenV2BalanceForEnergy int   `json:"acquired_delegated_frozenV2_balance_for_energy"`
	EnergyWindowOptimized                     bool  `json:"energy_window_optimized"`
}

type ActivePermission

type ActivePermission struct {
	Type           string `json:"type"`
	ID             int    `json:"id"`
	PermissionName string `json:"permission_name"`
	Threshold      int    `json:"threshold"`
	Operations     string `json:"operations"`
	Keys           []Keys `json:"keys"`
}

type AssetV2

type AssetV2 struct {
	Key   string `json:"key"`
	Value int64  `json:"value"`
}

type Block

type Block struct {
	BaseFeePerGas    string        `json:"baseFeePerGas"`
	Difficulty       string        `json:"difficulty"`
	ExtraData        string        `json:"extraData"`
	GasLimit         string        `json:"gasLimit"`
	GasUsed          string        `json:"gasUsed"`
	Hash             string        `json:"hash"`
	LogsBloom        string        `json:"logsBloom"`
	Miner            string        `json:"miner"`
	MixHash          string        `json:"mixHash"`
	Nonce            string        `json:"nonce"`
	Number           string        `json:"number"`
	ParentHash       string        `json:"parentHash"`
	ReceiptsRoot     string        `json:"receiptsRoot"`
	Sha3Uncles       string        `json:"sha3Uncles"`
	Size             string        `json:"size"`
	StateRoot        string        `json:"stateRoot"`
	Timestamp        string        `json:"timestamp"`
	TotalDifficulty  string        `json:"totalDifficulty"`
	Transactions     []string      `json:"transactions"`
	TransactionsRoot string        `json:"transactionsRoot"`
	Uncles           []interface{} `json:"uncles"`
}

type BroadcastReturns

type BroadcastReturns struct {
	Code    string `json:"code"`
	Txid    string `json:"txid"`
	Message string `json:"message"`
}

type ChainAdaptor

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

func (*ChainAdaptor) BuildSignedTransaction

BuildSignedTransaction Create a signed transaction

func (*ChainAdaptor) ConvertAddress

ConvertAddress Convert public key to address

func (*ChainAdaptor) CreateUnSignTransaction

CreateUnSignTransaction Create unsigned transactions

func (*ChainAdaptor) DecodeTransaction

DecodeTransaction Decoding transactions

func (*ChainAdaptor) GetAccount

GetAccount Obtain account information based on the address

func (*ChainAdaptor) GetBlockByHash

func (c *ChainAdaptor) GetBlockByHash(req *account.BlockHashRequest) (*account.BlockResponse, error)

GetBlockByHash Obtain block information based on block hash

func (*ChainAdaptor) GetBlockByNumber

func (c *ChainAdaptor) GetBlockByNumber(req *account.BlockNumberRequest) (*account.BlockResponse, error)

GetBlockByNumber Obtain block information based on block height

func (*ChainAdaptor) GetBlockByRange

GetBlockByRange Obtain blocks based on their scope

func (*ChainAdaptor) GetBlockHeaderByHash

func (c *ChainAdaptor) GetBlockHeaderByHash(req *account.BlockHeaderHashRequest) (*account.BlockHeaderResponse, error)

GetBlockHeaderByHash Obtain block header information based on block hash

func (*ChainAdaptor) GetBlockHeaderByNumber

func (c *ChainAdaptor) GetBlockHeaderByNumber(req *account.BlockHeaderNumberRequest) (*account.BlockHeaderResponse, error)

GetBlockHeaderByNumber Obtain block header information based on block height

func (*ChainAdaptor) GetExtraData

GetExtraData Obtain additional data

func (*ChainAdaptor) GetFee

GetFee Obtain transaction fees

func (*ChainAdaptor) GetSupportChains

GetSupportChains Return whether the chain is supported

func (*ChainAdaptor) GetTxByAddress

GetTxByAddress Obtain transactions based on the address

func (*ChainAdaptor) GetTxByHash

func (c *ChainAdaptor) GetTxByHash(req *account.TxHashRequest) (*account.TxHashResponse, error)

GetTxByHash Obtain transactions based on transaction hash

func (*ChainAdaptor) SendTx

SendTx Send transaction

func (*ChainAdaptor) ValidAddress

ValidAddress verify address

func (*ChainAdaptor) VerifySignedTransaction

VerifySignedTransaction verify signature

type ChainParameters

type ChainParameters struct {
	ChainParameter []struct {
		Key   string `json:"key"`
		Value int64  `json:"value,omitempty"`
	} `json:"chainParameter"`
}

type Contract

type Contract struct {
	Parameter Parameter `json:"parameter"`
	Type      string    `json:"type"`
}

type FreeAssetNetUsageV2

type FreeAssetNetUsageV2 struct {
	Key   string `json:"key"`
	Value int    `json:"value"`
}

type FrozenV2

type FrozenV2 struct {
	Type string `json:"type,omitempty"`
}

type Keys

type Keys struct {
	Address string `json:"address"`
	Weight  int    `json:"weight"`
}

type OwnerPermission

type OwnerPermission struct {
	PermissionName string `json:"permission_name"`
	Threshold      int    `json:"threshold"`
	Keys           []Keys `json:"keys"`
}

type Parameter

type Parameter struct {
	Value   Value  `json:"value"`
	TypeURL string `json:"type_url"`
}

type RawData

type RawData struct {
	Contract      []Contract `json:"contract"`
	RefBlockBytes string     `json:"ref_block_bytes"`
	RefBlockHash  string     `json:"ref_block_hash"`
	Expiration    int64      `json:"expiration"`
	Timestamp     int64      `json:"timestamp"`
}

type Response

type Response[T any] struct {
	Jsonrpc string `json:"jsonrpc"`
	Id      int    `json:"id"`
	Result  T      `json:"result"`
}

type Ret

type Ret struct {
	ContractRet string `json:"contractRet"`
}

type SendTxReq

type SendTxReq struct {
	RawData    RawData `json:"raw_data"`
	RawDataHex string  `json:"raw_data_hex"`
}

type TRC20BalanceResponse

type TRC20BalanceResponse struct {
	Data []struct {
		OwnerPermission       OwnerPermission     `json:"owner_permission"`
		AccountResource       AccountResource     `json:"account_resource"`
		ActivePermission      AccountResource     `json:"active_permission"`
		Address               string              `json:"address"`
		CreateTime            int64               `json:"create_time"`
		LatestOprationTime    int64               `json:"latest_opration_time"`
		FreeAssetNetUsageV2   FreeAssetNetUsageV2 `json:"free_asset_net_usageV2"`
		FreeNetUsage          int                 `json:"free_net_usage"`
		AssetV2               AssetV2             `json:"assetV2"`
		FrozenV2              FrozenV2            `json:"frozenV2"`
		Balance               int64               `json:"balance"`
		TRC20                 []map[string]string `json:"trc20"`
		LatestConsumeFreeTime int64               `json:"latest_consume_free_time"`
		NetWindowSize         int                 `json:"net_window_size"`
		NetWindowOptimized    bool                `json:"net_window_optimized"`
	} `json:"data"`
	Success bool `json:"success"`
	Meta    struct {
		At       int64 `json:"at"`
		PageSize int   `json:"page_size"`
	} `json:"meta"`
}

type Transaction

type Transaction struct {
	Ret        []Ret    `json:"ret"`
	Signature  []string `json:"signature"`
	TxID       string   `json:"txID"`
	RawData    RawData  `json:"raw_data"`
	RawDataHex string   `json:"raw_data_hex"`
}

type TronClient

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

TronClient Define a Tron RPC client

func DialTronClient

func DialTronClient(rpcURL, rpcUser, rpcPass string) *TronClient

DialTronClient Initialize and return a TronClient instance

func (*TronClient) BroadcastTransaction

func (client *TronClient) BroadcastTransaction(raw *SendTxReq) (*BroadcastReturns, error)

BroadcastTransaction Broadcast trading

func (*TronClient) CreateTRC20Transaction

func (client *TronClient) CreateTRC20Transaction(from, to, contractAddress string, amount int64) (*UnSignTransaction, error)

CreateTRC20Transaction Create TRC20 token transaction to be signed

func (*TronClient) CreateTRXTransaction

func (client *TronClient) CreateTRXTransaction(from, to string, amount int64) (*UnSignTransaction, error)

CreateTRXTransaction Create TRX transaction to be signed

func (*TronClient) GetAccount

func (client *TronClient) GetAccount(address string) (*Account, error)

GetAccount Get account information

func (*TronClient) GetBlockByHash

func (client *TronClient) GetBlockByHash(blockHash string) (*Block, error)

GetBlockByHash Obtain block information based on block hash

func (*TronClient) GetBlockByNumber

func (client *TronClient) GetBlockByNumber(blockNumber int64) (*Block, error)

GetBlockByNumber Obtain block information based on block number

func (*TronClient) GetChainParameters

func (client *TronClient) GetChainParameters() (*ChainParameters, error)

GetChainParameters Get chain parameters

func (*TronClient) GetTRC20Balance

func (client *TronClient) GetTRC20Balance(address, contractAddress string) (string, error)

GetTRC20Balance Query the TRC20 token balance at the specified address

func (*TronClient) GetTransactionByID

func (client *TronClient) GetTransactionByID(txHash string) (*Transaction, error)

GetTransactionByID Obtain transaction information based on transaction hash

func (*TronClient) GetTxByAddress

func (client *TronClient) GetTxByAddress(address string) (interface{}, error)

GetTxByAddress Obtain transaction list based on address

func (*TronClient) JsonRpc

func (client *TronClient) JsonRpc(method string, params interface{}, result interface{}) error

JsonRpc Call JSON-RPC

func (*TronClient) Solidity

func (client *TronClient) Solidity(method string, params interface{}, result interface{}) error

Solidity Call Solidity

func (*TronClient) Wallet

func (client *TronClient) Wallet(method string, params interface{}, result interface{}) error

Wallet Call Wallet

type TronData

type TronData struct {
	TronDataCli *oklink.ChainExplorerAdaptor
}

func NewTronDataClient

func NewTronDataClient(baseUrl, apiKey string, timeout time.Duration) (*TronData, error)

func (*TronData) GetEstimateGasFee

func (td *TronData) GetEstimateGasFee() (*gas_fee.GasEstimateFeeResponse, error)

GetEstimateGasFee Obtain estimated transaction fees

func (*TronData) GetTxByAddress

func (td *TronData) GetTxByAddress(page, pagesize uint64, address string, action account.ActionType) (*account.TransactionResponse[account.AccountTxResponse], error)

GetTxByAddress Transaction for obtaining address

type TxStructure

type TxStructure struct {
	ContractAddress string `json:"contract_address"`
	FromAddress     string `json:"from_address"`
	ToAddress       string `json:"to_address"`
	Value           int64  `json:"value"`
}

type UnSignTransaction

type UnSignTransaction struct {
	Visible    bool    `json:"visible"`
	TxID       string  `json:"txID"`
	RawData    RawData `json:"raw_data"`
	RawDataHex string  `json:"raw_data_hex"`
}

type UnSignTrc20Transaction

type UnSignTrc20Transaction struct {
	Result struct {
		Result bool `json:"result"`
	} `json:"result"`
	Transaction UnSignTransaction `json:"transaction"`
}

type Value

type Value struct {
	Amount          int    `json:"amount"`
	OwnerAddress    string `json:"owner_address"`
	ToAddress       string `json:"to_address"`
	CallValue       int    `json:"call_value"`
	ContractAddress string `json:"contract_address"`
	Data            string `json:"data"`
}

Jump to

Keyboard shortcuts

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