mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-19 05:43:51 +01:00
95 lines
3.3 KiB
Scala
95 lines
3.3 KiB
Scala
import java.nio.file._
|
|
import java.security.MessageDigest
|
|
import scala.util.Properties
|
|
|
|
name := "bitcoin-s-lnd-rpc"
|
|
|
|
libraryDependencies ++= Deps.lndRpc
|
|
|
|
CommonSettings.prodSettings
|
|
|
|
enablePlugins(AkkaGrpcPlugin)
|
|
|
|
// Disable deprecation and unused imports warning otherwise generated files will cause errors
|
|
Compile / scalacOptions ++= Seq(
|
|
"-Wconf:cat=deprecation:site=lnrpc\\..*:silent",
|
|
"-Wconf:cat=deprecation:site=signrpc\\..*:silent",
|
|
"-Wconf:cat=deprecation:site=walletrpc\\..*:silent",
|
|
"-Wconf:cat=deprecation:site=routerrpc\\..*:silent",
|
|
"-Wconf:cat=deprecation:site=invoicesrpc\\..*:silent",
|
|
"-Wconf:cat=deprecation:site=peersrpc\\..*:silent",
|
|
"-Wconf:cat=unused-imports:site=lnrpc:silent",
|
|
"-Wconf:cat=unused-imports:site=signrpc:silent",
|
|
"-Wconf:cat=unused-imports:site=walletrpc:silent",
|
|
"-Wconf:cat=unused-imports:site=routerrpc:silent",
|
|
"-Wconf:cat=unused-imports:site=invoicesrpc:silent",
|
|
"-Wconf:cat=unused-imports:site=peersrpc: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.14.3-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 s"lnd-$platform-v$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.!!
|
|
|
|
val bytes = Files.readAllBytes(archiveLocation)
|
|
val hash = MessageDigest
|
|
.getInstance("SHA-256")
|
|
.digest(bytes)
|
|
.map("%02x" format _)
|
|
.mkString
|
|
|
|
val expectedHash =
|
|
if (Properties.isLinux)
|
|
"272b9a8e745d1a67a5d6fa5fb9c6bad2791ab84996df5ed87ab89f850f9b9bf5"
|
|
else if (Properties.isMac)
|
|
"f72771e6babbdc630f25c14f3528b922415e4069446f340ef26dc80587eb3fe1"
|
|
else if (Properties.isWin)
|
|
"72487fccf8eda9f5d2942b6797c96b25ce3ea9771582ae46a752ec0a0c7f96de"
|
|
else sys.error(s"Unsupported OS: ${Properties.osName}")
|
|
|
|
if (hash.equalsIgnoreCase(expectedHash)) {
|
|
logger.info(s"Download complete and verified, unzipping result")
|
|
|
|
val extractCommand = s"tar -xzf $archiveLocation --directory $binaryDir"
|
|
logger.info(s"Extracting archive with command: $extractCommand")
|
|
extractCommand.!!
|
|
} else {
|
|
logger.error(
|
|
s"Downloaded invalid version of lnd, got $hash, expected $expectedHash")
|
|
}
|
|
|
|
logger.info(s"Deleting archive")
|
|
Files.delete(archiveLocation)
|
|
}
|
|
}
|