<commit_before>package rpcclient

import (
	"bytes"
	"encoding/json"
	"errors"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"

	. "github.com/tendermint/go-common"
	"github.com/tendermint/go-rpc/types"
	"github.com/tendermint/go-wire"
)

// JSON rpc takes params as a slice
type ClientJSONRPC struct {
	remote string
}

func NewClientJSONRPC(remote string) *ClientJSONRPC {
	return &ClientJSONRPC{remote}
}

func (c *ClientJSONRPC) Call(method string, params []interface{}, result interface{}) (interface{}, error) {
	return CallHTTP_JSONRPC(c.remote, method, params, result)
}

// URI takes params as a map
type ClientURI struct {
	remote string
}

func NewClientURI(remote string) *ClientURI {
	if !strings.HasSuffix(remote, "/") {
		remote = remote + "/"
	}
	return &ClientURI{remote}
}

func (c *ClientURI) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
	return CallHTTP_URI(c.remote, method, params, result)
}

func CallHTTP_JSONRPC(remote string, method string, params []interface{}, result interface{}) (interface{}, error) {
	// Make request and get responseBytes
	request := rpctypes.RPCRequest{
		JSONRPC: "2.0",
		Method:  method,
		Params:  params,
		ID:      "",
	}
	requestBytes := wire.JSONBytes(request)
	requestBuf := bytes.NewBuffer(requestBytes)
	log.Info(Fmt("RPC request to %v: %v", remote, string(requestBytes)))
	httpResponse, err := http.Post(remote, "text/json", requestBuf)
	if err != nil {
		return nil, err
	}
	defer httpResponse.Body.Close()
	responseBytes, err := ioutil.ReadAll(httpResponse.Body)
	if err != nil {
		return nil, err
	}
	log.Info(Fmt("RPC response: %v", string(responseBytes)))
	return unmarshalResponseBytes(responseBytes, result)
}

func CallHTTP_URI(remote string, method string, params map[string]interface{}, result interface{}) (interface{}, error) {
	values, err := argsToURLValues(params)
	if err != nil {
		return nil, err
	}
	log.Info(Fmt("URI request to %v: %v", remote, values))<commit_msg>print method in client log<commit_after>package rpcclient

import (
	"bytes"
	"encoding/json"
	"errors"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"

	. "github.com/tendermint/go-common"
	"github.com/tendermint/go-rpc/types"
	"github.com/tendermint/go-wire"
)

// JSON rpc takes params as a slice
type ClientJSONRPC struct {
	remote string
}

func NewClientJSONRPC(remote string) *ClientJSONRPC {
	return &ClientJSONRPC{remote}
}

func (c *ClientJSONRPC) Call(method string, params []interface{}, result interface{}) (interface{}, error) {
	return CallHTTP_JSONRPC(c.remote, method, params, result)
}

// URI takes params as a map
type ClientURI struct {
	remote string
}

func NewClientURI(remote string) *ClientURI {
	if !strings.HasSuffix(remote, "/") {
		remote = remote + "/"
	}
	return &ClientURI{remote}
}

func (c *ClientURI) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
	return CallHTTP_URI(c.remote, method, params, result)
}

func CallHTTP_JSONRPC(remote string, method string, params []interface{}, result interface{}) (interface{}, error) {
	// Make request and get responseBytes
	request := rpctypes.RPCRequest{
		JSONRPC: "2.0",
		Method:  method,
		Params:  params,
		ID:      "",
	}
	requestBytes := wire.JSONBytes(request)
	requestBuf := bytes.NewBuffer(requestBytes)
	log.Info(Fmt("RPC request to %v (%v): %v", remote, method, string(requestBytes)))
	httpResponse, err := http.Post(remote, "text/json", requestBuf)
	if err != nil {
		return nil, err
	}
	defer httpResponse.Body.Close()
	responseBytes, err := ioutil.ReadAll(httpResponse.Body)
	if err != nil {
		return nil, err
	}
	log.Info(Fmt("RPC response: %v", string(responseBytes)))
	return unmarshalResponseBytes(responseBytes, result)
}

func CallHTTP_URI(remote string, method string, params map[string]interface{}, result interface{}) (interface{}, error) {
	values, err := argsToURLValues(params)
	if err != nil {
		return nil, err
	}
	log.Info(Fmt("URI request to %v (%v): %v", remote, method, values))
{'fraction_non_alphanumeric': 0.14197071233556713, 'fraction_numerical': 0.0009928021841648052, 'mean_word_length': 5.0059612518628915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7280700', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1354, 'n_words': 359}