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 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.14.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.!! val bytes = Files.readAllBytes(archiveLocation) val hash = MessageDigest .getInstance("SHA-256") .digest(bytes) .map("%02x" format _) .mkString val expectedHash = if (Properties.isLinux) "7034e4aea3f404a9bbb1d157653741eb0e020c3d3272f854d3e2cefa0070f24a" else if (Properties.isMac) "046409faf7e5049d6ddfdbe2a556fa0b5e6cc651bccce039c6f736b72390ad1d" else if (Properties.isWin) "661d0538ca04c4f890d3d9a72717916f41350e810ae06f884e7ed97b38bf783f" 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) } }