Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions clients/feeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package feeder

import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
Expand All @@ -11,6 +10,7 @@ import (

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/starknet"
"github.com/NethermindEth/juno/utils/jsonx"
"github.com/NethermindEth/juno/utils/log"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -206,7 +206,7 @@ func (c *Client) StateUpdate(ctx context.Context, blockID string) (*starknet.Sta
defer body.Close()

update := new(starknet.StateUpdate)
if err = json.NewDecoder(body).Decode(update); err != nil {
if err = jsonx.NewDecoder(body).Decode(update); err != nil {
return nil, err
}
return update, nil
Expand All @@ -228,7 +228,7 @@ func (c *Client) Transaction(
defer body.Close()

txStatus := new(starknet.DeprecatedTransactionStatus)
if err = json.NewDecoder(body).Decode(txStatus); err != nil {
if err = jsonx.NewDecoder(body).Decode(txStatus); err != nil {
return nil, err
}
return txStatus, nil
Expand All @@ -251,7 +251,7 @@ func (c *Client) TransactionStatus(
defer body.Close()

txStatus := new(starknet.TransactionStatus)
if err = json.NewDecoder(body).Decode(txStatus); err != nil {
if err = jsonx.NewDecoder(body).Decode(txStatus); err != nil {
return nil, err
}
return txStatus, nil
Expand All @@ -269,7 +269,7 @@ func (c *Client) Block(ctx context.Context, blockID string) (*starknet.Block, er
defer body.Close()

block := new(starknet.Block)
if err = json.NewDecoder(body).Decode(block); err != nil {
if err = jsonx.NewDecoder(body).Decode(block); err != nil {
return nil, err
}
return block, nil
Expand All @@ -290,7 +290,7 @@ func (c *Client) BlockHeader(
defer body.Close()

header := starknet.BlockHeader{}
if err = json.NewDecoder(body).Decode(&header); err != nil {
if err = jsonx.NewDecoder(body).Decode(&header); err != nil {
return starknet.BlockHeader{}, err
}
return header, nil
Expand All @@ -309,7 +309,7 @@ func (c *Client) ClassDefinition(ctx context.Context, classHash *felt.Felt) (*st
defer body.Close()

class := new(starknet.ClassDefinition)
if err = json.NewDecoder(body).Decode(class); err != nil {
if err = jsonx.NewDecoder(body).Decode(class); err != nil {
return nil, err
}
return class, nil
Expand Down Expand Up @@ -340,7 +340,7 @@ func (c *Client) CasmClassDefinition(
}

class := new(starknet.CasmClass)
if err = json.Unmarshal(definition, class); err != nil {
if err = jsonx.Unmarshal(definition, class); err != nil {
return nil, err
}
return class, nil
Expand All @@ -356,7 +356,7 @@ func (c *Client) PublicKey(ctx context.Context) (*felt.Felt, error) {
defer body.Close()

var publicKey string // public key hex string
if err = json.NewDecoder(body).Decode(&publicKey); err != nil {
if err = jsonx.NewDecoder(body).Decode(&publicKey); err != nil {
return nil, err
}

Expand All @@ -375,7 +375,7 @@ func (c *Client) Signature(ctx context.Context, blockID string) (*starknet.Signa
defer body.Close()

signature := new(starknet.Signature)
if err := json.NewDecoder(body).Decode(signature); err != nil {
if err := jsonx.NewDecoder(body).Decode(signature); err != nil {
return nil, err
}

Expand All @@ -395,7 +395,7 @@ func (c *Client) StateUpdateWithBlock(ctx context.Context, blockID string) (*sta
defer body.Close()

stateUpdate := new(starknet.StateUpdateWithBlock)
if err := json.NewDecoder(body).Decode(stateUpdate); err != nil {
if err := jsonx.NewDecoder(body).Decode(stateUpdate); err != nil {
return nil, err
}

Expand All @@ -414,7 +414,7 @@ func (c *Client) BlockTrace(ctx context.Context, blockHash string) (*starknet.Bl
defer body.Close()

traces := new(starknet.BlockTrace)
if err = json.NewDecoder(body).Decode(traces); err != nil {
if err = jsonx.NewDecoder(body).Decode(traces); err != nil {
return nil, err
}
return traces, nil
Expand All @@ -432,7 +432,7 @@ func (c *Client) PreConfirmedBlock(ctx context.Context, blockNumber string) (*st
defer body.Close()

preConfirmedBlock := new(starknet.PreConfirmedBlock)
if err = json.NewDecoder(body).Decode(preConfirmedBlock); err != nil {
if err = jsonx.NewDecoder(body).Decode(preConfirmedBlock); err != nil {
return nil, err
}
return preConfirmedBlock, nil
Expand All @@ -447,7 +447,7 @@ func (c *Client) FeeTokenAddresses(ctx context.Context) (starknet.FeeTokenAddres
defer body.Close()

contractAddresses := new(starknet.FeeTokenAddresses)
if err = json.NewDecoder(body).Decode(contractAddresses); err != nil {
if err = jsonx.NewDecoder(body).Decode(contractAddresses); err != nil {
return starknet.FeeTokenAddresses{}, err
}
return *contractAddresses, nil
Expand Down
5 changes: 3 additions & 2 deletions clients/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

"github.com/NethermindEth/juno/utils/jsonx"
"github.com/NethermindEth/juno/utils/log"
)

Expand Down Expand Up @@ -91,7 +92,7 @@ func (c *Client) post(ctx context.Context, url string, data any) ([]byte, error)
var gatewayError Error
body, readErr := io.ReadAll(resp.Body)
if readErr == nil && len(body) > 0 {
if err := json.Unmarshal(body, &gatewayError); err == nil {
if err := jsonx.Unmarshal(body, &gatewayError); err == nil {
if len(gatewayError.Code) != 0 {
return nil, &gatewayError
}
Expand All @@ -107,7 +108,7 @@ func (c *Client) post(ctx context.Context, url string, data any) ([]byte, error)
// doPost performs a "POST" http request with the given URL and a JSON payload derived from the provided data
// it returns response without additional error handling
func (c *Client) doPost(ctx context.Context, url string, data any) (*http.Response, error) {
jsonBody, err := json.Marshal(data)
jsonBody, err := jsonx.Marshal(data)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/class_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ package core
import "C"

import (
"encoding/json"
"errors"
"unsafe"

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/starknet"
"github.com/NethermindEth/juno/utils"
"github.com/NethermindEth/juno/utils/jsonx"
)

func deprecatedCairoClassHash(class *DeprecatedCairoClass) (felt.Felt, error) {
Expand All @@ -25,7 +25,7 @@ func deprecatedCairoClassHash(class *DeprecatedCairoClass) (felt.Felt, error) {
return felt.Felt{}, err
}

classJSON, err := json.Marshal(definition)
classJSON, err := jsonx.Marshal(definition)
if err != nil {
return felt.Felt{}, err
}
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/VictoriaMetrics/fastcache v1.13.3
github.com/bits-and-blooms/bitset v1.24.4
github.com/bits-and-blooms/bloom/v3 v3.7.1
github.com/bytedance/sonic v1.15.0
github.com/cockroachdb/pebble v1.1.5
github.com/cockroachdb/pebble/v2 v2.1.4
github.com/coder/websocket v1.8.14
Expand Down Expand Up @@ -50,9 +51,12 @@ require (
github.com/RaduBerinde/btreemap v0.0.0-20260105202824-d3184786f603 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic/loader v0.5.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/clipperhouse/displaywidth v0.10.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/cockroachdb/crlib v0.0.0-20251122031428-fe658a2dbda1 // indirect
github.com/cockroachdb/errors v1.12.0 // indirect
github.com/cockroachdb/fifo v0.0.0-20240816210425-c5d0cb0b6fc0 // indirect
Expand Down Expand Up @@ -172,6 +176,7 @@ require (
github.com/supranational/blst v0.3.16 // indirect
github.com/tklauser/go-sysconf v0.3.16 // indirect
github.com/tklauser/numcpus v0.11.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand All @@ -185,6 +190,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/mod v0.34.0 // indirect
golang.org/x/net v0.52.0 // indirect
golang.org/x/sys v0.43.0 // indirect
Expand Down
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ github.com/bits-and-blooms/bitset v1.24.4/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6
github.com/bits-and-blooms/bloom/v3 v3.7.1 h1:WXovk4TRKZttAMJfoQx6K2DM0zNIt8w+c67UqO+etV0=
github.com/bits-and-blooms/bloom/v3 v3.7.1/go.mod h1:rZzYLLje2dfzXfAkJNxQQHsKurAyK55KUnL43Euk0hU=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE=
github.com/bytedance/sonic v1.15.0/go.mod h1:tFkWrPz0/CUCLEF4ri4UkHekCIcdnkqXw9VduqpJh0k=
github.com/bytedance/sonic/loader v0.5.0 h1:gXH3KVnatgY7loH5/TkeVyXPfESoqSBSBEiDd5VjlgE=
github.com/bytedance/sonic/loader v0.5.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
github.com/canonical/go-sp800.90a-drbg v0.0.0-20210314144037-6eeb1040d6c3 h1:oe6fCvaEpkhyW3qAicT0TnGtyht/UrgvOwMcEgLb7Aw=
github.com/canonical/go-sp800.90a-drbg v0.0.0-20210314144037-6eeb1040d6c3/go.mod h1:qdP0gaj0QtgX2RUZhnlVrceJ+Qln8aSlDyJwelLLFeM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand All @@ -91,6 +97,8 @@ github.com/clipperhouse/displaywidth v0.10.0 h1:GhBG8WuerxjFQQYeuZAeVTuyxuX+Urai
github.com/clipperhouse/displaywidth v0.10.0/go.mod h1:XqJajYsaiEwkxOj4bowCTMcT1SgvHo9flfF3jQasdbs=
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down Expand Up @@ -634,12 +642,19 @@ github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
Expand All @@ -653,6 +668,8 @@ github.com/tklauser/go-sysconf v0.3.16 h1:frioLaCQSsF5Cy1jgRBrzr6t502KIIwQ0MArYI
github.com/tklauser/go-sysconf v0.3.16/go.mod h1:/qNL9xxDhc7tx3HSRsLWNnuzbVfh3e7gh/BmM179nYI=
github.com/tklauser/numcpus v0.11.0 h1:nSTwhKH5e1dMNsCdVBukSZrURJRoHbSEQjdEbY+9RXw=
github.com/tklauser/numcpus v0.11.0/go.mod h1:z+LwcLq54uWZTX0u/bGobaV34u6V7KNlTZejzM6/3MQ=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/twmb/murmur3 v1.1.8 h1:8Yt9taO/WN3l08xErzjeschgZU2QSrwm1kclYq+0aRg=
github.com/twmb/murmur3 v1.1.8/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk=
Expand Down Expand Up @@ -720,6 +737,8 @@ go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
Loading
Loading