@@ -11,6 +11,7 @@ import (
1111 "github.com/rs/zerolog"
1212
1313 "github.com/evstack/ev-node/core/da"
14+ dautils "github.com/evstack/ev-node/da"
1415 internal "github.com/evstack/ev-node/da/jsonrpc/internal"
1516)
1617
@@ -36,28 +37,10 @@ type API struct {
3637 }
3738}
3839
39- // prepareNamespace hex encodes the namespace and ensures result is exactly 29 bytes
40- func prepareNamespace (ns []byte ) []byte {
41- // Hex encode the namespace
42- encoded := hex .EncodeToString (ns )
43-
44- // Ensure the result is exactly 29 bytes
45- // If shorter, pad with zeros; if longer, truncate
46- if len (encoded ) < 29 {
47- // Pad with zeros on the right
48- encoded = encoded + strings .Repeat ("0" , 29 - len (encoded ))
49- } else if len (encoded ) > 29 {
50- // Truncate to 29 bytes
51- encoded = encoded [:29 ]
52- }
53-
54- return []byte (encoded )
55- }
56-
5740// Get returns Blob for each given ID, or an error.
5841func (api * API ) Get (ctx context.Context , ids []da.ID , ns []byte ) ([]da.Blob , error ) {
59- preparedNs := prepareNamespace (ns )
60- api .Logger .Debug ().Str ("method" , "Get" ).Int ("num_ids" , len (ids )).Str ("namespace" , string (preparedNs )).Msg ("Making RPC call" )
42+ preparedNs := dautils . PrepareNamespace (ns )
43+ api .Logger .Debug ().Str ("method" , "Get" ).Int ("num_ids" , len (ids )).Str ("namespace" , hex . EncodeToString (preparedNs )).Msg ("Making RPC call" )
6144 res , err := api .Internal .Get (ctx , ids , preparedNs )
6245 if err != nil {
6346 if strings .Contains (err .Error (), context .Canceled .Error ()) {
@@ -74,8 +57,8 @@ func (api *API) Get(ctx context.Context, ids []da.ID, ns []byte) ([]da.Blob, err
7457
7558// GetIDs returns IDs of all Blobs located in DA at given height.
7659func (api * API ) GetIDs (ctx context.Context , height uint64 , ns []byte ) (* da.GetIDsResult , error ) {
77- preparedNs := prepareNamespace (ns )
78- api .Logger .Debug ().Str ("method" , "GetIDs" ).Uint64 ("height" , height ).Str ("namespace" , string (preparedNs )).Msg ("Making RPC call" )
60+ preparedNs := dautils . PrepareNamespace (ns )
61+ api .Logger .Debug ().Str ("method" , "GetIDs" ).Uint64 ("height" , height ).Str ("namespace" , hex . EncodeToString (preparedNs )).Msg ("Making RPC call" )
7962 res , err := api .Internal .GetIDs (ctx , height , preparedNs )
8063 if err != nil {
8164 // Using strings.contains since JSON RPC serialization doesn't preserve error wrapping
@@ -108,8 +91,8 @@ func (api *API) GetIDs(ctx context.Context, height uint64, ns []byte) (*da.GetID
10891
10992// GetProofs returns inclusion Proofs for Blobs specified by their IDs.
11093func (api * API ) GetProofs (ctx context.Context , ids []da.ID , ns []byte ) ([]da.Proof , error ) {
111- preparedNs := prepareNamespace (ns )
112- api .Logger .Debug ().Str ("method" , "GetProofs" ).Int ("num_ids" , len (ids )).Str ("namespace" , string (preparedNs )).Msg ("Making RPC call" )
94+ preparedNs := dautils . PrepareNamespace (ns )
95+ api .Logger .Debug ().Str ("method" , "GetProofs" ).Int ("num_ids" , len (ids )).Str ("namespace" , hex . EncodeToString (preparedNs )).Msg ("Making RPC call" )
11396 res , err := api .Internal .GetProofs (ctx , ids , preparedNs )
11497 if err != nil {
11598 api .Logger .Error ().Err (err ).Str ("method" , "GetProofs" ).Msg ("RPC call failed" )
@@ -121,8 +104,8 @@ func (api *API) GetProofs(ctx context.Context, ids []da.ID, ns []byte) ([]da.Pro
121104
122105// Commit creates a Commitment for each given Blob.
123106func (api * API ) Commit (ctx context.Context , blobs []da.Blob , ns []byte ) ([]da.Commitment , error ) {
124- preparedNs := prepareNamespace (ns )
125- api .Logger .Debug ().Str ("method" , "Commit" ).Int ("num_blobs" , len (blobs )).Str ("namespace" , string (preparedNs )).Msg ("Making RPC call" )
107+ preparedNs := dautils . PrepareNamespace (ns )
108+ api .Logger .Debug ().Str ("method" , "Commit" ).Int ("num_blobs" , len (blobs )).Str ("namespace" , hex . EncodeToString (preparedNs )).Msg ("Making RPC call" )
126109 res , err := api .Internal .Commit (ctx , blobs , preparedNs )
127110 if err != nil {
128111 api .Logger .Error ().Err (err ).Str ("method" , "Commit" ).Msg ("RPC call failed" )
@@ -134,8 +117,8 @@ func (api *API) Commit(ctx context.Context, blobs []da.Blob, ns []byte) ([]da.Co
134117
135118// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
136119func (api * API ) Validate (ctx context.Context , ids []da.ID , proofs []da.Proof , ns []byte ) ([]bool , error ) {
137- preparedNs := prepareNamespace (ns )
138- api .Logger .Debug ().Str ("method" , "Validate" ).Int ("num_ids" , len (ids )).Int ("num_proofs" , len (proofs )).Str ("namespace" , string (preparedNs )).Msg ("Making RPC call" )
120+ preparedNs := dautils . PrepareNamespace (ns )
121+ api .Logger .Debug ().Str ("method" , "Validate" ).Int ("num_ids" , len (ids )).Int ("num_proofs" , len (proofs )).Str ("namespace" , hex . EncodeToString (preparedNs )).Msg ("Making RPC call" )
139122 res , err := api .Internal .Validate (ctx , ids , proofs , preparedNs )
140123 if err != nil {
141124 api .Logger .Error ().Err (err ).Str ("method" , "Validate" ).Msg ("RPC call failed" )
@@ -147,8 +130,8 @@ func (api *API) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, ns
147130
148131// Submit submits the Blobs to Data Availability layer.
149132func (api * API ) Submit (ctx context.Context , blobs []da.Blob , gasPrice float64 , ns []byte ) ([]da.ID , error ) {
150- preparedNs := prepareNamespace (ns )
151- api .Logger .Debug ().Str ("method" , "Submit" ).Int ("num_blobs" , len (blobs )).Float64 ("gas_price" , gasPrice ).Str ("namespace" , string (preparedNs )).Msg ("Making RPC call" )
133+ preparedNs := dautils . PrepareNamespace (ns )
134+ api .Logger .Debug ().Str ("method" , "Submit" ).Int ("num_blobs" , len (blobs )).Float64 ("gas_price" , gasPrice ).Str ("namespace" , hex . EncodeToString (preparedNs )).Msg ("Making RPC call" )
152135 res , err := api .Internal .Submit (ctx , blobs , gasPrice , preparedNs )
153136 if err != nil {
154137 if strings .Contains (err .Error (), context .Canceled .Error ()) {
@@ -188,8 +171,8 @@ func (api *API) SubmitWithOptions(ctx context.Context, inputBlobs []da.Blob, gas
188171 return nil , da .ErrBlobSizeOverLimit
189172 }
190173
191- preparedNs := prepareNamespace (ns )
192- api .Logger .Debug ().Str ("method" , "SubmitWithOptions" ).Int ("num_blobs" , len (inputBlobs )).Uint64 ("total_size" , totalSize ).Float64 ("gas_price" , gasPrice ).Str ("namespace" , string (preparedNs )).Msg ("Making RPC call" )
174+ preparedNs := dautils . PrepareNamespace (ns )
175+ api .Logger .Debug ().Str ("method" , "SubmitWithOptions" ).Int ("num_blobs" , len (inputBlobs )).Uint64 ("total_size" , totalSize ).Float64 ("gas_price" , gasPrice ).Str ("namespace" , hex . EncodeToString (preparedNs )).Msg ("Making RPC call" )
193176 res , err := api .Internal .SubmitWithOptions (ctx , inputBlobs , gasPrice , preparedNs , options )
194177 if err != nil {
195178 if strings .Contains (err .Error (), context .Canceled .Error ()) {
0 commit comments