2022-02-11 16:28:39 +00:00
|
|
|
# Nimbus
|
2024-04-03 15:48:35 +00:00
|
|
|
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
2022-02-11 16:28:39 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
|
|
|
## Pretty printing, an alternative to `$` for debugging
|
|
|
|
## ----------------------------------------------------
|
|
|
|
|
|
|
|
import
|
2024-04-03 15:48:35 +00:00
|
|
|
std/[tables, typetraits],
|
2023-11-08 12:18:32 +00:00
|
|
|
eth/common,
|
|
|
|
stew/byteutils,
|
2022-12-02 04:39:12 +00:00
|
|
|
../../nimbus/common/chain_config,
|
2023-11-08 12:18:32 +00:00
|
|
|
./pp_light
|
2022-02-11 16:28:39 +00:00
|
|
|
|
2022-03-16 09:13:17 +00:00
|
|
|
export
|
|
|
|
pp_light
|
2022-02-11 16:28:39 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions, pretty printer
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-10-01 21:03:10 +00:00
|
|
|
func pp*(b: seq[byte]): string =
|
2023-11-08 12:18:32 +00:00
|
|
|
b.toHex.pp(hex = true)
|
2022-02-11 16:28:39 +00:00
|
|
|
|
2024-10-16 06:51:38 +00:00
|
|
|
func pp*(a: Address): string =
|
2023-11-08 12:18:32 +00:00
|
|
|
a.toHex[32 .. 39]
|
2022-02-11 16:28:39 +00:00
|
|
|
|
2024-10-16 06:51:38 +00:00
|
|
|
func pp*(a: Opt[Address]): string =
|
2024-04-03 15:48:35 +00:00
|
|
|
if a.isSome: a.unsafeGet.pp else: "n/a"
|
|
|
|
|
2024-10-16 06:51:38 +00:00
|
|
|
func pp*(a: openArray[Address]): string =
|
2022-03-31 08:21:36 +00:00
|
|
|
"[" & a.mapIt(it.pp).join(" ") & "]"
|
|
|
|
|
2024-10-03 11:42:24 +00:00
|
|
|
func pp*(a: Bytes8|Bytes32): string =
|
2023-11-08 12:18:32 +00:00
|
|
|
a.toHex
|
2022-02-11 16:28:39 +00:00
|
|
|
|
2024-04-03 15:48:35 +00:00
|
|
|
func pp*(a: NetworkPayload): string =
|
|
|
|
if a.isNil:
|
|
|
|
"n/a"
|
|
|
|
else:
|
|
|
|
"([#" & $a.blobs.len & "],[#" &
|
|
|
|
$a.commitments.len & "],[#" &
|
|
|
|
$a.proofs.len & "])"
|
|
|
|
|
2024-10-01 21:03:10 +00:00
|
|
|
func pp*(h: Header; sep = " "): string =
|
2022-02-11 16:28:39 +00:00
|
|
|
"" &
|
|
|
|
&"hash={h.blockHash.pp}{sep}" &
|
2024-06-14 07:31:08 +00:00
|
|
|
&"blockNumber={h.number}{sep}" &
|
2022-02-11 16:28:39 +00:00
|
|
|
&"parentHash={h.parentHash.pp}{sep}" &
|
|
|
|
&"coinbase={h.coinbase.pp}{sep}" &
|
|
|
|
&"gasLimit={h.gasLimit}{sep}" &
|
|
|
|
&"gasUsed={h.gasUsed}{sep}" &
|
2023-10-18 02:16:11 +00:00
|
|
|
&"timestamp={h.timestamp}{sep}" &
|
2022-02-11 16:28:39 +00:00
|
|
|
&"extraData={h.extraData.pp}{sep}" &
|
|
|
|
&"difficulty={h.difficulty}{sep}" &
|
2024-06-14 07:31:08 +00:00
|
|
|
&"mixHash={h.mixHash.pp}{sep}" &
|
2022-02-11 16:28:39 +00:00
|
|
|
&"nonce={h.nonce.pp}{sep}" &
|
|
|
|
&"ommersHash={h.ommersHash.pp}{sep}" &
|
|
|
|
&"txRoot={h.txRoot.pp}{sep}" &
|
2024-06-14 07:31:08 +00:00
|
|
|
&"receiptsRoot={h.receiptsRoot.pp}{sep}" &
|
2022-02-11 16:28:39 +00:00
|
|
|
&"stateRoot={h.stateRoot.pp}{sep}" &
|
2024-06-14 07:31:08 +00:00
|
|
|
&"baseFee={h.baseFeePerGas}{sep}" &
|
2024-08-01 10:41:20 +00:00
|
|
|
&"withdrawalsRoot={h.withdrawalsRoot.get(EMPTY_ROOT_HASH).pp}{sep}" &
|
2024-04-03 15:48:35 +00:00
|
|
|
&"blobGasUsed={h.blobGasUsed.get(0'u64)}{sep}" &
|
2023-08-04 12:43:30 +00:00
|
|
|
&"excessBlobGas={h.excessBlobGas.get(0'u64)}"
|
2022-02-11 16:28:39 +00:00
|
|
|
|
2024-04-03 15:48:35 +00:00
|
|
|
func pp*(g: Genesis; sep = " "): string =
|
2022-02-11 16:28:39 +00:00
|
|
|
"" &
|
|
|
|
&"nonce={g.nonce.pp}{sep}" &
|
2023-10-18 02:16:11 +00:00
|
|
|
&"timestamp={g.timestamp}{sep}" &
|
2022-02-11 16:28:39 +00:00
|
|
|
&"extraData={g.extraData.pp}{sep}" &
|
|
|
|
&"gasLimit={g.gasLimit}{sep}" &
|
|
|
|
&"difficulty={g.difficulty}{sep}" &
|
|
|
|
&"mixHash={g.mixHash.pp}{sep}" &
|
|
|
|
&"coinbase={g.coinbase.pp}{sep}" &
|
|
|
|
&"alloc=<{g.alloc.len} accounts>{sep}" &
|
|
|
|
&"number={g.number}{sep}" &
|
|
|
|
&"gasUser={g.gasUser}{sep}" &
|
|
|
|
&"parentHash={g.parentHash.pp}{sep}" &
|
|
|
|
&"baseFeePerGas={g.baseFeePerGas}"
|
|
|
|
|
2024-04-03 15:48:35 +00:00
|
|
|
func pp*(t: Transaction; sep = " "): string =
|
|
|
|
"" &
|
|
|
|
&"txType={t.txType}{sep}" &
|
|
|
|
&"chainId={t.chainId.distinctBase}{sep}" &
|
|
|
|
&"nonce={t.nonce}{sep}" &
|
|
|
|
&"gasPrice={t.gasPrice}{sep}" &
|
2024-06-14 07:31:08 +00:00
|
|
|
&"maxPriorityFee={t.maxPriorityFeePerGas}{sep}" &
|
|
|
|
&"maxFee={t.maxFeePerGas}{sep}" &
|
2024-04-03 15:48:35 +00:00
|
|
|
&"gasLimit={t.gasLimit}{sep}" &
|
|
|
|
&"to={t.to.pp}{sep}" &
|
|
|
|
&"value={t.value}{sep}" &
|
|
|
|
&"payload={t.payload.pp}{sep}" &
|
|
|
|
&"accessList=[#{t.accessList.len}]{sep}" &
|
|
|
|
&"maxFeePerBlobGas={t.maxFeePerBlobGas}{sep}" &
|
|
|
|
&"versionedHashes=[#{t.versionedHashes.len}]{sep}" &
|
|
|
|
&"V={t.V}{sep}" &
|
|
|
|
&"R={t.R}{sep}" &
|
|
|
|
&"S={t.S}{sep}"
|
2022-03-16 09:13:17 +00:00
|
|
|
|
2024-10-01 21:03:10 +00:00
|
|
|
proc pp*(h: Header; indent: int): string =
|
2022-02-11 16:28:39 +00:00
|
|
|
h.pp("\n" & " ".repeat(max(1,indent)))
|
|
|
|
|
|
|
|
proc pp*(g: Genesis; indent: int): string =
|
|
|
|
g.pp("\n" & " ".repeat(max(1,indent)))
|
|
|
|
|
2022-08-04 08:04:30 +00:00
|
|
|
proc pp*(a: Account): string =
|
|
|
|
&"({a.nonce},{a.balance},{a.storageRoot.pp},{a.codeHash.pp})"
|
|
|
|
|
2022-02-11 16:28:39 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|