Skip to content

Commit

Permalink
Add missing depositTxWithNonce case to MarshalJSON / SourceHash / Mint (
Browse files Browse the repository at this point in the history
ethereum-optimism#395)

Also add depositTxWithNonce cases to Transaction.SourceHash and Transaction.Mint functions
  • Loading branch information
mdehoog authored Oct 9, 2024
1 parent d5a9661 commit 9eb6114
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,23 @@ func (tx *Transaction) To() *common.Address {
// e.g. a user deposit event, or a L1 info deposit included in a specific L2 block height.
// Non-deposit transactions return a zeroed hash.
func (tx *Transaction) SourceHash() common.Hash {
if dep, ok := tx.inner.(*DepositTx); ok {
return dep.SourceHash
switch tx.inner.(type) {
case *DepositTx:
return tx.inner.(*DepositTx).SourceHash
case *depositTxWithNonce:
return tx.inner.(*depositTxWithNonce).SourceHash
}
return common.Hash{}
}

// Mint returns the ETH to mint in the deposit tx.
// This returns nil if there is nothing to mint, or if this is not a deposit tx.
func (tx *Transaction) Mint() *big.Int {
if dep, ok := tx.inner.(*DepositTx); ok {
return dep.Mint
switch tx.inner.(type) {
case *DepositTx:
return tx.inner.(*DepositTx).Mint
case *depositTxWithNonce:
return tx.inner.(*depositTxWithNonce).Mint
}
return nil
}
Expand Down
14 changes: 14 additions & 0 deletions core/types/transaction_marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
}
enc.IsSystemTx = &itx.IsSystemTransaction
// other fields will show up as null.

case *depositTxWithNonce:
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
enc.Value = (*hexutil.Big)(itx.Value)
enc.Input = (*hexutil.Bytes)(&itx.Data)
enc.To = tx.To()
enc.SourceHash = &itx.SourceHash
enc.From = &itx.From
if itx.Mint != nil {
enc.Mint = (*hexutil.Big)(itx.Mint)
}
enc.IsSystemTx = &itx.IsSystemTransaction
enc.Nonce = (*hexutil.Uint64)(&itx.EffectiveNonce)
// other fields will show up as null.
}
return json.Marshal(&enc)
}
Expand Down

0 comments on commit 9eb6114

Please sign in to comment.