Replace encoding/hex and encoding/json dependencies on monero RPC code
This commit is contained in:
parent
5a50924816
commit
b36c9561b9
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue