@@ -17,10 +17,15 @@ import (
1717 "github.com/scroll-tech/da-codec/encoding/zstd"
1818)
1919
20- type DACodecV7 struct {}
20+ type DACodecV7 struct {
21+ forcedVersion * CodecVersion
22+ }
2123
2224// Version returns the codec version.
2325func (d * DACodecV7 ) Version () CodecVersion {
26+ if d .forcedVersion != nil {
27+ return * d .forcedVersion
28+ }
2429 return CodecV7
2530}
2631
@@ -86,7 +91,7 @@ func (d *DACodecV7) NewDABatch(batch *Batch) (DABatch, error) {
8691 return nil , fmt .Errorf ("failed to construct blob: %w" , err )
8792 }
8893
89- daBatch , err := newDABatchV7 (CodecV7 , batch .Index , blobVersionedHash , batch .ParentBatchHash , blob , blobBytes , challengeDigest )
94+ daBatch , err := newDABatchV7 (d . Version () , batch .Index , blobVersionedHash , batch .ParentBatchHash , blob , blobBytes , challengeDigest )
9095 if err != nil {
9196 return nil , fmt .Errorf ("failed to construct DABatch: %w" , err )
9297 }
@@ -115,7 +120,7 @@ func (d *DACodecV7) constructBlob(batch *Batch) (*kzg4844.Blob, common.Hash, []b
115120
116121 sizeSlice := encodeSize3Bytes (uint32 (len (payloadBytes )))
117122
118- blobBytes [blobEnvelopeV7OffsetVersion ] = uint8 (CodecV7 )
123+ blobBytes [blobEnvelopeV7OffsetVersion ] = uint8 (d . Version () )
119124 copy (blobBytes [blobEnvelopeV7OffsetByteSize :blobEnvelopeV7OffsetCompressedFlag ], sizeSlice )
120125 blobBytes [blobEnvelopeV7OffsetCompressedFlag ] = isCompressedFlag
121126 blobBytes = append (blobBytes , payloadBytes ... )
@@ -166,15 +171,15 @@ func (d *DACodecV7) NewDABatchFromBytes(data []byte) (DABatch, error) {
166171 return nil , fmt .Errorf ("failed to decode DA batch: %w" , err )
167172 }
168173
169- if daBatch .version != CodecV7 {
170- return nil , fmt .Errorf ("codec version mismatch: expected %d but found %d" , CodecV7 , daBatch .version )
174+ if daBatch .version != d . Version () {
175+ return nil , fmt .Errorf ("codec version mismatch: expected %d but found %d" , d . Version () , daBatch .version )
171176 }
172177
173178 return daBatch , nil
174179}
175180
176181func (d * DACodecV7 ) NewDABatchFromParams (batchIndex uint64 , blobVersionedHash , parentBatchHash common.Hash ) (DABatch , error ) {
177- return newDABatchV7 (CodecV7 , batchIndex , blobVersionedHash , parentBatchHash , nil , nil , common.Hash {})
182+ return newDABatchV7 (d . Version () , batchIndex , blobVersionedHash , parentBatchHash , nil , nil , common.Hash {})
178183}
179184
180185func (d * DACodecV7 ) DecodeDAChunksRawTx (_ [][]byte ) ([]* DAChunkRawTx , error ) {
@@ -186,8 +191,8 @@ func (d *DACodecV7) DecodeBlob(blob *kzg4844.Blob) (DABlobPayload, error) {
186191
187192 // read the blob envelope header
188193 version := rawBytes [blobEnvelopeV7OffsetVersion ]
189- if CodecVersion (version ) != CodecV7 {
190- return nil , fmt .Errorf ("codec version mismatch: expected %d but found %d" , CodecV7 , version )
194+ if CodecVersion (version ) != d . Version () {
195+ return nil , fmt .Errorf ("codec version mismatch: expected %d but found %d" , d . Version () , version )
191196 }
192197
193198 // read the data size
0 commit comments