diff --git a/premix/downloader.nim b/premix/downloader.nim index d5e9c739c..515a2da7d 100644 --- a/premix/downloader.nim +++ b/premix/downloader.nim @@ -120,12 +120,13 @@ proc requestBlock*( if DownloadReceipts in flags: result.receipts = requestReceipts(header, client) - let - receiptRoot = calcReceiptRoot(result.receipts).prefixHex - receiptRootOK = result.header.receiptRoot.prefixHex - if receiptRoot != receiptRootOK: - debug "wrong receipt root", receiptRoot, receiptRootOK, blockNumber - raise newException(ValueError, "Error when validating receipt root") + if DownloadAndValidate in flags: + let + receiptRoot = calcReceiptRoot(result.receipts).prefixHex + receiptRootOK = result.header.receiptRoot.prefixHex + if receiptRoot != receiptRootOK: + debug "wrong receipt root", receiptRoot, receiptRootOK, blockNumber + raise newException(ValueError, "Error when validating receipt root") if DownloadAndValidate in flags: let diff --git a/premix/parser.nim b/premix/parser.nim index ae4a192a7..ae92cb9f3 100644 --- a/premix/parser.nim +++ b/premix/parser.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2020-2023 Status Research & Development GmbH +# Copyright (c) 2020-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -15,6 +15,8 @@ import import ../nimbus/transaction, ../nimbus/utils/ec_recover +from stew/objects import checkedEnumAssign + template stripLeadingZeros(value: string): string = var cidx = 0 # ignore the last character so we retain '0' on zero value @@ -225,7 +227,15 @@ proc parseLogs(n: JsonNode): seq[Log] = result = @[] proc parseReceipt*(n: JsonNode): Receipt = - var rec = Receipt(receiptType: LegacyReceipt) + var recType: byte + n.fromJson "type", recType + var txVal: ReceiptType + var rec = + if checkedEnumAssign(txVal, recType): + Receipt(receiptType: txVal) + else: + raise newException(ValueError, "Unknown receipt type") + if n.hasKey("root"): var hash: Hash256 n.fromJson "root", hash