project: init

This commit is contained in:
2021-12-14 14:24:18 +03:00
commit a543115d40
7 changed files with 402 additions and 0 deletions

30
pkg/rpc/client.go Normal file
View 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
}