project: init
This commit is contained in:
30
pkg/rpc/client.go
Normal file
30
pkg/rpc/client.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user