Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing depositTxWithNonce case to MarshalJSON / SourceHash / Mint #395

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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