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.2-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) "7e0f290716e3c246305e176310a9a49aaafc9c243adc829631094a409cfd0ef1" else if (Properties.isMac) "c9f9bab9209a329407c4ba42b7b177b5e9edcab936e0a6c84593b09369ef43c5" else if (Properties.isWin) "c0060c000b11f440c5cc1675ec23820a67eae2cca7a881d430b78109d707b543" 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) } }