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

fix receipt json marshaling/unmarshaling #167

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
92 changes: 50 additions & 42 deletions core/types/gen_receipt_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ type receiptMarshaling struct {
BlockNumber *hexutil.Big
TransactionIndex hexutil.Uint

// Optimism: extend receipts with their L1 price (if a rollup tx)
L1GasPrice *hexutil.Big
L1GasUsed *hexutil.Big
L1Fee *hexutil.Big
FeeScalar *big.Float
// Optimism
L1GasPrice *hexutil.Big
L1GasUsed *hexutil.Big
L1Fee *hexutil.Big
FeeScalar *big.Float
DepositNonce *hexutil.Uint64
DepositReceiptVersion *hexutil.Uint64
}

// receiptRLP is the consensus encoding of a receipt.
Expand Down
12 changes: 12 additions & 0 deletions core/types/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,18 @@ func TestReceiptJSON(t *testing.T) {
if err != nil {
t.Fatal("error unmarshaling receipt from json:", err)
}

// Make sure marshal/unmarshal doesn't affect receipt hash root computation by comparing
// the output of EncodeIndex
rsBefore := Receipts([]*Receipt{receipts[i]})
rsAfter := Receipts([]*Receipt{&r})

encBefore, encAfter := bytes.Buffer{}, bytes.Buffer{}
rsBefore.EncodeIndex(0, &encBefore)
rsAfter.EncodeIndex(0, &encAfter)
if !bytes.Equal(encBefore.Bytes(), encAfter.Bytes()) {
t.Errorf("%v: EncodeIndex differs after JSON marshal/unmarshal", i)
}
}
}

Expand Down