diff --git a/monero/client/rpc/client.go b/monero/client/rpc/client.go index 3490571..704afed 100644 --- a/monero/client/rpc/client.go +++ b/monero/client/rpc/client.go @@ -3,8 +3,8 @@ package rpc import ( "bytes" "context" - "encoding/json" "fmt" + "git.gammaspectra.live/P2Pool/consensus/v3/utils" "io" "net/http" "net/url" @@ -137,7 +137,7 @@ func (c *Client) RawRequest(ctx context.Context, endpoint string, params interfa var body io.Reader if params != nil { - b, err := json.Marshal(params) + b, err := utils.MarshalJSON(params) if err != nil { return fmt.Errorf("marshal: %w", err) } @@ -166,7 +166,7 @@ func (c *Client) JSONRPC(ctx context.Context, method string, params interface{}, address := *c.address address.Path = endpointJSONRPC - b, err := json.Marshal(&RequestEnvelope{ + b, err := utils.MarshalJSON(&RequestEnvelope{ ID: "0", JSONRPC: versionJSONRPC, Method: method, @@ -215,7 +215,7 @@ func (c *Client) submitRequest(req *http.Request, response interface{}) error { return fmt.Errorf("non-2xx status code: %d", resp.StatusCode) } - if err := json.NewDecoder(resp.Body).Decode(response); err != nil { + if err := utils.NewJSONDecoder(resp.Body).Decode(response); err != nil { return fmt.Errorf("decode: %w", err) } diff --git a/monero/client/rpc/client_test.go b/monero/client/rpc/client_test.go index f3a097c..5140838 100644 --- a/monero/client/rpc/client_test.go +++ b/monero/client/rpc/client_test.go @@ -2,8 +2,8 @@ package rpc_test import ( "context" - "encoding/json" "fmt" + "git.gammaspectra.live/P2Pool/consensus/v3/utils" "net/http" "net/http/httptest" "testing" @@ -100,7 +100,7 @@ func TestClient(t *testing.T) { ) handler := func(w http.ResponseWriter, r *http.Request) { - err := json.NewDecoder(r.Body).Decode(body) + err := utils.NewJSONDecoder(r.Body).Decode(body) assert.NoError(t, err) } diff --git a/monero/client/rpc/daemon/binary_endpoints.go b/monero/client/rpc/daemon/binary_endpoints.go index d93c2c4..7202aed 100644 --- a/monero/client/rpc/daemon/binary_endpoints.go +++ b/monero/client/rpc/daemon/binary_endpoints.go @@ -3,9 +3,9 @@ package daemon import ( "bytes" "context" - "encoding/hex" "errors" "git.gammaspectra.live/P2Pool/consensus/v3/monero/client/levin" + fasthex "github.com/tmthrgd/go-hex" "io" ) @@ -17,7 +17,7 @@ func (c *Client) GetOIndexes( ctx context.Context, txid string, ) (indexes []uint64, finalError error) { - binaryTxId, err := hex.DecodeString(txid) + binaryTxId, err := fasthex.DecodeString(txid) if err != nil { return nil, err } diff --git a/monero/client/rpc/daemon/jsonrpc.go b/monero/client/rpc/daemon/jsonrpc.go index 21fdecb..1640daf 100644 --- a/monero/client/rpc/daemon/jsonrpc.go +++ b/monero/client/rpc/daemon/jsonrpc.go @@ -2,9 +2,9 @@ package daemon import ( "context" - "encoding/hex" - "encoding/json" "fmt" + "git.gammaspectra.live/P2Pool/consensus/v3/utils" + fasthex "github.com/tmthrgd/go-hex" ) const ( @@ -251,7 +251,7 @@ func (c *Client) SubmitBlock(ctx context.Context, blobs ...[]byte) (*SubmitBlock params := make([]string, 0, len(blobs)) for _, blob := range blobs { - params = append(params, hex.EncodeToString(blob)) + params = append(params, fasthex.EncodeToString(blob)) } err := c.JSONRPC(ctx, methodSubmitBlock, params, resp) @@ -321,7 +321,7 @@ func (c *Client) GetCoinbaseTxSum( func (j *GetBlockResult) InnerJSON() (*GetBlockResultJSON, error) { res := &GetBlockResultJSON{} - err := json.Unmarshal([]byte(j.JSON), res) + err := utils.UnmarshalJSON([]byte(j.JSON), res) if err != nil { return nil, fmt.Errorf("unmarshal: %w", err) } diff --git a/monero/client/rpc/daemon/raw_endpoints.go b/monero/client/rpc/daemon/raw_endpoints.go index d1a4352..43518c0 100644 --- a/monero/client/rpc/daemon/raw_endpoints.go +++ b/monero/client/rpc/daemon/raw_endpoints.go @@ -2,8 +2,8 @@ package daemon import ( "context" - "encoding/json" "fmt" + "git.gammaspectra.live/P2Pool/consensus/v3/utils" ) const ( @@ -229,7 +229,7 @@ func (r *GetTransactionsResult) GetTransactions() ([]*TransactionJSON, error) { } t := &TransactionJSON{} - err := json.Unmarshal([]byte(txn.AsJSON), t) + err := utils.UnmarshalJSON([]byte(txn.AsJSON), t) if err != nil { return nil, fmt.Errorf("unmarshal txn '%s': %w", txn.TxHash, err)