wallet/pkg/tron/tron_block.go
Anton Nesterov 5efcf35dd6
[init]
2024-08-31 16:59:34 +02:00

35 lines
875 B
Go

package tron
import (
"github.com/fbsobreira/gotron-sdk/pkg/client"
"github.com/fbsobreira/gotron-sdk/pkg/proto/api"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func TronLastBlock() (uint64, error) {
conn := client.NewGrpcClient(tronNode.grpcNode)
err := conn.Start(grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return 0, err
}
block, err := conn.GetNowBlock()
if err != nil {
return 0, err
}
return uint64(block.BlockHeader.RawData.Number), nil
}
func TronBlockByNumber(blockNumber uint64) (*api.BlockExtention, error) {
conn := client.NewGrpcClient(tronNode.grpcNode)
err := conn.Start(grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
block, err := conn.GetBlockByNum(int64(blockNumber))
if err != nil {
return nil, err
}
return block, nil
}