package Ġorg . ke thereum . rpc Ċ Ċ import Ġcom . squareup . mos hi . Json Adapter Ċ import Ġcom . squareup . mos hi . M oshi Ċ import Ġokhttp 3 . MediaType Ċ import Ġokhttp 3 . Ok HttpClient Ċ import Ġokhttp 3 . Request Ċ import Ġokhttp 3 . RequestBody Ċ import Ġorg . ke thereum . rpc . model . BigInteger Adapter Ċ import Ġorg . ke thereum . rpc . model . Block Information Response Ċ import Ġorg . ke thereum . rpc . model . Block Number Response ĊĊ Ċ val ĠJSON MediaType : ĠMediaType Ġ= ĠMediaType . parse (" application / json ") !! Ċ Ċ class ĠEthereum RPC ( val Ġbase URL : ĠString , Ġprivate Ġval Ġokhttp : ĠOk HttpClient Ġ= ĠOk HttpClient (). newBuilder (). build ()) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġm oshi Ġ= ĠM oshi . Builder (). build (). newBuilder (). add ( BigInteger Adapter ()). build () ĊĊĠĠĠ Ġprivate Ġval Ġblock Number Adapter : ĠJson Adapter < Block Number Response > Ġ= Ġm oshi . adapter ( Block Number Response :: class . java ) ĊĊĠĠĠ Ġprivate Ġval Ġblock Info Adapter : ĠJson Adapter < Block Information Response > Ġ= Ġm oshi . adapter ( Block Information Response :: class . java ) ĊĊĠĠĠ Ġprivate Ġfun Ġbuild Block Request () Ġ= Ġbuild Request ( RequestBody . create ( JSON MediaType , Ġ"{\" jsonrpc \":\" 2 . 0 \",\" method \":\" eth _ block Number \",\" params \": [], \" id \": 1 } ")) ĊĊĠĠĠ Ġprivate Ġfun Ġbuild Block By Number Request ( number : ĠString ) Ġ= Ġbuild Request ( RequestBody . create ( JSON MediaType , Ġ""" {" jsonrpc ":" 2 . 0 "," method ":" eth _ getBlock By Number "," params ":[" $ number ", Ġtrue ]," id ": 1 }} "" ")) ĊĊĠĠĠ Ġprivate Ġfun Ġbuild Request ( body : ĠRequest Body ) Ġ= ĠRequest . Builder (). url ( base URL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. method (" POST ", Ġbody ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () !! ĊĊĠĠĠ Ġfun Ġget Block Number String () Ġ= Ġokhttp . new Call ( build Block Request ()). execute (). body (). use Ġ{ Ġbody Ġ-> ĊĠĠĠĠĠĠĠ Ġbody ?. source ()?. use Ġ{ Ġblock Number Adapter . fromJson ( it ) Ġ} ĊĠĠĠ Ġ} ?. result ĊĊĠĠĠ Ġfun Ġget Block By Number ( number : ĠString ) Ġ= Ġokhttp . new Call ( build Block By Number Request ( number )). execute (). body (). use Ġ{ Ġbody Ġ-> ĊĠĠĠĠĠĠĠ Ġbody ?. source ()?. use Ġ{ Ġblock Info Adapter . fromJson ( it ) Ġ} ĊĠĠĠ Ġ} ?. result ?. to Block Information () Ċ Ċ }