Skip to content

Commit

Permalink
[CGKIELE-107] mallet - PR review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtkaczyk committed Apr 27, 2018
1 parent 81f1d70 commit 3da9694
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ scalacOptions := Seq(
"-unchecked",
"-deprecation",
"-feature",
"-Xfatal-warnings",
"-Xlint:unsound-match",
"-Ywarn-inaccessible",
"-Ywarn-unused-import",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ object Commands {
}
}

val helpHeader = "fetch the receipt for a know transaction hash"
val helpHeader = "fetch the receipt for a known transaction hash"
val helpDetail =
"""|Shows the receipt of a transaction given its [hash]. The transaction must be already mined on the blockchain
""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package io.iohk.ethereum.mallet.main
import io.iohk.ethereum.mallet.service.PasswordReader

/**
* This implementation of [[PasswordReader]] is in non-interactive mode when the password is
* provided as a command line option
* This implementation of [[io.iohk.ethereum.mallet.service.PasswordReader PasswordReader]] is used in
* non-interactive mode when the password is provided as a command line option
*/
class ConstPasswordReader(password: String) extends PasswordReader {
def readPassword(): Option[String] =
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/io/iohk/ethereum/mallet/main/Mallet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Mallet extends App {
private val initialState = {
new State(
shell,
new RpcClient(clOptions.node),
RpcClient(clOptions.node),
new KeyStoreImpl(clOptions.dataDir, new SecureRandom()),
clOptions.account,
None,
Expand All @@ -35,7 +35,7 @@ object Mallet extends App {
val result = Interpreter(cmd, state)
shell.printLine(result.msg)

RpcClient.actorSystem.terminate()
state.rpcClient.shutdown()
val exitCode = if (result.error) 1 else 0
sys.exit(exitCode)
}
Expand All @@ -51,7 +51,7 @@ object Mallet extends App {
loop(result.state)

case None =>
RpcClient.actorSystem.terminate()
state.rpcClient.shutdown()
}
}

Expand Down
31 changes: 21 additions & 10 deletions src/main/scala/io/iohk/ethereum/mallet/service/RpcClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,41 @@ import io.iohk.ethereum.jsonrpc.{JsonRpcError, TransactionReceiptResponse}
import io.iohk.ethereum.mallet.common.{Constants, Err, RpcClientError, Util}

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

object RpcClient {
// TODO: CL option to enable akka logging
private val akkaConfig = ConfigFactory.load("mallet")

implicit val actorSystem = ActorSystem("mallet_rpc", akkaConfig)
implicit val materializer = ActorMaterializer()
/**
* This factory method is defining an ActorSystem, ActorMaterializer and ExecutionContext for
* the [[RpcClient]]. To customize these dependencies use [[RpcClient]]'s constructor
*/
def apply(node: Uri): RpcClient = {
// TODO: CL option to enable akka logging
val akkaConfig = ConfigFactory.load("mallet")

implicit val system = ActorSystem("mallet_rpc", akkaConfig)
implicit val mat = ActorMaterializer()
implicit val ec = scala.concurrent.ExecutionContext.Implicits.global

new RpcClient(node)
}
}

/**
* Talks to a node over HTTP(S) JSON-RPC
* Note: the URI schema determins whether HTTP or HTTPS is used
* Note: the URI schema determines whether HTTP or HTTPS is used
*/
class RpcClient(node: Uri) {
class RpcClient(node: Uri)(implicit system: ActorSystem, mat: ActorMaterializer, ec: ExecutionContext) {
import CommonJsonCodecs._
import RpcClient._
import actorSystem.dispatcher


//TODO: CL option
private val httpTimeout = 5.seconds

def shutdown(): Unit = {
Await.ready(system.terminate(), 5.seconds)
}

def sendTransaction(rawTx: ByteString): Either[Err, ByteString] =
doRequest[ByteString]("eth_sendRawTransaction", List(rawTx.asJson))

Expand Down

0 comments on commit 3da9694

Please sign in to comment.