|
6 | 6 | "fmt" |
7 | 7 | "math/big" |
8 | 8 |
|
| 9 | + "github.com/scroll-tech/da-codec/encoding" |
| 10 | + |
9 | 11 | "github.com/scroll-tech/go-ethereum" |
10 | 12 | "github.com/scroll-tech/go-ethereum/accounts/abi" |
11 | 13 | "github.com/scroll-tech/go-ethereum/common" |
@@ -97,7 +99,7 @@ func (r *Reader) FinalizedL1MessageQueueIndex(blockNumber uint64) (uint64, error |
97 | 99 | return next - 1, nil |
98 | 100 | } |
99 | 101 |
|
100 | | -func (r *Reader) LatestFinalizedBatch(blockNumber uint64) (uint64, error) { |
| 102 | +func (r *Reader) LatestFinalizedBatchIndex(blockNumber uint64) (uint64, error) { |
101 | 103 | data, err := r.scrollChainABI.Pack(lastFinalizedBatchIndex) |
102 | 104 | if err != nil { |
103 | 105 | return 0, fmt.Errorf("failed to pack %s: %w", lastFinalizedBatchIndex, err) |
@@ -398,6 +400,28 @@ func (r *Reader) FetchCommitTxData(commitEvent *CommitBatchEvent) (*CommitBatchA |
398 | 400 | if err != nil { |
399 | 401 | return nil, fmt.Errorf("failed to decode calldata into commitBatch args %s, values: %+v, err: %w", commitBatchesV7MethodName, values, err) |
400 | 402 | } |
| 403 | + } else if method.Name == commitAndFinalizeBatch { |
| 404 | + commitAndFinalizeArgs, err := newCommitAndFinalizeBatchArgs(method, values) |
| 405 | + if err != nil { |
| 406 | + return nil, fmt.Errorf("failed to decode calldata into commitAndFinalizeBatch args %s, values: %+v, err: %w", commitAndFinalizeBatch, values, err) |
| 407 | + } |
| 408 | + |
| 409 | + // in commitAndFinalizeBatch, the last batch hash is encoded in the finalize struct as this is the only batch we're |
| 410 | + // committing when calling this function. |
| 411 | + codec, err := encoding.CodecFromVersion(encoding.CodecVersion(commitAndFinalizeArgs.Version)) |
| 412 | + if err != nil { |
| 413 | + return nil, fmt.Errorf("failed to get codec from version %d, err: %w", commitAndFinalizeArgs.Version, err) |
| 414 | + } |
| 415 | + daBatch, err := codec.NewDABatchFromBytes(commitAndFinalizeArgs.FinalizeStruct.BatchHeader) |
| 416 | + if err != nil { |
| 417 | + return nil, fmt.Errorf("failed to decode daBatch from bytes, err: %w", err) |
| 418 | + } |
| 419 | + |
| 420 | + args = &CommitBatchArgs{ |
| 421 | + Version: commitAndFinalizeArgs.Version, |
| 422 | + ParentBatchHash: commitAndFinalizeArgs.ParentBatchHash, |
| 423 | + LastBatchHash: daBatch.Hash(), |
| 424 | + } |
401 | 425 | } else { |
402 | 426 | return nil, fmt.Errorf("unknown method name for commit transaction: %s", method.Name) |
403 | 427 | } |
|
0 commit comments