From 0b3283a030f2da3f83f7056a64b3de858bf06238 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Fri, 11 Jul 2025 14:44:16 +0900 Subject: [PATCH] add copy method for block access list --- core/types/bal/bal_encoding.go | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/core/types/bal/bal_encoding.go b/core/types/bal/bal_encoding.go index 77e5b7fe80..31fcd81901 100644 --- a/core/types/bal/bal_encoding.go +++ b/core/types/bal/bal_encoding.go @@ -198,6 +198,52 @@ func (e *AccountAccess) validate() error { return nil } +// Copy returns a deep copy of the account access +func (e *AccountAccess) Copy() AccountAccess { + res := AccountAccess{ + Address: e.Address, + } + + for _, storageWrite := range e.StorageWrites { + cpy := encodingSlotWrites{ + Slot: storageWrite.Slot, + Accesses: slices.Clone(storageWrite.Accesses), + } + for _, slotWrite := range storageWrite.Accesses { + cpy.Accesses = append(cpy.Accesses, encodingStorageWrite{ + TxIdx: slotWrite.TxIdx, + ValueAfter: slotWrite.ValueAfter, + }) + } + res.StorageWrites = append(res.StorageWrites, cpy) + } + + res.StorageReads = slices.Clone(e.StorageReads) + + for _, balanceChange := range e.BalanceChanges { + res.BalanceChanges = append(res.BalanceChanges, encodingBalanceChange{ + TxIdx: balanceChange.TxIdx, + Balance: balanceChange.Balance, + }) + } + + for _, nonceChange := range e.NonceChanges { + res.NonceChanges = append(res.NonceChanges, encodingAccountNonce{ + TxIdx: nonceChange.TxIdx, + Nonce: nonceChange.Nonce, + }) + } + if len(e.Code) == 1 { + res.Code = []CodeChange{ + { + e.Code[0].TxIndex, + bytes.Clone(e.Code[0].Code), + }, + } + } + return res +} + // EncodeRLP returns the RLP-encoded access list func (b *ConstructionBlockAccessList) EncodeRLP(wr io.Writer) error { return b.toEncodingObj().EncodeRLP(wr) @@ -332,3 +378,11 @@ func (e *BlockAccessList) PrettyPrint() string { } return res.String() } + +// Copy returns a deep copy of the access list +func (e *BlockAccessList) Copy() (res BlockAccessList) { + for _, accountAccess := range e.Accesses { + res.Accesses = append(res.Accesses, accountAccess.Copy()) + } + return +}