Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 95 additions & 8 deletions insomnia_workspace.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"_type": "export",
"__export_format": 4,
"__export_date": "2020-10-02T11:18:34.806Z",
"__export_source": "insomnia.desktop.app:v2020.4.1",
"__export_date": "2020-11-02T20:39:43.839Z",
"__export_source": "insomnia.desktop.app:v2020.4.2",
"resources": [
{
"_id": "req_4222a4d54ba24fa7813429bdcdb732df",
Expand Down Expand Up @@ -90,6 +90,88 @@
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "req_5c84aeff984d41e4aca173ac56a0b113",
"parentId": "fld_9f9137459d5c429d83901f5c682be0f9",
"modified": 1604346888565,
"created": 1603997152827,
"url": "{{ faucet_url }}",
"name": "send_funds",
"description": "",
"method": "POST",
"body":
{
"mimeType": "application/json",
"text": "{\n\t\"jsonrpc\": \"2.0\",\n \"method\": \"faucet_sendFunds\", \n \"params\": [\"$address\"],\n \"id\": 1\n}"
},
"parameters": [],
"headers":
[
{
"name": "Content-Type",
"value": "application/json",
"description": "",
"id": "pair_b080d7c5b5194ad09efdd6926ed108c5",
"disabled": false
}
],
"authentication": {},
"metaSortKey": -1603997152827,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "fld_9f9137459d5c429d83901f5c682be0f9",
"parentId": "wrk_097d43914a4d4aea8b6f73f647921182",
"modified": 1604349428103,
"created": 1603918083216,
"name": "faucet",
"description": "",
"environment": {},
"environmentPropertyOrder": null,
"metaSortKey": -1552939140242,
"_type": "request_group"
},
{
"_id": "req_48316ba9ba834bcc94fdeae41d966eb9",
"parentId": "fld_9f9137459d5c429d83901f5c682be0f9",
"modified": 1604346774105,
"created": 1604338553808,
"url": "{{ faucet_url }}",
"name": "status",
"description": "",
"method": "POST",
"body":
{
"mimeType": "application/json",
"text": "{\n\t\"jsonrpc\": \"2.0\",\n \"method\": \"faucet_status\", \n \"params\": [],\n \"id\": 1\n}"
},
"parameters": [],
"headers":
[
{
"name": "Content-Type",
"value": "application/json",
"id": "pair_bce95e5eaba54223bb10210f4563af71"
}
],
"authentication": {},
"metaSortKey": -1604338553809,
"isPrivate": false,
"settingStoreCookies": true,
"settingSendCookies": true,
"settingDisableRenderRequestBody": false,
"settingEncodeUrl": true,
"settingRebuildPath": true,
"settingFollowRedirects": "global",
"_type": "request"
},
{
"_id": "req_cd0078ce4a034ebdbdf7dc9e20e78a29",
"parentId": "fld_2b54cbb84e244284b3ef752c5f805376",
Expand Down Expand Up @@ -1203,15 +1285,20 @@
{
"_id": "env_2e1a8d7b5f3649308cb3c524e84a3f33",
"parentId": "env_ee4c8118750744559d3b1020845fe5d4",
"modified": 1599825641645,
"modified": 1604347516298,
"created": 1552663140073,
"name": "Develop",
"data": {
"node_url": "http://127.0.0.1:8546"
"data":
{
"node_url": "http://127.0.0.1:8546",
"faucet_url": "http://127.0.0.1:8547"
},
"dataPropertyOrder": {
"&": [
"node_url"
"dataPropertyOrder":
{
"&":
[
"node_url",
"faucet_url"
]
},
"color": null,
Expand Down
27 changes: 3 additions & 24 deletions src/main/scala/io/iohk/ethereum/faucet/Faucet.scala
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
package io.iohk.ethereum.faucet

import java.security.SecureRandom

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import com.typesafe.config.ConfigFactory
import io.iohk.ethereum.keystore.KeyStoreImpl
import io.iohk.ethereum.mallet.service.RpcClient
import io.iohk.ethereum.utils.{KeyStoreConfig, Logger}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
import io.iohk.ethereum.faucet.jsonrpc.FaucetServer
import io.iohk.ethereum.utils.Logger

object Faucet extends Logger {

def main(args: Array[String]): Unit = {
val config = FaucetConfig(ConfigFactory.load())

implicit val system = ActorSystem("Faucet-system")

val keyStore = new KeyStoreImpl(KeyStoreConfig.customKeyStoreConfig(config.keyStoreDir), new SecureRandom())
val rpcClient = new RpcClient(config.rpcAddress)
val api = new FaucetApi(rpcClient, keyStore, config)

val bindingResultF = Http().newServerAt(config.listenInterface, config.listenPort).bind(api.route)

bindingResultF onComplete {
case Success(serverBinding) => log.info(s"Faucet HTTP server listening on ${serverBinding.localAddress}")
case Failure(ex) => log.error("Cannot start faucet HTTP server", ex)
}
(new FaucetServer).start()
}

}
73 changes: 0 additions & 73 deletions src/main/scala/io/iohk/ethereum/faucet/FaucetApi.scala

This file was deleted.

25 changes: 10 additions & 15 deletions src/main/scala/io/iohk/ethereum/faucet/FaucetConfig.scala
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
package io.iohk.ethereum.faucet

import ch.megard.akka.http.cors.scaladsl.model.HttpOriginMatcher
import com.typesafe.config.{Config => TypesafeConfig}
import com.typesafe.config.{ConfigFactory, Config => TypesafeConfig}
import io.iohk.ethereum.domain.Address
import io.iohk.ethereum.utils.ConfigUtils

import scala.concurrent.duration.{FiniteDuration, _}

trait FaucetConfigBuilder {
lazy val rawConfig: TypesafeConfig = ConfigFactory.load()
lazy val rawMantisConfig: TypesafeConfig = rawConfig.getConfig("mantis")
lazy val faucetConfig: FaucetConfig = FaucetConfig(rawConfig)
}

case class FaucetConfig(
walletAddress: Address,
walletPassword: String,
txGasPrice: BigInt,
txGasLimit: BigInt,
txValue: BigInt,
corsAllowedOrigins: HttpOriginMatcher,
rpcAddress: String,
keyStoreDir: String,
listenInterface: String,
listenPort: Int,
minRequestInterval: FiniteDuration,
latestTimestampCacheSize: Int
minRequestInterval: FiniteDuration
)

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

val corsAllowedOrigins = ConfigUtils.parseCorsAllowedOrigins(faucetConfig, "cors-allowed-origins")

FaucetConfig(
walletAddress = Address(faucetConfig.getString("wallet-address")),
walletPassword = faucetConfig.getString("wallet-password"),
txGasPrice = faucetConfig.getLong("tx-gas-price"),
txGasLimit = faucetConfig.getLong("tx-gas-limit"),
txValue = faucetConfig.getLong("tx-value"),
corsAllowedOrigins = corsAllowedOrigins,
rpcAddress = faucetConfig.getString("rpc-address"),
keyStoreDir = faucetConfig.getString("keystore-dir"),
listenInterface = faucetConfig.getString("listen-interface"),
listenPort = faucetConfig.getInt("listen-port"),
minRequestInterval = faucetConfig.getDuration("min-request-interval").toMillis.millis,
latestTimestampCacheSize = faucetConfig.getInt("latest-timestamp-cache-size")
minRequestInterval = faucetConfig.getDuration("min-request-interval").toMillis.millis
)
}
}
Loading