Add 'getversion' endpoint to fetch the version from the backend (#3689)

* Add 'getversion' endpoint to fetch the version from the backend

* Use EnvUtil.getversion
This commit is contained in:
Chris Stewart 2021-09-27 07:42:21 -05:00 committed by GitHub
parent 26efbe783e
commit 2191eb2049
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 5 deletions

View file

@ -4,7 +4,7 @@ import akka.actor.ActorSystem
import org.bitcoins.commons.util.{DatadirParser, ServerArgParser} import org.bitcoins.commons.util.{DatadirParser, ServerArgParser}
import org.bitcoins.dlc.oracle.DLCOracle import org.bitcoins.dlc.oracle.DLCOracle
import org.bitcoins.dlc.oracle.config.DLCOracleAppConfig import org.bitcoins.dlc.oracle.config.DLCOracleAppConfig
import org.bitcoins.server.routes.{BitcoinSServerRunner, Server} import org.bitcoins.server.routes.{BitcoinSServerRunner, CommonRoutes, Server}
import org.bitcoins.server.util.BitcoinSAppScalaDaemon import org.bitcoins.server.util.BitcoinSAppScalaDaemon
import scala.concurrent.Future import scala.concurrent.Future
@ -21,10 +21,12 @@ class OracleServerMain(override val serverArgParser: ServerArgParser)(implicit
case None => conf.rpcBindOpt case None => conf.rpcBindOpt
} }
val commonRoutes = CommonRoutes()
for { for {
_ <- conf.start() _ <- conf.start()
oracle = new DLCOracle() oracle = new DLCOracle()
routes = Seq(OracleRoutes(oracle)) routes = Seq(OracleRoutes(oracle), commonRoutes)
server = serverArgParser.rpcPortOpt match { server = serverArgParser.rpcPortOpt match {
case Some(rpcport) => case Some(rpcport) =>
Server(conf = conf, Server(conf = conf,

View file

@ -0,0 +1,17 @@
package org.bitcoins.server.routes
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.directives.RouteDirectives
import org.bitcoins.core.util.EnvUtil
case class CommonRoutes() extends ServerRoute {
override def handleCommand: PartialFunction[ServerCommand, Route] = {
case ServerCommand("getversion", _) =>
RouteDirectives.complete {
val vec = Vector(("version", ujson.Str(EnvUtil.getVersion)))
val obj = ujson.Obj.from(vec)
Server.httpSuccess(obj)
}
}
}

View file

@ -0,0 +1,28 @@
package org.bitcoins.server
import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.bitcoins.core.util.EnvUtil
import org.bitcoins.server.routes.{CommonRoutes, ServerCommand}
import org.scalamock.scalatest.MockFactory
import org.scalatest.wordspec.AnyWordSpec
class CommonRoutesSpec
extends AnyWordSpec
with ScalatestRouteTest
with MockFactory {
val commonRoutes = CommonRoutes()
"CommonRoutes" should {
"getversion" in {
val route =
commonRoutes.handleCommand(ServerCommand("getversion", ujson.Arr()))
Get() ~> route ~> check {
s"""
|{ "version" : "${EnvUtil.getVersion}" }
|""".stripMargin
}
}
}
}

View file

@ -38,7 +38,7 @@ import org.bitcoins.core.wallet.fee.{FeeUnit, SatoshisPerVirtualByte}
import org.bitcoins.core.wallet.utxo._ import org.bitcoins.core.wallet.utxo._
import org.bitcoins.crypto._ import org.bitcoins.crypto._
import org.bitcoins.node.Node import org.bitcoins.node.Node
import org.bitcoins.server.routes.ServerCommand import org.bitcoins.server.routes.{CommonRoutes, ServerCommand}
import org.bitcoins.testkit.BitcoinSTestAppConfig import org.bitcoins.testkit.BitcoinSTestAppConfig
import org.bitcoins.testkit.wallet.DLCWalletUtil import org.bitcoins.testkit.wallet.DLCWalletUtil
import org.bitcoins.wallet.MockWalletApi import org.bitcoins.wallet.MockWalletApi
@ -80,6 +80,7 @@ class RoutesSpec extends AnyWordSpec with ScalatestRouteTest with MockFactory {
val coreRoutes: CoreRoutes = CoreRoutes() val coreRoutes: CoreRoutes = CoreRoutes()
val commonRoutes: CommonRoutes = CommonRoutes()
"The server" should { "The server" should {
"combine PSBTs" in { "combine PSBTs" in {

View file

@ -27,7 +27,7 @@ import org.bitcoins.node._
import org.bitcoins.node.config.NodeAppConfig import org.bitcoins.node.config.NodeAppConfig
import org.bitcoins.node.models.Peer import org.bitcoins.node.models.Peer
import org.bitcoins.rpc.config.{BitcoindRpcAppConfig, ZmqConfig} import org.bitcoins.rpc.config.{BitcoindRpcAppConfig, ZmqConfig}
import org.bitcoins.server.routes.{BitcoinSServerRunner, Server} import org.bitcoins.server.routes.{BitcoinSServerRunner, CommonRoutes, Server}
import org.bitcoins.server.util.BitcoinSAppScalaDaemon import org.bitcoins.server.util.BitcoinSAppScalaDaemon
import org.bitcoins.tor.config.TorAppConfig import org.bitcoins.tor.config.TorAppConfig
import org.bitcoins.wallet.Wallet import org.bitcoins.wallet.Wallet
@ -338,9 +338,15 @@ class BitcoinSServerMain(override val serverArgParser: ServerArgParser)(implicit
val chainRoutes = ChainRoutes(chainApi, nodeConf.network) val chainRoutes = ChainRoutes(chainApi, nodeConf.network)
val coreRoutes = CoreRoutes() val coreRoutes = CoreRoutes()
val dlcRoutes = DLCRoutes(dlcNode) val dlcRoutes = DLCRoutes(dlcNode)
val commonRoutes = CommonRoutes()
val handlers = val handlers =
Seq(walletRoutes, nodeRoutes, chainRoutes, coreRoutes, dlcRoutes) Seq(walletRoutes,
nodeRoutes,
chainRoutes,
coreRoutes,
dlcRoutes,
commonRoutes)
val bindConfOpt = serverCmdLineArgs.rpcBindOpt match { val bindConfOpt = serverCmdLineArgs.rpcBindOpt match {
case Some(rpcbind) => Some(rpcbind) case Some(rpcbind) => Some(rpcbind)

View file

@ -138,6 +138,9 @@ the `-p 9999:9999` port mapping on the docker container to adjust for this.
## Server Endpoints ## Server Endpoints
### Common
- `getversion` - The version of our application you are using
### Blockchain ### Blockchain
- `getblockcount` - Get the current block height - `getblockcount` - Get the current block height
- `getfiltercount` - Get the number of filters - `getfiltercount` - Get the number of filters