bitcoin-s/lnd-rpc/lnd-rpc.sbt
benthecarman 6b479e8765
Add support for mac m1 lnd rpc (#4780)
* Add support for mac m1 lnd rpc

* Remove unneeded wait

* Add timeout to isStarted

* Consider RPC_ACTIVE not started

* Fix formatting
2022-09-14 15:35:28 -05:00

101 lines
3.6 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=deprecation:site=chainrpc\\..*: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",
"-Wconf:cat=unused-imports:site=chainrpc: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.15.0-beta"
val (platform, suffix) =
if (Properties.isLinux) ("linux-amd64", "tar.gz")
else if (Properties.isMac && System.getProperty("os.arch") == "aarch64")
("darwin-arm64", "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)
"60511b4717a82c303e164f7d1048fd52f965c5fcb7aefaa11678be48e81a9dcc"
else if (Properties.isMac && System.getProperty("os.arch") == "aarch64")
"c1e1452dd2f4cf6bca248cc6b63d2f1b8f64b82ae0f81dcf669575bc4b359f84"
else if (Properties.isMac)
"eacf6e8f19de942fb23f481c85541342d3248bd545616822a172da3d23c03c9d"
else if (Properties.isWin)
"74c16854292ca27b335309d7b37a44baec4df402e16b203df393ebece6570ad3"
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)
}
}