mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-23 14:50:42 +01:00
* Upgrade eclair to 0.11.0 * Fix getinfo RPC call * Remove Future parameters from EclairRpctestUtil.openAndConfirmChannel() * Fix docs * fix lnd hash
107 lines
3.8 KiB
Scala
107 lines
3.8 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(PekkoGrpcPlugin)
|
|
|
|
// 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=deprecation:site=wtclientrpc\\..*: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.18.4-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)
|
|
"cd0c0c14c62334a00e8107be436a32e63dac7d3c63e3dd3c89c427da316ef873"
|
|
else if (Properties.isMac && System.getProperty("os.arch") == "aarch64")
|
|
"e7379d70d7f4dbc7c08172b22207d8e21fddee3d8bd6a5a5527d3f4e7a74698c"
|
|
else if (Properties.isMac)
|
|
"71ec034b2e62a6db29c88d941f8e8902fa6070ce45e1b3c22d529313ae5fd0ce"
|
|
else if (Properties.isWin)
|
|
"8e15e5ac0d270d20e3341bfa622ca6251281b1ff6f88634430a209dff2d8ac0a"
|
|
else sys.error(s"Unsupported OS: ${Properties.osName}")
|
|
|
|
val success = hash.equalsIgnoreCase(expectedHash)
|
|
if (success) {
|
|
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 {
|
|
Files.deleteIfExists(versionDir)
|
|
logger.error(
|
|
s"Downloaded invalid version of lnd, got $hash, expected $expectedHash")
|
|
}
|
|
|
|
logger.info(s"Deleting archive")
|
|
Files.delete(archiveLocation)
|
|
|
|
if (!success) {
|
|
throw new RuntimeException(s"Failed to download lnd v$version")
|
|
}
|
|
}
|
|
}
|