From 6e2fcf6d6cef6d22099d5315741fec446dc7a6c8 Mon Sep 17 00:00:00 2001 From: Theodoros Kasampalis Date: Tue, 24 Aug 2021 16:55:12 -0500 Subject: [PATCH] adding a new RPC end point to access blockhashes --- vm/ieleApi.ml | 4 ++++ vm/ieleApi.mli | 1 + vm/ieleApiClient.ml | 1 + 3 files changed, 6 insertions(+) diff --git a/vm/ieleApi.ml b/vm/ieleApi.ml index 1df52e90f..7366da821 100644 --- a/vm/ieleApi.ml +++ b/vm/ieleApi.ml @@ -74,6 +74,10 @@ let get_account_field address blocknumber field convert default = let eth_getCode address blocknumber = `String (get_account_field address blocknumber "code" to_string "0x") +let eth_getBlockhash offset = + let hash = IeleClientUtils.InMemoryWorldState.get_blockhash (int_of_string offset) in + `String (to_hex_unsigned hash) + let eth_getBlockByNumber blocknumber = let block = get_block blocknumber in `Assoc [("timestamp", `String block.timestamp)] diff --git a/vm/ieleApi.mli b/vm/ieleApi.mli index 4c3e4cef5..2def9b043 100644 --- a/vm/ieleApi.mli +++ b/vm/ieleApi.mli @@ -1,6 +1,7 @@ open Yojson.Basic val eth_getCode : string -> string -> json +val eth_getBlockhash : string -> json val eth_getBlockByNumber : string -> json val eth_getTransactionReceipt : string -> json val iele_sendTransaction : json -> json diff --git a/vm/ieleApiClient.ml b/vm/ieleApiClient.ml index e5a2e1e7e..ce0a25783 100644 --- a/vm/ieleApiClient.ml +++ b/vm/ieleApiClient.ml @@ -20,6 +20,7 @@ let process_requests (_in,fd) = let params = request |> member "params" |> to_list in let response = match _method, params with | "eth_getCode", [`String address; `String number] -> eth_getCode address number + | "eth_getBlockhash", [`String offset] -> eth_getBlockhash offset | "eth_getBlockByNumber", [`String number; `Bool _] -> eth_getBlockByNumber number | "eth_getTransactionReceipt", [`String hash] -> eth_getTransactionReceipt hash | "iele_sendTransaction", [tx] -> iele_sendTransaction tx