39 lines
782 B
Go
39 lines
782 B
Go
package genex
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
)
|
|
|
|
// Client Genex Chain SDK 客户端
|
|
type Client struct {
|
|
rpcURL string
|
|
chainID int64
|
|
ethClient *ethclient.Client
|
|
}
|
|
|
|
// NewClient 创建 Genex SDK 客户端
|
|
func NewClient(rpcURL string, chainID int64) (*Client, error) {
|
|
ethClient, err := ethclient.Dial(rpcURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Client{rpcURL: rpcURL, chainID: chainID, ethClient: ethClient}, nil
|
|
}
|
|
|
|
// Close 关闭客户端连接
|
|
func (c *Client) Close() {
|
|
if c.ethClient != nil {
|
|
c.ethClient.Close()
|
|
}
|
|
}
|
|
|
|
// GetEthClient 获取底层 go-ethereum 客户端
|
|
func (c *Client) GetEthClient() *ethclient.Client {
|
|
return c.ethClient
|
|
}
|
|
|
|
// GetChainID 获取链 ID
|
|
func (c *Client) GetChainID() int64 {
|
|
return c.chainID
|
|
}
|