Skip to content

Commit

Permalink
fix deprecated warnings (#6606)
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran authored Oct 8, 2024
1 parent 5d11c52 commit 3f37caa
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion beacon_chain/el/deposit_contract.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import
chronos, chronicles, confutils, stint, json_serialization,
../filepath,
../networking/network_metadata,
web3, web3/confutils_defs, eth/keys, eth/p2p/discoveryv5/random2,
web3, web3/confutils_defs, eth/common/keys, eth/p2p/discoveryv5/random2,
stew/[io2, byteutils],
../spec/eth2_merkleization,
../spec/datatypes/base,
Expand Down
20 changes: 10 additions & 10 deletions beacon_chain/el/engine_api_conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV1):
gas_limit: rpcExecutionPayload.gasLimit.uint64,
gas_used: rpcExecutionPayload.gasUsed.uint64,
timestamp: rpcExecutionPayload.timestamp.uint64,
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.bytes),
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.data),
base_fee_per_gas: rpcExecutionPayload.baseFeePerGas,
block_hash: rpcExecutionPayload.blockHash.asEth2Digest,
transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init(
Expand Down Expand Up @@ -88,7 +88,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV1OrV2|ExecutionPaylo
gas_limit: rpcExecutionPayload.gasLimit.uint64,
gas_used: rpcExecutionPayload.gasUsed.uint64,
timestamp: rpcExecutionPayload.timestamp.uint64,
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.bytes),
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.data),
base_fee_per_gas: rpcExecutionPayload.baseFeePerGas,
block_hash: rpcExecutionPayload.blockHash.asEth2Digest,
transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init(
Expand Down Expand Up @@ -119,7 +119,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV3):
gas_limit: rpcExecutionPayload.gasLimit.uint64,
gas_used: rpcExecutionPayload.gasUsed.uint64,
timestamp: rpcExecutionPayload.timestamp.uint64,
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.bytes),
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(rpcExecutionPayload.extraData.data),
base_fee_per_gas: rpcExecutionPayload.baseFeePerGas,
block_hash: rpcExecutionPayload.blockHash.asEth2Digest,
transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init(
Expand All @@ -141,12 +141,12 @@ func asConsensusType*(payload: engine_api.GetPayloadV3Response):
blobsBundle: deneb.BlobsBundle(
commitments: KzgCommitments.init(
payload.blobsBundle.commitments.mapIt(
kzg_abi.KzgCommitment(bytes: it.bytes))),
kzg_abi.KzgCommitment(bytes: it.data))),
proofs: KzgProofs.init(
payload.blobsBundle.proofs.mapIt(
kzg_abi.KzgProof(bytes: it.bytes))),
kzg_abi.KzgProof(bytes: it.data))),
blobs: Blobs.init(
payload.blobsBundle.blobs.mapIt(it.bytes))))
payload.blobsBundle.blobs.mapIt(it.data))))

func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4):
electra.ExecutionPayload =
Expand Down Expand Up @@ -189,7 +189,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4):
gas_used: rpcExecutionPayload.gasUsed.uint64,
timestamp: rpcExecutionPayload.timestamp.uint64,
extra_data: List[byte, MAX_EXTRA_DATA_BYTES].init(
rpcExecutionPayload.extraData.bytes),
rpcExecutionPayload.extraData.data),
base_fee_per_gas: rpcExecutionPayload.baseFeePerGas,
block_hash: rpcExecutionPayload.blockHash.asEth2Digest,
transactions: List[bellatrix.Transaction, MAX_TRANSACTIONS_PER_PAYLOAD].init(
Expand All @@ -211,12 +211,12 @@ func asConsensusType*(payload: engine_api.GetPayloadV4Response):
blobsBundle: deneb.BlobsBundle(
commitments: KzgCommitments.init(
payload.blobsBundle.commitments.mapIt(
kzg_abi.KzgCommitment(bytes: it.bytes))),
kzg_abi.KzgCommitment(bytes: it.data))),
proofs: KzgProofs.init(
payload.blobsBundle.proofs.mapIt(
kzg_abi.KzgProof(bytes: it.bytes))),
kzg_abi.KzgProof(bytes: it.data))),
blobs: Blobs.init(
payload.blobsBundle.blobs.mapIt(it.bytes))))
payload.blobsBundle.blobs.mapIt(it.data))))

func asEngineExecutionPayload*(blockBody: bellatrix.BeaconBlockBody):
ExecutionPayloadV1 =
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/el/eth1_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ template toGaugeValue*(x: Quantity | BlockNumber): int64 =
toGaugeValue(distinctBase x)

type
Eth1BlockNumber* = BlockNumber
Eth1BlockNumber* = Quantity
Eth1BlockTimestamp* = uint64

Eth1BlockObj* = object
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/networking/network_metadata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const
incbinEnabled* = sizeof(pointer) == 8

type
Eth1BlockHash* = web3types.BlockHash
Eth1BlockHash* = web3types.Hash32

Eth1Network* = enum
mainnet
Expand Down
18 changes: 9 additions & 9 deletions beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export
json_serialization, net, sets, rest_types, slashing_protection_common,
jsonSerializationResults, rest_keymanager_types

from web3/primitives import BlockHash, BlockNumber
export primitives.BlockHash, primitives.BlockNumber
from web3/primitives import Hash32, Quantity
export primitives.Hash32, primitives.Quantity

func decodeMediaType*(
contentType: Opt[ContentTypeData]): Result[MediaType, string] =
Expand Down Expand Up @@ -995,14 +995,14 @@ proc readValue*(reader: var JsonReader[RestJson], value: var uint8) {.
else:
reader.raiseUnexpectedValue($res.error() & ": " & svalue)

## BlockNumber
## BlockNumber/Quantity
proc writeValue*(
w: var JsonWriter[RestJson], value: BlockNumber) {.raises: [IOError].} =
w: var JsonWriter[RestJson], value: Quantity) {.raises: [IOError].} =
w.writeValue(distinctBase(value))

proc readValue*(
reader: var JsonReader[RestJson],
value: var BlockNumber) {.raises: [IOError, SerializationError].} =
value: var Quantity) {.raises: [IOError, SerializationError].} =
reader.readValue(distinctBase(value))

## RestNumeric
Expand Down Expand Up @@ -1272,17 +1272,17 @@ proc writeValue*(
writer: var JsonWriter[RestJson], value: BitArray) {.raises: [IOError].} =
writeValue(writer, hexOriginal(value.bytes))

## BlockHash
proc readValue*(reader: var JsonReader[RestJson], value: var BlockHash) {.
## BlockHash/Hash32
proc readValue*(reader: var JsonReader[RestJson], value: var Hash32) {.
raises: [IOError, SerializationError].} =
try:
hexToByteArray(reader.readValue(string), distinctBase(value))
except ValueError:
raiseUnexpectedValue(reader,
"BlockHash value should be a valid hex string")
"Hash32 value should be a valid hex string")

proc writeValue*(
writer: var JsonWriter[RestJson], value: BlockHash) {.raises: [IOError].} =
writer: var JsonWriter[RestJson], value: Hash32) {.raises: [IOError].} =
writeValue(writer, hexOriginal(distinctBase(value)))

## Eth2Digest
Expand Down
8 changes: 4 additions & 4 deletions beacon_chain/spec/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func toGwei*(eth: Ether): Gwei =
distinctBase(eth) * ETH_TO_GWEI

type
ExecutionHash256* = eth_types.Hash256
ExecutionHash256* = eth_types.Hash32
ExecutionTransaction* = eth_types.Transaction
ExecutionReceipt* = eth_types.Receipt
ExecutionWithdrawal* = eth_types.Withdrawal
ExecutionDepositRequest* = eth_types.DepositRequest
ExecutionWithdrawalRequest* = eth_types.WithdrawalRequest
ExecutionConsolidationRequest* = eth_types.ConsolidationRequest
ExecutionBlockHeader* = eth_types.BlockHeader
ExecutionBlockHeader* = eth_types.Header

FinalityCheckpoints* = object
justified*: Checkpoint
Expand Down Expand Up @@ -592,15 +592,15 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader =
stateRoot : payload.state_root.to(Root),
transactionsRoot : txRoot,
receiptsRoot : payload.receipts_root.to(Root),
logsBloom : BloomFilter payload.logs_bloom.data.to(Bloom),
logsBloom : Bloom payload.logs_bloom.data.to(Bloom),
difficulty : default(DifficultyInt),
number : payload.block_number,
gasLimit : payload.gas_limit,
gasUsed : payload.gas_used,
timestamp : EthTime(payload.timestamp),
extraData : payload.extra_data.asSeq,
mixHash : Bytes32 payload.prev_randao.data, # EIP-4399 `mixHash` -> `prevRandao`
nonce : default(BlockNonce),
nonce : default(Bytes8),
baseFeePerGas : Opt.some payload.base_fee_per_gas,
withdrawalsRoot : withdrawalsRoot,
blobGasUsed : blobGasUsed, # EIP-4844
Expand Down
8 changes: 4 additions & 4 deletions beacon_chain/spec/presets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type

# Transition
TERMINAL_TOTAL_DIFFICULTY*: UInt256
TERMINAL_BLOCK_HASH*: BlockHash
TERMINAL_BLOCK_HASH*: Hash32
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH*: Epoch # Not actively used, but part of the spec

# Genesis
Expand Down Expand Up @@ -164,7 +164,7 @@ when const_preset == "mainnet":
TERMINAL_TOTAL_DIFFICULTY:
u256"115792089237316195423570985008687907853269984665640564039457584007913129638912",
# By default, don't use these params
TERMINAL_BLOCK_HASH: BlockHash.fromHex(
TERMINAL_BLOCK_HASH: Hash32.fromHex(
"0x0000000000000000000000000000000000000000000000000000000000000000"),

# Genesis
Expand Down Expand Up @@ -643,8 +643,8 @@ template parse(T: type string, input: string): T =
template parse(T: type Eth1Address, input: string): T =
Eth1Address.fromHex(input)

template parse(T: type BlockHash, input: string): T =
BlockHash.fromHex(input)
template parse(T: type Hash32, input: string): T =
Hash32.fromHex(input)

template parse(T: type UInt256, input: string): T =
parse(input, UInt256, 10)
Expand Down
4 changes: 2 additions & 2 deletions research/fakeee.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ proc setupEngineAPI*(server: RpcServer) =
info "eth_getBlockByNumber", quantityTag, fullTransactions

return if quantityTag == "latest":
JrpcConv.encode(BlockObject(number: 1000.BlockNumber)).JsonString
JrpcConv.encode(BlockObject(number: 1000.Quantity)).JsonString
else:
"{}".JsonString

server.rpc("eth_getBlockByHash") do(
data: string, fullTransactions: bool) -> BlockObject:
info "eth_getBlockByHash", data = toHex(data), fullTransactions

return BlockObject(number: 1000.BlockNumber)
return BlockObject(number: 1000.Quantity)

server.rpc("eth_chainId") do() -> Quantity:
info "eth_chainId"
Expand Down

0 comments on commit 3f37caa

Please sign in to comment.