diff --git a/beacon_chain/libnimbus_lc/libnimbus_lc.nim b/beacon_chain/libnimbus_lc/libnimbus_lc.nim index aa154cc46f..2e5fae6b48 100644 --- a/beacon_chain/libnimbus_lc/libnimbus_lc.nim +++ b/beacon_chain/libnimbus_lc/libnimbus_lc.nim @@ -15,7 +15,6 @@ import eth/p2p/discoveryv5/random2, eth/rlp, eth/trie/ordered_trie, - json_rpc/jsonmarshal, secp256k1, web3/[engine_api_types, eth_api_types, conversions], ../el/engine_api_conversions, @@ -1215,10 +1214,10 @@ proc ETHExecutionBlockHeaderCreateFromJson( ## See: ## * https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbyhash let data = try: - # a direct parameter like JrpcConv.decode($blockHeaderJson, BlockObject) + # a direct parameter like EthJson.decode($blockHeaderJson, BlockObject) # will cause premature garbage collector kick in. let jsonBytes = $blockHeaderJson - JrpcConv.decode(jsonBytes, BlockObject) + EthJson.decode(jsonBytes, BlockObject) except SerializationError: return nil if data == nil: @@ -1474,10 +1473,10 @@ proc ETHTransactionsCreateFromJson( ## See: ## * https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbyhash var datas = try: - # a direct parameter like JrpcConv.decode($transactionsJson, seq[TransactionObject]) + # a direct parameter like EthJson.decode($transactionsJson, seq[TransactionObject]) # will cause premature garbage collector kick in. let jsonBytes = $transactionsJson - JrpcConv.decode(jsonBytes, seq[TransactionObject]) + EthJson.decode(jsonBytes, seq[TransactionObject]) except SerializationError: return nil @@ -2283,10 +2282,10 @@ proc ETHReceiptsCreateFromJson( ## See: ## * https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt var datas = try: - # a direct parameter like JrpcConv.decode($receiptsJson, seq[ReceiptObject]) + # a direct parameter like EthJson.decode($receiptsJson, seq[ReceiptObject]) # will cause premature garbage collector kick in. let jsonBytes = $receiptsJson - JrpcConv.decode(jsonBytes, seq[ReceiptObject]) + EthJson.decode(jsonBytes, seq[ReceiptObject]) except SerializationError: return nil if datas.len != ETHTransactionsGetCount(transactions): diff --git a/ncli/ncli_testnet.nim b/ncli/ncli_testnet.nim index 4e1397f7e4..8fb968072b 100644 --- a/ncli/ncli_testnet.nim +++ b/ncli/ncli_testnet.nim @@ -11,7 +11,7 @@ import std/[json, options, times], chronos, bearssl/rand, chronicles, confutils, stint, json_serialization, web3, eth/common/keys, eth/p2p/discoveryv5/random2, - stew/[io2, byteutils], json_rpc/jsonmarshal, + stew/[io2, byteutils], ../beacon_chain/conf, ../beacon_chain/el/el_manager, ../beacon_chain/networking/eth2_network, @@ -399,7 +399,7 @@ proc doCreateTestnet*(config: CliConfig, try: let blockAsJson = genesisBlockContents.get - genesisBlock = JrpcConv.decode(blockAsJson, BlockObject) + genesisBlock = EthJson.decode(blockAsJson, BlockObject) except CatchableError as err: error "Failed to load the genesis block from json", err = err.msg diff --git a/research/fakeee.nim b/research/fakeee.nim index 33537b6065..29aef016f8 100644 --- a/research/fakeee.nim +++ b/research/fakeee.nim @@ -17,75 +17,76 @@ import chronicles proc setupEngineAPI*(server: RpcServer) = - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#engine_newpayloadv1 - # cannot use `params` as param name. see https:#github.com/status-im/nim-json-rpc/issues/128 - server.rpc("engine_newPayloadV1") do(payload: ExecutionPayloadV1) -> PayloadStatusV1: - info "engine_newPayloadV1", - number = $(distinctBase payload.blockNumber), hash = payload.blockHash - - return PayloadStatusV1( - status: PayloadExecutionStatus.syncing, - ) - - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#engine_newpayloadv2 - server.rpc("engine_newPayloadV2") do(payload: ExecutionPayloadV2) -> PayloadStatusV1: - info "engine_newPayloadV2", payload - - return PayloadStatusV1( - status: PayloadExecutionStatus.syncing, - ) - - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#engine_getpayloadv1 - server.rpc("engine_getPayloadV1") do(payloadId: Bytes8) -> ExecutionPayloadV1: - info "engine_getPayloadV1", - id = payloadId.toHex - - raise (ref ApplicationError)( - code: engineApiUnknownPayload, - msg: "Unknown payload" - ) - - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#engine_forkchoiceupdatedv1 - server.rpc("engine_forkchoiceUpdatedV1") do( - update: ForkchoiceStateV1, - payloadAttributes: Opt[PayloadAttributesV1]) -> ForkchoiceUpdatedResponse: - info "engine_forkchoiceUpdatedV1", - update, - payloadAttributes - - return ForkchoiceUpdatedResponse( - payloadStatus: PayloadStatusV1( - status: PayloadExecutionStatus.syncing)) - - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#engine_forkchoiceupdatedv2 - server.rpc("engine_forkchoiceUpdatedV2") do( - forkchoiceState: ForkchoiceStateV1, payloadAttributes: Opt[PayloadAttributesV2]) -> ForkchoiceUpdatedResponse: - info "engine_forkchoiceUpdatedV2", - forkchoiceState, payloadAttributes - - return ForkchoiceUpdatedResponse( - payloadStatus: PayloadStatusV1( - status: PayloadExecutionStatus.syncing)) - - server.rpc("eth_getBlockByNumber") do( - quantityTag: string, fullTransactions: bool) -> JsonString: - info "eth_getBlockByNumber", quantityTag, fullTransactions - - return if quantityTag == "latest": - 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.Quantity) - - server.rpc("eth_chainId") do() -> UInt256: - info "eth_chainId" - - return 1.u256 + server.rpc(EthJson): + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#engine_newpayloadv1 + # cannot use `params` as param name. see https:#github.com/status-im/nim-json-rpc/issues/128 + proc engine_newPayloadV1(payload: ExecutionPayloadV1): PayloadStatusV1 = + info "engine_newPayloadV1", + number = $(distinctBase payload.blockNumber), hash = payload.blockHash + + return PayloadStatusV1( + status: PayloadExecutionStatus.syncing, + ) + + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#engine_newpayloadv2 + proc engine_newPayloadV2(payload: ExecutionPayloadV2): PayloadStatusV1 = + info "engine_newPayloadV2", payload + + return PayloadStatusV1( + status: PayloadExecutionStatus.syncing, + ) + + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#engine_getpayloadv1 + proc engine_getPayloadV1(payloadId: Bytes8): ExecutionPayloadV1 = + info "engine_getPayloadV1", + id = payloadId.toHex + + raise (ref ApplicationError)( + code: engineApiUnknownPayload, + msg: "Unknown payload" + ) + + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#engine_forkchoiceupdatedv1 + proc engine_forkchoiceUpdatedV1( + update: ForkchoiceStateV1, + payloadAttributes: Opt[PayloadAttributesV1]): ForkchoiceUpdatedResponse = + info "engine_forkchoiceUpdatedV1", + update, + payloadAttributes + + return ForkchoiceUpdatedResponse( + payloadStatus: PayloadStatusV1( + status: PayloadExecutionStatus.syncing)) + + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#engine_forkchoiceupdatedv2 + proc engine_forkchoiceUpdatedV2( + forkchoiceState: ForkchoiceStateV1, payloadAttributes: Opt[PayloadAttributesV2]): ForkchoiceUpdatedResponse = + info "engine_forkchoiceUpdatedV2", + forkchoiceState, payloadAttributes + + return ForkchoiceUpdatedResponse( + payloadStatus: PayloadStatusV1( + status: PayloadExecutionStatus.syncing)) + + proc eth_getBlockByNumber( + quantityTag: string, fullTransactions: bool): JsonString = + info "eth_getBlockByNumber", quantityTag, fullTransactions + + return if quantityTag == "latest": + EthJson.encode(BlockObject(number: 1000.Quantity)).JsonString + else: + "{}".JsonString + + proc eth_getBlockByHash( + data: string, fullTransactions: bool): BlockObject = + info "eth_getBlockByHash", data = toHex(data), fullTransactions + + return BlockObject(number: 1000.Quantity) + + proc eth_chainId(): UInt256 = + info "eth_chainId" + + return 1.u256 when isMainModule: let server = newRpcHttpServer( diff --git a/vendor/nim-json-rpc b/vendor/nim-json-rpc index 841d1c9fcc..1cf6c9ceb1 160000 --- a/vendor/nim-json-rpc +++ b/vendor/nim-json-rpc @@ -1 +1 @@ -Subproject commit 841d1c9fcc7ce7ebbd1f9a774cfdcd7470e5e976 +Subproject commit 1cf6c9ceb130efa3e5d4ae2650df37e65ce50055 diff --git a/vendor/nim-web3 b/vendor/nim-web3 index 6868584a2f..9fbb6c6eff 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit 6868584a2f473eb1da04d5a3a7270d8f6795acf0 +Subproject commit 9fbb6c6effe20cc66c893a961beee1a2d11e9ad5