|
|
|
|
@@ -1,7 +1,6 @@
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/binary"
|
|
|
|
|
"errors"
|
|
|
|
|
@@ -76,6 +75,14 @@ func GetBatchRangeFromCalldataV2(calldata []byte) (uint64, uint64, uint64, error
|
|
|
|
|
method := backendabi.ScrollChainV2ABI.Methods["commitBatch"]
|
|
|
|
|
values, err := method.Inputs.Unpack(calldata[4:])
|
|
|
|
|
if err != nil {
|
|
|
|
|
// special case: import genesis batch
|
|
|
|
|
method = backendabi.ScrollChainV2ABI.Methods["importGenesisBatch"]
|
|
|
|
|
_, err2 := method.Inputs.Unpack(calldata[4:])
|
|
|
|
|
if err2 == nil {
|
|
|
|
|
// genesis batch
|
|
|
|
|
return 0, 0, 0, nil
|
|
|
|
|
}
|
|
|
|
|
// none of "commitBatch" and "importGenesisBatch" match, give up
|
|
|
|
|
return 0, 0, 0, err
|
|
|
|
|
}
|
|
|
|
|
args := commitBatchArgs{}
|
|
|
|
|
@@ -110,48 +117,3 @@ func GetBatchRangeFromCalldataV2(calldata []byte) (uint64, uint64, uint64, error
|
|
|
|
|
|
|
|
|
|
return batchIndex, startBlock, finishBlock, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetBatchRangeFromCalldataV1 find the block range from calldata, both inclusive.
|
|
|
|
|
func GetBatchRangeFromCalldataV1(calldata []byte) ([]uint64, []uint64, []uint64, error) {
|
|
|
|
|
var batchIndices []uint64
|
|
|
|
|
var startBlocks []uint64
|
|
|
|
|
var finishBlocks []uint64
|
|
|
|
|
if bytes.Equal(calldata[0:4], common.Hex2Bytes("cb905499")) {
|
|
|
|
|
// commitBatches
|
|
|
|
|
method := backendabi.ScrollChainABI.Methods["commitBatches"]
|
|
|
|
|
values, err := method.Inputs.Unpack(calldata[4:])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return batchIndices, startBlocks, finishBlocks, err
|
|
|
|
|
}
|
|
|
|
|
args := make([]backendabi.IScrollChainBatch, len(values))
|
|
|
|
|
err = method.Inputs.Copy(&args, values)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return batchIndices, startBlocks, finishBlocks, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := 0; i < len(args); i++ {
|
|
|
|
|
batchIndices = append(batchIndices, args[i].BatchIndex)
|
|
|
|
|
startBlocks = append(startBlocks, args[i].Blocks[0].BlockNumber)
|
|
|
|
|
finishBlocks = append(finishBlocks, args[i].Blocks[len(args[i].Blocks)-1].BlockNumber)
|
|
|
|
|
}
|
|
|
|
|
} else if bytes.Equal(calldata[0:4], common.Hex2Bytes("8c73235d")) {
|
|
|
|
|
// commitBatch
|
|
|
|
|
method := backendabi.ScrollChainABI.Methods["commitBatch"]
|
|
|
|
|
values, err := method.Inputs.Unpack(calldata[4:])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return batchIndices, startBlocks, finishBlocks, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args := backendabi.IScrollChainBatch{}
|
|
|
|
|
err = method.Inputs.Copy(&args, values)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return batchIndices, startBlocks, finishBlocks, err
|
|
|
|
|
}
|
|
|
|
|
batchIndices = append(batchIndices, args.BatchIndex)
|
|
|
|
|
startBlocks = append(startBlocks, args.Blocks[0].BlockNumber)
|
|
|
|
|
finishBlocks = append(finishBlocks, args.Blocks[len(args.Blocks)-1].BlockNumber)
|
|
|
|
|
} else {
|
|
|
|
|
return batchIndices, startBlocks, finishBlocks, errors.New("invalid selector")
|
|
|
|
|
}
|
|
|
|
|
return batchIndices, startBlocks, finishBlocks, nil
|
|
|
|
|
}
|
|
|
|
|
|