Skip to content

Commit

Permalink
Merge pull request #1 from acrylplatform/FIX-1
Browse files Browse the repository at this point in the history
FIX-1: Various fixes
  • Loading branch information
deadblackclover authored Feb 13, 2020
2 parents f2b50a1 + 2391cc0 commit 38105a4
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 9 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# acryl-node-extension
Extension for Acryl Node

## Extension options
- when the node starts, it sends message why the node will not generate blocks:
- if mining disabled in config
- a generating balance is less than 100 Acryl
- the miner account has a smart contract
- notifies if the node mined block and its reward
- notifies about incoming Acryl
- notifies about changes of leased volume.

## How to install:
1. Download `node-extension-0.0.1.jar` to `/usr/share/acryl/lib/`:
```
wget https://github.com/acrylplatform/acryl-node-extension/releases/download/v0.0.1/node-extension-0.0.1.jar -P /usr/share/acryl/lib/
```
2. Download official `scalaj-http_2.12-2.4.2.jar` from Maven Central to `/usr/share/acryl/lib/`:
```
wget https://repo1.maven.org/maven2/org/scalaj/scalaj-http_2.12/2.4.2/scalaj-http_2.12-2.4.2.jar -P /usr/share/acryl/lib/
```
3. Add to `/etc/acryl/acryl.conf` (or `local.conf`):
```
acryl.extensions = [
"com.acrylplatform.extensions.Node"
]
node-extension.webhook {
# url = "https://example.com/webhook/1234567890" # SPECIFY YOUR ENDPOINT
# body = """Mainnet: %s"""
}
```
4. Restart the node
If node starts successfully, you will receive message about this.
## Notifications
By default the extension writes notifications to the node log file. In addition, you can specify any endpoint of notifications.
For example, you can use Telegram bot https://t.me/bullhorn_bot from https://integram.org/ team (add this bot and read its welcome message).
You can read the full list of properties in the [application.conf](src/main/resources/application.conf).
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name := "node-extension"
version := "0.0.1"

scalaVersion := "2.12.9"
scalaVersion := "2.12.8"
val nodeVersion = "v1.0.4"

lazy val node = ProjectRef(uri(s"git://github.com/acrylplatform/Acryl.git#$nodeVersion"), "node")

lazy val myProject = (project in file("."))
lazy val nodeExtension = (project in file("."))
.dependsOn(node % "compile;runtime->provided")

libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.4.2"
4 changes: 2 additions & 2 deletions src/main/scala/com/acrylplatform/extensions/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ class Node(context: ExtensionContext) extends Extension with ScorexLogging {
}

if (context.settings.minerSettings.enable) {
if (generatingBalance < 1000 * 100000000)
if (generatingBalance < 100 * 100000000)
warn(
s"Node doesn't mine blocks!" +
s" Generating balance is ${acryl(generatingBalance)} Acryl but must be at least 1000 Acryl")
s" Generating balance is ${acryl(generatingBalance)} Acryl but must be at least 100 Acryl")
if (context.blockchain.hasScript(minerPublicKey.toAddress))
warn(
s"Node doesn't mine blocks! Account ${minerPublicKey.toAddress.stringRepr} is scripted." +
Expand Down
52 changes: 47 additions & 5 deletions src/main/scala/com/acrylplatform/extensions/node/Settings.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.acrylplatform.extensions.node

import net.ceedubs.ficus.readers.ArbitraryTypeReader.arbitraryTypeValueReader
import net.ceedubs.ficus.readers.ValueReader
import com.typesafe.config.Config
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import net.ceedubs.ficus.readers.{NameMapper, ValueReader}

case class Settings(
webhook: WebhookSettings,
Expand All @@ -23,13 +25,53 @@ case class NotificationsSettings(
)

object Settings {
implicit val valueReader: ValueReader[Settings] = arbitraryTypeValueReader
implicit val chosenCase: NameMapper = net.ceedubs.ficus.readers.namemappers.implicits.hyphenCase

implicit val valueReader: ValueReader[Settings] =
(cfg, path) => fromConfig(cfg.getConfig(path))

private[this] def fromConfig(config: Config): Settings = {
val webhookSettings = config.as[WebhookSettings]("webhook")
val blockUrl = config.as[String]("block-url")
val notificationsSettings = config.as[NotificationsSettings]("notifications")
Settings(
webhook = webhookSettings,
blockUrl = blockUrl,
notifications = notificationsSettings
)
}
}

object WebhookSettings {
implicit val valueReader: ValueReader[WebhookSettings] = arbitraryTypeValueReader
implicit val valueReader: ValueReader[WebhookSettings] =
(cfg, path) => fromConfig(cfg.getConfig(path))

private[this] def fromConfig(config: Config): WebhookSettings = {
val url = config.as[String]("url")
val method = config.as[String]("method")
val headers = config.as[Seq[String]]("headers")
val body = config.as[String]("body")
WebhookSettings(
url = url,
method = method,
headers = headers,
body = body
)
}
}

object NotificationsSettings {
implicit val valueReader: ValueReader[NotificationsSettings] = arbitraryTypeValueReader
implicit val valueReader: ValueReader[NotificationsSettings] =
(cfg, path) => fromConfig(cfg.getConfig(path))

private[this] def fromConfig(config: Config): NotificationsSettings = {
val startStop = config.as[Boolean]("start-stop")
val acrylReceived = config.as[Boolean]("acryl-received")
val leasing = config.as[Boolean]("leasing")
NotificationsSettings(
startStop = startStop,
acrylReceived = acrylReceived,
leasing = leasing
)
}
}

0 comments on commit 38105a4

Please sign in to comment.