Skip to content

Commit 3da9694

Browse files
committed
[CGKIELE-107] mallet - PR review fixes
1 parent 81f1d70 commit 3da9694

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ scalacOptions := Seq(
9696
"-unchecked",
9797
"-deprecation",
9898
"-feature",
99+
"-Xfatal-warnings",
99100
"-Xlint:unsound-match",
100101
"-Ywarn-inaccessible",
101102
"-Ywarn-unused-import",

src/main/scala/io/iohk/ethereum/mallet/interpreter/Commands.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ object Commands {
244244
}
245245
}
246246

247-
val helpHeader = "fetch the receipt for a know transaction hash"
247+
val helpHeader = "fetch the receipt for a known transaction hash"
248248
val helpDetail =
249249
"""|Shows the receipt of a transaction given its [hash]. The transaction must be already mined on the blockchain
250250
""".stripMargin

src/main/scala/io/iohk/ethereum/mallet/main/ConstPasswordReader.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package io.iohk.ethereum.mallet.main
33
import io.iohk.ethereum.mallet.service.PasswordReader
44

55
/**
6-
* This implementation of [[PasswordReader]] is in non-interactive mode when the password is
7-
* provided as a command line option
6+
* This implementation of [[io.iohk.ethereum.mallet.service.PasswordReader PasswordReader]] is used in
7+
* non-interactive mode when the password is provided as a command line option
88
*/
99
class ConstPasswordReader(password: String) extends PasswordReader {
1010
def readPassword(): Option[String] =

src/main/scala/io/iohk/ethereum/mallet/main/Mallet.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Mallet extends App {
2222
private val initialState = {
2323
new State(
2424
shell,
25-
new RpcClient(clOptions.node),
25+
RpcClient(clOptions.node),
2626
new KeyStoreImpl(clOptions.dataDir, new SecureRandom()),
2727
clOptions.account,
2828
None,
@@ -35,7 +35,7 @@ object Mallet extends App {
3535
val result = Interpreter(cmd, state)
3636
shell.printLine(result.msg)
3737

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

5353
case None =>
54-
RpcClient.actorSystem.terminate()
54+
state.rpcClient.shutdown()
5555
}
5656
}
5757

src/main/scala/io/iohk/ethereum/mallet/service/RpcClient.scala

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,41 @@ import io.iohk.ethereum.jsonrpc.{JsonRpcError, TransactionReceiptResponse}
1818
import io.iohk.ethereum.mallet.common.{Constants, Err, RpcClientError, Util}
1919

2020
import scala.concurrent.duration._
21-
import scala.concurrent.{Await, Future}
21+
import scala.concurrent.{Await, ExecutionContext, Future}
2222
import scala.util.{Failure, Success, Try}
2323

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

28-
implicit val actorSystem = ActorSystem("mallet_rpc", akkaConfig)
29-
implicit val materializer = ActorMaterializer()
26+
/**
27+
* This factory method is defining an ActorSystem, ActorMaterializer and ExecutionContext for
28+
* the [[RpcClient]]. To customize these dependencies use [[RpcClient]]'s constructor
29+
*/
30+
def apply(node: Uri): RpcClient = {
31+
// TODO: CL option to enable akka logging
32+
val akkaConfig = ConfigFactory.load("mallet")
33+
34+
implicit val system = ActorSystem("mallet_rpc", akkaConfig)
35+
implicit val mat = ActorMaterializer()
36+
implicit val ec = scala.concurrent.ExecutionContext.Implicits.global
37+
38+
new RpcClient(node)
39+
}
3040
}
3141

3242
/**
3343
* Talks to a node over HTTP(S) JSON-RPC
34-
* Note: the URI schema determins whether HTTP or HTTPS is used
44+
* Note: the URI schema determines whether HTTP or HTTPS is used
3545
*/
36-
class RpcClient(node: Uri) {
46+
class RpcClient(node: Uri)(implicit system: ActorSystem, mat: ActorMaterializer, ec: ExecutionContext) {
3747
import CommonJsonCodecs._
38-
import RpcClient._
39-
import actorSystem.dispatcher
40-
4148

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

52+
def shutdown(): Unit = {
53+
Await.ready(system.terminate(), 5.seconds)
54+
}
55+
4556
def sendTransaction(rawTx: ByteString): Either[Err, ByteString] =
4657
doRequest[ByteString]("eth_sendRawTransaction", List(rawTx.asJson))
4758

0 commit comments

Comments
 (0)