Documentation
¶
Overview ¶
Package network exposes simple accessors for network-level information such as chain parameters and node metadata.
Manager Features ¶
The network manager provides methods for network-level queries:
cli, _ := client.NewClient("grpc://grpc.trongrid.io:50051")
defer cli.Close()
nm := network.NewManager(cli)
// Get chain parameters
params, err := nm.GetChainParameters(context.Background())
if err != nil { /* handle */ }
// Get node info
info, err := nm.GetNodeInfo(context.Background())
if err != nil { /* handle */ }
Error Handling ¶
Common error types:
- ErrNetworkUnavailable - Network or node unavailable
- ErrInvalidResponse - Invalid response from node
Always check for errors in production code.
Package network provides high-level network and node information functionality
Index ¶
- type NetworkManager
- func (m *NetworkManager) GetBlockById(ctx context.Context, blockId []byte) (*core.Block, error)
- func (m *NetworkManager) GetBlockByNumber(ctx context.Context, blockNumber int64) (*api.BlockExtention, error)
- func (m *NetworkManager) GetBlocksByLimit(ctx context.Context, startNum int64, endNum int64) (*api.BlockListExtention, error)
- func (m *NetworkManager) GetChainParameters(ctx context.Context) (*core.ChainParameters, error)
- func (m *NetworkManager) GetLatestBlocks(ctx context.Context, count int64) (*api.BlockListExtention, error)
- func (m *NetworkManager) GetNodeInfo(ctx context.Context) (*core.NodeInfo, error)
- func (m *NetworkManager) GetNowBlock(ctx context.Context) (*api.BlockExtention, error)
- func (m *NetworkManager) GetTransactionById(ctx context.Context, txIdHex string) (*core.Transaction, error)
- func (m *NetworkManager) GetTransactionInfoByBlockNum(ctx context.Context, blockNumber int64) (*api.TransactionInfoList, error)
- func (m *NetworkManager) GetTransactionInfoById(ctx context.Context, txIdHex string) (*core.TransactionInfo, error)
- func (m *NetworkManager) ListNodes(ctx context.Context) (*api.NodeList, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NetworkManager ¶
type NetworkManager struct {
// contains filtered or unexported fields
}
NetworkManager provides high-level network operations
func NewManager ¶
func NewManager(conn lowlevel.ConnProvider) *NetworkManager
NewManager creates a new network manager
Example ¶
ExampleNewManager demonstrates fetching node info.
package main
import (
"context"
"testing"
"time"
"github.com/kslamph/tronlib/pkg/client"
"github.com/kslamph/tronlib/pkg/network"
)
func main() {
if testing.Short() {
return
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
cli, _ := client.NewClient("grpc://grpc.trongrid.io:50051")
defer cli.Close()
nm := network.NewManager(cli)
_, _ = nm.GetNodeInfo(ctx)
}
Output:
func (*NetworkManager) GetBlockById ¶
GetBlockById retrieves a block by its ID (hash)
func (*NetworkManager) GetBlockByNumber ¶
func (m *NetworkManager) GetBlockByNumber(ctx context.Context, blockNumber int64) (*api.BlockExtention, error)
GetBlockByNumber retrieves a block by its number
func (*NetworkManager) GetBlocksByLimit ¶
func (m *NetworkManager) GetBlocksByLimit(ctx context.Context, startNum int64, endNum int64) (*api.BlockListExtention, error)
GetBlocksByLimit retrieves blocks by limit and next parameters
func (*NetworkManager) GetChainParameters ¶
func (m *NetworkManager) GetChainParameters(ctx context.Context) (*core.ChainParameters, error)
GetChainParameters retrieves the current chain parameters
func (*NetworkManager) GetLatestBlocks ¶
func (m *NetworkManager) GetLatestBlocks(ctx context.Context, count int64) (*api.BlockListExtention, error)
GetLatestBlocks retrieves the latest blocks by count
func (*NetworkManager) GetNodeInfo ¶
GetNodeInfo retrieves information about the connected node
func (*NetworkManager) GetNowBlock ¶
func (m *NetworkManager) GetNowBlock(ctx context.Context) (*api.BlockExtention, error)
GetNowBlock retrieves the current/latest block
func (*NetworkManager) GetTransactionById ¶ added in v1.0.5
func (m *NetworkManager) GetTransactionById(ctx context.Context, txIdHex string) (*core.Transaction, error)
GetTransactionById retrieves transaction by transaction ID (hex string)
func (*NetworkManager) GetTransactionInfoByBlockNum ¶ added in v1.0.9
func (m *NetworkManager) GetTransactionInfoByBlockNum(ctx context.Context, blockNumber int64) (*api.TransactionInfoList, error)
GetTransactionInfoByBlockNum queries the network for all transaction info records in the given block. It queries the network.
func (*NetworkManager) GetTransactionInfoById ¶
func (m *NetworkManager) GetTransactionInfoById(ctx context.Context, txIdHex string) (*core.TransactionInfo, error)
GetTransactionInfoById retrieves transaction information by transaction ID (hex string)