Fetch the repository succeeded.
package tron
import (
"fmt"
"gitee.com/fu-ce-wei/wallet-grpc/core/base"
"github.com/fbsobreira/gotron-sdk/pkg/client"
"google.golang.org/grpc"
"math/big"
"time"
)
type TronChain struct {
RemoteRpcClient *client.GrpcClient
RpcClient *client.GrpcClient
timeout time.Duration
chainId *big.Int
rpcUrl string
}
func NewTronChain() *TronChain {
timeout := 60 * time.Second
return &TronChain{
timeout: timeout,
}
}
func (e *TronChain) CreateRemote(rpcUrl string) (chain *TronChain, err error) {
return e.CreateRemoteWithTimeout(rpcUrl, 0)
}
// @param timeout time unit millsecond. 0 means use chain's default: 60000ms.
func (e *TronChain) CreateRemoteWithTimeout(rpcUrl string, timeout int64) (chain *TronChain, err error) {
defer base.CatchPanicAndMapToBasicError(&err)
remoteRpcClient := client.NewGrpcClient(rpcUrl)
err = e.RemoteRpcClient.Start(grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("grpc client start error: %v", err)
}
e.chainId = big.NewInt(1)
e.RpcClient = remoteRpcClient
e.RemoteRpcClient = remoteRpcClient
e.rpcUrl = rpcUrl
return e, nil
}
func (e *TronChain) ConnectRemote(rpcUrl string) error {
_, err := e.CreateRemote(rpcUrl)
return err
}
func (e *TronChain) Close() {
if e.RemoteRpcClient != nil {
e.RemoteRpcClient.Stop()
}
if e.RpcClient != nil {
e.RpcClient.Stop()
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。