diff --git a/cmd/rpcdaemon/commands/zkevm_api.go b/cmd/rpcdaemon/commands/zkevm_api.go index 877677b7a63..87ad94d6e00 100644 --- a/cmd/rpcdaemon/commands/zkevm_api.go +++ b/cmd/rpcdaemon/commands/zkevm_api.go @@ -475,7 +475,25 @@ func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, batchNumber rpc.B // txs hashes := make([]types.TransactionOrHash, len(bbj.Transactions)) for i, txn := range bbj.Transactions { - // TODO: add transactionl2hash + + blkTx := blk.Transactions()[i] + l2TxHash, err := zktx.ComputeL2TxHash( + blkTx.GetChainID().ToBig(), + blkTx.GetValue(), + blkTx.GetPrice(), + blkTx.GetNonce(), + blkTx.GetGas(), + blkTx.GetTo(), + &txn.Tx.From, + blkTx.GetData(), + ) + if err != nil { + return nil, err + } + + txn.Tx.L2Hash = l2TxHash + txn.Tx.Receipt.TransactionL2Hash = l2TxHash + batchTransactionsJson = append(batchTransactionsJson, txn) txn.Hash = &txn.Tx.Hash txn.Tx = nil @@ -485,8 +503,6 @@ func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, batchNumber rpc.B // after collecting transactions, reduce them to them hash only on the block bbj.Transactions = hashes - // TODO: add l2hash - batchBlocksJson = append(batchBlocksJson, batchBlockExtra) } @@ -616,12 +632,11 @@ func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, batchNumber rpc.B } batch.BatchL2Data = batchL2Data - // currently gives 'error execution reverted' when calling the L1 - //oaih, err := api.l1Syncer.GetOldAccInputHash(ctx, &api.config.AddressRollup, ApiRollupId, bn+1) - //if err != nil { - // return nil, err - //} - //batch.AccInputHash = oaih + oldAccInputHash, err := api.l1Syncer.GetOldAccInputHash(ctx, &api.config.AddressRollup, ApiRollupId, batchNo) + if err != nil { + return nil, err + } + batch.AccInputHash = oldAccInputHash return populateBatchDetails(batch) } diff --git a/zk/rpcdaemon/types.go b/zk/rpcdaemon/types.go index eebbde96400..afe8f420bce 100644 --- a/zk/rpcdaemon/types.go +++ b/zk/rpcdaemon/types.go @@ -407,6 +407,7 @@ type Transaction struct { ChainID ArgBig `json:"chainId"` Type ArgUint64 `json:"type"` Receipt *Receipt `json:"receipt,omitempty"` + L2Hash common.Hash `json:"l2Hash,omitempty"` } // GetSender gets the sender from the transaction's signature @@ -482,6 +483,7 @@ type Receipt struct { ContractAddress *common.Address `json:"contractAddress"` Type ArgUint64 `json:"type"` EffectiveGasPrice *ArgBig `json:"effectiveGasPrice,omitempty"` + TransactionL2Hash common.Hash `json:"transactionL2Hash,omitempty"` } // NewReceipt creates a new Receipt instance