@@ -17,6 +17,7 @@ import io.iohk.ethereum.jsonrpc.FilterManager.{FilterChanges, FilterLogs, LogFil
1717import io .iohk .ethereum .jsonrpc .JsonRpcController .JsonRpcConfig
1818import io .iohk .ethereum .keystore .KeyStore
1919import io .iohk .ethereum .ledger .{InMemoryWorldStateProxy , Ledger , StxLedger }
20+ import io .iohk .ethereum .mpt .MerklePatriciaTrie .MissingNodeException
2021import io .iohk .ethereum .ommers .OmmersPool
2122import io .iohk .ethereum .rlp
2223import io .iohk .ethereum .rlp .RLPImplicitConversions ._
@@ -226,7 +227,7 @@ class EthService(
226227
227228 private [this ] def ifEthash [Req , Res ](req : Req )(f : Req => Res ): ServiceResponse [Res ] = {
228229 @ inline def F [A ](x : A ): Future [A ] = Future .successful(x)
229- consensus.ifEthash[ServiceResponse [Res ]](_ => F (Right (f(req))))(F (Left (JsonRpcErrors .ConsensusIsNotEthash )))
230+ consensus.ifEthash[ServiceResponse [Res ]](_ => F (Right (f(req))))(F (Left (JsonRpcError .ConsensusIsNotEthash )))
230231 }
231232
232233 def protocolVersion (req : ProtocolVersionRequest ): ServiceResponse [ProtocolVersionResponse ] =
@@ -557,7 +558,7 @@ class EthService(
557558 )
558559 }
559560 response
560- })(Future .successful(Left (JsonRpcErrors .ConsensusIsNotEthash )))
561+ })(Future .successful(Left (JsonRpcError .ConsensusIsNotEthash )))
561562
562563 private def getOmmersFromPool (parentBlockHash : ByteString ): Future [OmmersPool .Ommers ] =
563564 consensus.ifEthash(ethash => {
@@ -602,7 +603,7 @@ class EthService(
602603 Right (SubmitWorkResponse (false ))
603604 }
604605 }
605- })(Future .successful(Left (JsonRpcErrors .ConsensusIsNotEthash )))
606+ })(Future .successful(Left (JsonRpcError .ConsensusIsNotEthash )))
606607
607608 /**
608609 * Implements the eth_syncing method that returns syncing information if the node is syncing.
@@ -637,10 +638,10 @@ class EthService(
637638 pendingTransactionsManager ! PendingTransactionsManager .AddOrOverrideTransaction (signedTransaction)
638639 Future .successful(Right (SendRawTransactionResponse (signedTransaction.hash)))
639640 } else {
640- Future .successful(Left (JsonRpcErrors .InvalidRequest ))
641+ Future .successful(Left (JsonRpcError .InvalidRequest ))
641642 }
642643 case Failure (_) =>
643- Future .successful(Left (JsonRpcErrors .InvalidRequest ))
644+ Future .successful(Left (JsonRpcError .InvalidRequest ))
644645 }
645646 }
646647
@@ -657,7 +658,7 @@ class EthService(
657658 val dataEither = (tx.function, tx.contractCode) match {
658659 case (Some (function), None ) => Right (rlp.encode(RLPList (function, args)))
659660 case (None , Some (contractCode)) => Right (rlp.encode(RLPList (contractCode, args)))
660- case _ => Left (JsonRpcErrors .InvalidParams (" Iele transaction should contain either functionName or contractCode" ))
661+ case _ => Left (JsonRpcError .InvalidParams (" Iele transaction should contain either functionName or contractCode" ))
661662 }
662663
663664 dataEither match {
@@ -710,7 +711,7 @@ class EthService(
710711 Right (GetUncleCountByBlockHashResponse (blockBody.uncleNodesList.size))
711712 case None =>
712713 Left (
713- JsonRpcErrors .InvalidParams (s " Block with hash ${Hex .toHexString(req.blockHash.toArray[Byte ])} not found " )
714+ JsonRpcError .InvalidParams (s " Block with hash ${Hex .toHexString(req.blockHash.toArray[Byte ])} not found " )
714715 )
715716 }
716717 }
@@ -774,31 +775,22 @@ class EthService(
774775 .flatMap(_ => Right (None ))
775776 }
776777
777- def getBalance (req : GetBalanceRequest ): ServiceResponse [GetBalanceResponse ] = {
778- Future {
779- withAccount(req.address, req.block) { account =>
780- GetBalanceResponse (account.balance)
781- }
778+ def getBalance (req : GetBalanceRequest ): ServiceResponse [GetBalanceResponse ] =
779+ withAccount(req.address, req.block) { account =>
780+ GetBalanceResponse (account.balance)
782781 }
783- }
784782
785- def getStorageAt (req : GetStorageAtRequest ): ServiceResponse [GetStorageAtResponse ] = {
786- Future {
787- withAccount(req.address, req.block) { account =>
788- GetStorageAtResponse (
789- blockchain.getAccountStorageAt(account.storageRoot, req.position, blockchainConfig.ethCompatibleStorage)
790- )
791- }
783+ def getStorageAt (req : GetStorageAtRequest ): ServiceResponse [GetStorageAtResponse ] =
784+ withAccount(req.address, req.block) { account =>
785+ GetStorageAtResponse (
786+ blockchain.getAccountStorageAt(account.storageRoot, req.position, blockchainConfig.ethCompatibleStorage)
787+ )
792788 }
793- }
794789
795- def getTransactionCount (req : GetTransactionCountRequest ): ServiceResponse [GetTransactionCountResponse ] = {
796- Future {
797- withAccount(req.address, req.block) { account =>
798- GetTransactionCountResponse (account.nonce)
799- }
790+ def getTransactionCount (req : GetTransactionCountRequest ): ServiceResponse [GetTransactionCountResponse ] =
791+ withAccount(req.address, req.block) { account =>
792+ GetTransactionCountResponse (account.nonce)
800793 }
801- }
802794
803795 def newFilter (req : NewFilterRequest ): ServiceResponse [NewFilterResponse ] = {
804796 implicit val timeout : Timeout = Timeout (filterConfig.filterManagerQueryTimeout)
@@ -863,20 +855,25 @@ class EthService(
863855 }
864856 }
865857
866- private def withAccount [T ](address : Address , blockParam : BlockParam )(f : Account => T ): Either [JsonRpcError , T ] = {
867- resolveBlock(blockParam).map { case ResolvedBlock (block, _) =>
868- f(
869- blockchain.getAccount(address, block.header.number).getOrElse(Account .empty(blockchainConfig.accountStartNonce))
870- )
858+ private def withAccount [T ](address : Address , blockParam : BlockParam )(makeResponse : Account => T ): ServiceResponse [T ] =
859+ Future {
860+ resolveBlock(blockParam)
861+ .map { case ResolvedBlock (block, _) =>
862+ blockchain
863+ .getAccount(address, block.header.number)
864+ .getOrElse(Account .empty(blockchainConfig.accountStartNonce))
865+ }
866+ .map(makeResponse)
867+ }.recover { case _ : MissingNodeException =>
868+ Left (JsonRpcError .NodeNotFound )
871869 }
872- }
873870
874871 private def resolveBlock (blockParam : BlockParam ): Either [JsonRpcError , ResolvedBlock ] = {
875872 def getBlock (number : BigInt ): Either [JsonRpcError , Block ] = {
876873 blockchain
877874 .getBlockByNumber(number)
878875 .map(Right .apply)
879- .getOrElse(Left (JsonRpcErrors .InvalidParams (s " Block $number not found " )))
876+ .getOrElse(Left (JsonRpcError .InvalidParams (s " Block $number not found " )))
880877 }
881878
882879 blockParam match {
@@ -929,7 +926,7 @@ class EthService(
929926 if (numBlocksToSearch > jsonRpcConfig.accountTransactionsMaxBlocks) {
930927 Future .successful(
931928 Left (
932- JsonRpcErrors .InvalidParams (
929+ JsonRpcError .InvalidParams (
933930 s """ Maximum number of blocks to search is ${jsonRpcConfig.accountTransactionsMaxBlocks}, requested: $numBlocksToSearch.
934931 |See: 'network.rpc.account-transactions-max-blocks' config. """ .stripMargin
935932 )
@@ -963,13 +960,10 @@ class EthService(
963960 }
964961 }
965962
966- def getStorageRoot (req : GetStorageRootRequest ): ServiceResponse [GetStorageRootResponse ] = {
967- Future {
968- withAccount(req.address, req.block) { account =>
969- GetStorageRootResponse (account.storageRoot)
970- }
963+ def getStorageRoot (req : GetStorageRootRequest ): ServiceResponse [GetStorageRootResponse ] =
964+ withAccount(req.address, req.block) { account =>
965+ GetStorageRootResponse (account.storageRoot)
971966 }
972- }
973967
974968 /**
975969 * Returns the transactions that are pending in the transaction pool and have a from address that is one of the accounts this node manages.
0 commit comments