bitcoin-s/lnd-rpc/lnd-rpc.sbt
2021-07-21 15:19:32 -05:00

62 lines
2.0 KiB
Scala

import java.nio.file._
import scala.util.Properties
name := "bitcoin-s-lnd-rpc"
libraryDependencies ++= Deps.lndRpc
CommonSettings.prodSettings
enablePlugins(AkkaGrpcPlugin)
// Disable deprecation warning otherwise protobuf deprecation warnings will cause errors
Compile / scalacOptions += {
"-Wconf:cat=deprecation:site=lnrpc\\..*:silent,cat=deprecation:site=signrpc\\..*:silent,cat=deprecation:site=walletrpc\\..*:silent"
}
TaskKeys.downloadLnd := {
val logger = streams.value.log
import scala.sys.process._
val binaryDir = CommonSettings.binariesPath.resolve("lnd")
if (Files.notExists(binaryDir)) {
logger.info(s"Creating directory for lnd binaries: $binaryDir")
Files.createDirectories(binaryDir)
}
val version = "0.13.1-beta"
val (platform, suffix) =
if (Properties.isLinux) ("linux-amd64", "tar.gz")
else if (Properties.isMac) ("darwin-amd64", "tar.gz")
else if (Properties.isWin) ("windows-amd64", "zip")
else sys.error(s"Unsupported OS: ${Properties.osName}")
logger.debug(s"(Maybe) downloading lnd binaries for version: $version")
val versionDir = binaryDir resolve version
val location =
s"https://github.com/lightningnetwork/lnd/releases/download/v$version/lnd-$platform-v$version.$suffix"
if (Files.exists(versionDir)) {
logger.debug(
s"Directory $versionDir already exists, skipping download of lnd $version")
} else {
val archiveLocation = binaryDir resolve s"$version.$suffix"
logger.info(s"Downloading lnd version $version from location: $location")
logger.info(s"Placing the file in $archiveLocation")
val downloadCommand = url(location) #> archiveLocation.toFile
downloadCommand.!!
logger.info(s"Download complete, unzipping result")
val extractCommand = s"tar -xzf $archiveLocation --directory $binaryDir"
logger.info(s"Extracting archive with command: $extractCommand")
extractCommand.!!
logger.info(s"Deleting archive")
Files.delete(archiveLocation)
}
}