mychain

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: BSD-3-Clause Imports: 22 Imported by: 2

README

mychain 061902

Documentation

Index

Constants

View Source
const (
	ContractAddrTronTrc20 = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"         //Tether(USDT)在波场(TRON)网络上的 TRC20 合约地址
	ContractAddrERCUSDT   = "0xdac17f958d2ee523a2206206994597c13d831ec7" //ERC-USDT 合约地址
	ContractAddrERCUSDC   = "0xA0b86991C6218b36c1d19D4a2e9Eb0cE3606eB48" //ERC-USDC 合约地址
)

Variables

This section is empty.

Functions

func ImpBtcChain added in v1.0.5

func ImpBtcChain() btcChain

func ImpEth

func ImpEth(apiKey string) ethChain

func ImpTron

func ImpTron(token string) tronChain

Types

type AccountInfo added in v1.0.4

type AccountInfo struct {
	Balance int64               `json:"balance"` //单位Sun (1 TRX = 1,000,000 sun)
	TRC20   []map[string]string `json:"trc20"`   //合约地址(key)和余额(value),余额单位为最小计量单位
}

账号详情

func (*AccountInfo) GetTrc20Balance added in v1.0.4

func (self *AccountInfo) GetTrc20Balance() float64

获取 TRC20 代币余额

func (*AccountInfo) GetTrxBalance added in v1.0.4

func (self *AccountInfo) GetTrxBalance() float64

type BtcTxInfo added in v1.0.5

type BtcTxInfo struct {
	TxID        string  // 交易ID
	Time        string  // 交易时间
	FromAddress string  // 发送地址
	ToAddress   string  // 接收地址
	AmountBTC   float64 // 金额(单位 BTC)
	Currency    string  // 币种(固定 BTC)
}

func (BtcTxInfo) TimeStamp added in v1.0.5

func (self BtcTxInfo) TimeStamp() int64

type EthBlock

type EthBlock struct {
	Jsonrpc string `json:"jsonrpc"`
	Id      int    `json:"id"`
	Result  struct {
		BaseFeePerGas         string `json:"baseFeePerGas"`
		BlobGasUsed           string `json:"blobGasUsed"`
		Difficulty            string `json:"difficulty"`
		ExcessBlobGas         string `json:"excessBlobGas"`
		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"`
		ParentBeaconBlockRoot string `json:"parentBeaconBlockRoot"`
		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          []struct {
			BlockHash            string `json:"blockHash"`
			BlockNumber          string `json:"blockNumber"`
			From                 string `json:"from"`
			Gas                  string `json:"gas"`
			GasPrice             string `json:"gasPrice"`
			MaxFeePerGas         string `json:"maxFeePerGas,omitempty"`
			MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas,omitempty"`
			Hash                 string `json:"hash"`
			Input                string `json:"input"`
			Nonce                string `json:"nonce"`
			To                   string `json:"to"`
			TransactionIndex     string `json:"transactionIndex"`
			Value                string `json:"value"`
			Type                 string `json:"type"`
			AccessList           []struct {
				Address     string   `json:"address"`
				StorageKeys []string `json:"storageKeys"`
			} `json:"accessList,omitempty"`
			ChainId             string   `json:"chainId"`
			V                   string   `json:"v"`
			R                   string   `json:"r"`
			S                   string   `json:"s"`
			YParity             string   `json:"yParity,omitempty"`
			MaxFeePerBlobGas    string   `json:"maxFeePerBlobGas,omitempty"`
			BlobVersionedHashes []string `json:"blobVersionedHashes,omitempty"`
		} `json:"transactions"`
		TransactionsRoot string `json:"transactionsRoot"`
		//Uncles           []interface{} `json:"uncles"`
		Withdrawals []struct {
			Index          string `json:"index"`
			ValidatorIndex string `json:"validatorIndex"`
			Address        string `json:"address"`
			Amount         string `json:"amount"`
		} `json:"withdrawals"`
		WithdrawalsRoot string `json:"withdrawalsRoot"`
	} `json:"result"`
}

type EthBlockNum

type EthBlockNum struct {
	Jsonrpc string `json:"jsonrpc"`
	Id      int    `json:"id"`
	Result  string `json:"result"`
}

func (*EthBlockNum) ToNumber

func (self *EthBlockNum) ToNumber() int64

type EthTx added in v1.0.8

type EthTx struct {
	Hash        string `json:"hash"`
	BlockNumber string `json:"blockNumber"`
	From        string `json:"from"`
	To          string `json:"to"`
	Value       string `json:"value"`     // string 类型防止超长
	TokenName   string `json:"tokenName"` // 仅 ERC20 有效
	TokenSymbol string `json:"tokenSymbol"`
	TimeStamp   string `json:"timeStamp"`
}

func (EthTx) ToAmount added in v1.0.8

func (t EthTx) ToAmount() float64

内嵌方法:转为 float64 金额(自动判断 TokenSymbol 小数位)

func (EthTx) ToTimeStamp added in v1.0.8

func (t EthTx) ToTimeStamp() time.Time

转为时间类型 time.Time(UTC 时间)

type NetworkRes added in v1.0.11

type NetworkRes struct {
	TotalNetLimit     int64 `json:"TotalNetLimit"`
	TotalNetWeight    int64 `json:"TotalNetWeight"`
	TotalEnergyLimit  int64 `json:"TotalEnergyLimit"`
	TotalEnergyWeight int64 `json:"TotalEnergyWeight"`
}

func (*NetworkRes) CalcTrxForBandwidth added in v1.0.11

func (self *NetworkRes) CalcTrxForBandwidth(net int64) (float64, error)

计算获取指定带宽所需的TRX

func (*NetworkRes) CalcTrxForEnergy added in v1.0.11

func (self *NetworkRes) CalcTrxForEnergy(energy int64) (float64, error)

type TRC20Tx added in v1.0.8

type TRC20Tx struct {
	TxID        string `json:"transaction_id"`
	Timestamp   int64  `json:"block_timestamp"`
	BlockNumber int64  `json:"block_number"` // ✅ 增加区块高度
	From        string `json:"from"`
	To          string `json:"to"`
	TokenInfo   struct {
		Symbol   string `json:"symbol"` //代币符号,常用于判断是否为 USDT
		Name     string `json:"name"`   //代币合约地址,最准确的识别方式
		Address  string `json:"address"`
		Decimals int    `json:"decimals"` //精度,用于 value 转换成实际金额
	} `json:"token_info"`
	Value string `json:"value"` // 注意是字符串,需自行转换
}

TRC20Tx 表示一个 TRC20 交易记录

func (*TRC20Tx) ToTime added in v1.0.9

func (t *TRC20Tx) ToTime() time.Time

func (*TRC20Tx) ToUsdt added in v1.0.8

func (t *TRC20Tx) ToUsdt() float64

type TRXTx added in v1.0.8

type TRXTx struct {
	TxID        string `json:"txID"`
	Timestamp   int64  `json:"block_timestamp"`
	BlockNumber int64  // ✅ 区块高度
	From        string
	To          string
	Amount      int64 // 单位:sun(1 TRX = 1_000_000 sun)
}

TRXTx 代表一条 TRX 主币转账交易

func (*TRXTx) ToTime added in v1.0.9

func (t *TRXTx) ToTime() time.Time

func (*TRXTx) ToTrx added in v1.0.8

func (t *TRXTx) ToTrx() float64

type TokenData added in v1.0.3

type TokenData struct {
	TokenId         string  `json:"tokenId"`
	TokenName       string  `json:"tokenName"`
	TokenDecimal    int     `json:"tokenDecimal"`
	TokenAbbr       string  `json:"tokenAbbr"`
	TokenCanShow    int     `json:"tokenCanShow"`
	TokenType       string  `json:"tokenType"`
	Vip             bool    `json:"vip"`
	Balance         string  `json:"balance"`
	TokenPriceInTrx int     `json:"tokenPriceInTrx"`
	TokenPriceInUsd float64 `json:"tokenPriceInUsd"`
	AssetInTrx      float64 `json:"assetInTrx"`
	AssetInUsd      float64 `json:"assetInUsd"`
	Percent         int     `json:"percent"`
}

代币详情

type TokenOverview added in v1.0.3

type TokenOverview struct {
	TotalAssetInTrx float64     `json:"totalAssetInTrx"`
	Data            []TokenData `json:"data"`
	TotalTokenCount int         `json:"totalTokenCount"`
	TotalAssetInUsd float64     `json:"totalAssetInUsd"`
}

代币概览

type TronBlock

type TronBlock struct {
	BlockID     string `json:"blockID"` //区块编号,
	BlockHeader struct {
		RawData struct {
			Number         int64  `json:"number"`          //区块编号,也就是链上区块的高度
			TxTrieRoot     string `json:"txTrieRoot"`      //交易根节点的哈希值
			WitnessAddress string `json:"witness_address"` //产生该区块的超级代表的帐户地址
			ParentHash     string `json:"parentHash"`      //上一区块的ID
			Version        int    `json:"version"`         //标识链的版本
			Timestamp      int64  `json:"timestamp"`       //创建块的时间戳
		} `json:"raw_data"`
		WitnessSignature string `json:"witness_signature"` //产生区块的超级代表的签名
	} `json:"block_header"`
	Transactions []TronTransactionInfo `json:"transactions"` //打包进该区块的交易清单
}

type TronContractInfo

type TronContractInfo struct {
	Parameter struct {
		Value struct {
			Data            string `json:"data"` //从中解析交易类型,交易对象,交易金额
			OwnerAddress    string `json:"owner_address"`
			ToAddress       string `json:"to_address"`
			ContractAddress string `json:"contract_address"`
			Amount          int    `json:"amount"`
		} `json:"value"`
		TypeUrl string `json:"type_url"`
	} `json:"parameter"`
	Type string `json:"type"`
}

type TronTrRawInfo

type TronTrRawInfo struct {
	Contract      []TronContractInfo `json:"contract"`
	RefBlockBytes string             `json:"ref_block_bytes"`
	RefBlockHash  string             `json:"ref_block_hash"`
	Expiration    int64              `json:"expiration"`
	Timestamp     int64              `json:"timestamp"`
	FeeLimit      int                `json:"fee_limit"`
}

type TronTrResult

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

type TronTransaction added in v1.0.11

type TronTransaction struct {
	TxID       string   `json:"txID"`
	RawData    any      `json:"raw_data"`
	RawDataHex string   `json:"raw_data_hex"`
	Signature  []string `json:"signature,omitempty"`
	Error      string   `json:"Error,omitempty"`
}

TronTransaction Tron返回的交易体

type TronTransactionInfo

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

Jump to

Keyboard shortcuts

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