Skip to content

Commit 272e9ad

Browse files
[ETCM-251] faucet healthcheck (#768)
* init refactor * add refactor from JsonRpcController * add refactor from JsonRpcController * change rpc fuacet * remove faucet api * change faucet config * fix test * change properties * add new endpoints from faucet * remove config from limit request * change name from JsonRpcBaseController * fix test * change faucet implicits * change monix task -- add now * remove configs from http * fix test * change test Co-authored-by: Piotr Paradziński <[email protected]>
1 parent 62c0014 commit 272e9ad

30 files changed

+731
-405
lines changed

insomnia_workspace.json

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"_type": "export",
33
"__export_format": 4,
4-
"__export_date": "2020-10-02T11:18:34.806Z",
5-
"__export_source": "insomnia.desktop.app:v2020.4.1",
4+
"__export_date": "2020-11-02T20:39:43.839Z",
5+
"__export_source": "insomnia.desktop.app:v2020.4.2",
66
"resources": [
77
{
88
"_id": "req_4222a4d54ba24fa7813429bdcdb732df",
@@ -90,6 +90,88 @@
9090
"settingFollowRedirects": "global",
9191
"_type": "request"
9292
},
93+
{
94+
"_id": "req_5c84aeff984d41e4aca173ac56a0b113",
95+
"parentId": "fld_9f9137459d5c429d83901f5c682be0f9",
96+
"modified": 1604346888565,
97+
"created": 1603997152827,
98+
"url": "{{ faucet_url }}",
99+
"name": "send_funds",
100+
"description": "",
101+
"method": "POST",
102+
"body":
103+
{
104+
"mimeType": "application/json",
105+
"text": "{\n\t\"jsonrpc\": \"2.0\",\n \"method\": \"faucet_sendFunds\", \n \"params\": [\"$address\"],\n \"id\": 1\n}"
106+
},
107+
"parameters": [],
108+
"headers":
109+
[
110+
{
111+
"name": "Content-Type",
112+
"value": "application/json",
113+
"description": "",
114+
"id": "pair_b080d7c5b5194ad09efdd6926ed108c5",
115+
"disabled": false
116+
}
117+
],
118+
"authentication": {},
119+
"metaSortKey": -1603997152827,
120+
"isPrivate": false,
121+
"settingStoreCookies": true,
122+
"settingSendCookies": true,
123+
"settingDisableRenderRequestBody": false,
124+
"settingEncodeUrl": true,
125+
"settingRebuildPath": true,
126+
"settingFollowRedirects": "global",
127+
"_type": "request"
128+
},
129+
{
130+
"_id": "fld_9f9137459d5c429d83901f5c682be0f9",
131+
"parentId": "wrk_097d43914a4d4aea8b6f73f647921182",
132+
"modified": 1604349428103,
133+
"created": 1603918083216,
134+
"name": "faucet",
135+
"description": "",
136+
"environment": {},
137+
"environmentPropertyOrder": null,
138+
"metaSortKey": -1552939140242,
139+
"_type": "request_group"
140+
},
141+
{
142+
"_id": "req_48316ba9ba834bcc94fdeae41d966eb9",
143+
"parentId": "fld_9f9137459d5c429d83901f5c682be0f9",
144+
"modified": 1604346774105,
145+
"created": 1604338553808,
146+
"url": "{{ faucet_url }}",
147+
"name": "status",
148+
"description": "",
149+
"method": "POST",
150+
"body":
151+
{
152+
"mimeType": "application/json",
153+
"text": "{\n\t\"jsonrpc\": \"2.0\",\n \"method\": \"faucet_status\", \n \"params\": [],\n \"id\": 1\n}"
154+
},
155+
"parameters": [],
156+
"headers":
157+
[
158+
{
159+
"name": "Content-Type",
160+
"value": "application/json",
161+
"id": "pair_bce95e5eaba54223bb10210f4563af71"
162+
}
163+
],
164+
"authentication": {},
165+
"metaSortKey": -1604338553809,
166+
"isPrivate": false,
167+
"settingStoreCookies": true,
168+
"settingSendCookies": true,
169+
"settingDisableRenderRequestBody": false,
170+
"settingEncodeUrl": true,
171+
"settingRebuildPath": true,
172+
"settingFollowRedirects": "global",
173+
"_type": "request"
174+
},
93175
{
94176
"_id": "req_cd0078ce4a034ebdbdf7dc9e20e78a29",
95177
"parentId": "fld_2b54cbb84e244284b3ef752c5f805376",
@@ -1203,15 +1285,20 @@
12031285
{
12041286
"_id": "env_2e1a8d7b5f3649308cb3c524e84a3f33",
12051287
"parentId": "env_ee4c8118750744559d3b1020845fe5d4",
1206-
"modified": 1599825641645,
1288+
"modified": 1604347516298,
12071289
"created": 1552663140073,
12081290
"name": "Develop",
1209-
"data": {
1210-
"node_url": "http://127.0.0.1:8546"
1291+
"data":
1292+
{
1293+
"node_url": "http://127.0.0.1:8546",
1294+
"faucet_url": "http://127.0.0.1:8547"
12111295
},
1212-
"dataPropertyOrder": {
1213-
"&": [
1214-
"node_url"
1296+
"dataPropertyOrder":
1297+
{
1298+
"&":
1299+
[
1300+
"node_url",
1301+
"faucet_url"
12151302
]
12161303
},
12171304
"color": null,
Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
11
package io.iohk.ethereum.faucet
22

3-
import java.security.SecureRandom
4-
5-
import akka.actor.ActorSystem
6-
import akka.http.scaladsl.Http
7-
import com.typesafe.config.ConfigFactory
8-
import io.iohk.ethereum.keystore.KeyStoreImpl
9-
import io.iohk.ethereum.mallet.service.RpcClient
10-
import io.iohk.ethereum.utils.{KeyStoreConfig, Logger}
11-
12-
import scala.concurrent.ExecutionContext.Implicits.global
13-
import scala.util.{Failure, Success}
3+
import io.iohk.ethereum.faucet.jsonrpc.FaucetServer
4+
import io.iohk.ethereum.utils.Logger
145

156
object Faucet extends Logger {
167

178
def main(args: Array[String]): Unit = {
18-
val config = FaucetConfig(ConfigFactory.load())
19-
20-
implicit val system = ActorSystem("Faucet-system")
21-
22-
val keyStore = new KeyStoreImpl(KeyStoreConfig.customKeyStoreConfig(config.keyStoreDir), new SecureRandom())
23-
val rpcClient = new RpcClient(config.rpcAddress)
24-
val api = new FaucetApi(rpcClient, keyStore, config)
25-
26-
val bindingResultF = Http().newServerAt(config.listenInterface, config.listenPort).bind(api.route)
279

28-
bindingResultF onComplete {
29-
case Success(serverBinding) => log.info(s"Faucet HTTP server listening on ${serverBinding.localAddress}")
30-
case Failure(ex) => log.error("Cannot start faucet HTTP server", ex)
31-
}
10+
(new FaucetServer).start()
3211
}
3312

3413
}

src/main/scala/io/iohk/ethereum/faucet/FaucetApi.scala

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,40 @@
11
package io.iohk.ethereum.faucet
22

3-
import ch.megard.akka.http.cors.scaladsl.model.HttpOriginMatcher
4-
import com.typesafe.config.{Config => TypesafeConfig}
3+
import com.typesafe.config.{ConfigFactory, Config => TypesafeConfig}
54
import io.iohk.ethereum.domain.Address
6-
import io.iohk.ethereum.utils.ConfigUtils
5+
76
import scala.concurrent.duration.{FiniteDuration, _}
87

8+
trait FaucetConfigBuilder {
9+
lazy val rawConfig: TypesafeConfig = ConfigFactory.load()
10+
lazy val rawMantisConfig: TypesafeConfig = rawConfig.getConfig("mantis")
11+
lazy val faucetConfig: FaucetConfig = FaucetConfig(rawConfig)
12+
}
13+
914
case class FaucetConfig(
1015
walletAddress: Address,
1116
walletPassword: String,
1217
txGasPrice: BigInt,
1318
txGasLimit: BigInt,
1419
txValue: BigInt,
15-
corsAllowedOrigins: HttpOriginMatcher,
1620
rpcAddress: String,
1721
keyStoreDir: String,
18-
listenInterface: String,
19-
listenPort: Int,
20-
minRequestInterval: FiniteDuration,
21-
latestTimestampCacheSize: Int
22+
minRequestInterval: FiniteDuration
2223
)
2324

2425
object FaucetConfig {
2526
def apply(typesafeConfig: TypesafeConfig): FaucetConfig = {
2627
val faucetConfig = typesafeConfig.getConfig("faucet")
2728

28-
val corsAllowedOrigins = ConfigUtils.parseCorsAllowedOrigins(faucetConfig, "cors-allowed-origins")
29-
3029
FaucetConfig(
3130
walletAddress = Address(faucetConfig.getString("wallet-address")),
3231
walletPassword = faucetConfig.getString("wallet-password"),
3332
txGasPrice = faucetConfig.getLong("tx-gas-price"),
3433
txGasLimit = faucetConfig.getLong("tx-gas-limit"),
3534
txValue = faucetConfig.getLong("tx-value"),
36-
corsAllowedOrigins = corsAllowedOrigins,
3735
rpcAddress = faucetConfig.getString("rpc-address"),
3836
keyStoreDir = faucetConfig.getString("keystore-dir"),
39-
listenInterface = faucetConfig.getString("listen-interface"),
40-
listenPort = faucetConfig.getInt("listen-port"),
41-
minRequestInterval = faucetConfig.getDuration("min-request-interval").toMillis.millis,
42-
latestTimestampCacheSize = faucetConfig.getInt("latest-timestamp-cache-size")
37+
minRequestInterval = faucetConfig.getDuration("min-request-interval").toMillis.millis
4338
)
4439
}
4540
}

0 commit comments

Comments
 (0)