openethereum-node-status/pkg/rpc/client.go
2021-12-14 14:24:18 +03:00

31 lines
564 B
Go

package rpc
import (
"fmt"
"github.com/ybbus/jsonrpc/v2"
)
type RpcClient struct {
ethClient jsonrpc.RPCClient
}
func NewRpcClient(endpoint string) RpcClient {
return RpcClient{
ethClient: jsonrpc.NewClient(endpoint),
}
}
func (r *RpcClient) EthRpcCall(method string) (*jsonrpc.RPCResponse, error) {
response, err := r.ethClient.Call(method)
if err != nil {
return response, err
}
if response.Error != nil {
return response, fmt.Errorf("rpc client error: (code %d) %s", response.Error.Code, response.Error.Message)
}
return response, nil
}