network

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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)
}

func (*NetworkManager) GetBlockById

func (m *NetworkManager) GetBlockById(ctx context.Context, blockId []byte) (*core.Block, error)

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

func (m *NetworkManager) GetNodeInfo(ctx context.Context) (*core.NodeInfo, error)

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)

func (*NetworkManager) ListNodes

func (m *NetworkManager) ListNodes(ctx context.Context) (*api.NodeList, error)

ListNodes retrieves the list of connected nodes

Jump to

Keyboard shortcuts

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