From 932c7ede765a94f4dc2124ede4a93f1aba5a08a6 Mon Sep 17 00:00:00 2001 From: rorp Date: Thu, 28 May 2020 08:50:57 -0700 Subject: [PATCH] Upgrade Eclair to v0.4 (#1421) * Upgrade Eclair to v0.4 * fix test binary * logging * unquote paths * fix eclair-node.sh * OSX fix * cleanup --- eclair-rpc/eclair-rpc.sbt | 49 ++++++++++++++++--- .../eclair/rpc/client/EclairRpcClient.scala | 20 +++++--- .../eclair/rpc/EclairRpcTestUtil.scala | 9 +++- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/eclair-rpc/eclair-rpc.sbt b/eclair-rpc/eclair-rpc.sbt index bd198a685f..6129810f18 100644 --- a/eclair-rpc/eclair-rpc.sbt +++ b/eclair-rpc/eclair-rpc.sbt @@ -21,14 +21,14 @@ TaskKeys.downloadEclair := { Files.createDirectories(binaryDir) } - val version = "0.3.3" - val commit = "12ac145" + val version = "0.4" + val commit = "69c538e" logger.debug(s"(Maybe) downloading Eclair binaries for version: $version") val versionDir = binaryDir resolve version val location = - s"https://github.com/ACINQ/eclair/releases/download/v$version/eclair-node-$version-$commit.jar" + s"https://github.com/ACINQ/eclair/releases/download/v$version/eclair-node-$version-$commit-bin.zip" if (Files.exists(versionDir)) { logger.debug( @@ -37,11 +37,48 @@ TaskKeys.downloadEclair := { logger.info(s"Creating directory $version") Files.createDirectories(versionDir) - val destination = versionDir resolve s"eclair-node-$version-$commit.jar" + val archiveLocation = versionDir resolve s"eclair-node-$version-$commit.zip" logger.info( - s"Downloading Eclair $version from location: $location, to destination: $destination") - (url(location) #> destination.toFile).!! + s"Downloading Eclair $version from location: $location, to destination: $archiveLocation") + (url(location) #> archiveLocation.toFile).!! + + val extractCommand = s"unzip $archiveLocation -d $versionDir" + logger.info(s"Extracting archive with command: $extractCommand") + extractCommand.!! + + logger.info(s"Deleting archive") + Files.delete(archiveLocation) + + fixShebang( + versionDir resolve s"eclair-node-$version-$commit" resolve "bin" resolve "eclair-node.sh") logger.info(s"Download complete") } + + // remove me when https://github.com/ACINQ/eclair/issues/1421 + // and https://github.com/ACINQ/eclair/issues/1422 are fixed + def fixShebang(scriptPath: Path): Unit = { + import java.nio.file.attribute.PosixFilePermissions + import scala.io.Source + import scala.collection.JavaConverters._ + + val tempPath = scriptPath.getParent resolve scriptPath.getFileName.toString + ".tmp" + Files.createFile(tempPath, + PosixFilePermissions.asFileAttribute( + PosixFilePermissions.fromString("rwxr-xr-x"))) + val source = Source + .fromFile(scriptPath.toUri) + + val lines = (Vector("#!/usr/bin/env bash") ++ source.getLines()).map( + line => + if (line == "declare -r lib_dir=\"$(realpath \"${app_home::-4}/lib\")\" # {app_home::-4} transforms ../bin in ../") + "declare -r lib_dir=\"$(realpath \"${app_home:0:${#app_home}-4}/lib\")\" # {app_home:0:${#app_home}-4} transforms ../bin in ../" + else line) + + source.close() + + Files.write(tempPath, lines.asJava, StandardOpenOption.WRITE) + + tempPath.toFile.renameTo(scriptPath.toFile) + } } diff --git a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala index 3c898e8449..c548d0ba4e 100644 --- a/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala +++ b/eclair-rpc/src/main/scala/org/bitcoins/eclair/rpc/client/EclairRpcClient.scala @@ -698,16 +698,20 @@ class EclairRpcClient(val instance: EclairInstance, binary: Option[File] = None) s"Given binary ($binary) does not exist!") } case (None, Some(path)) => + val eclairBinDir = + s"eclair-node-${EclairRpcClient.version}-${EclairRpcClient.commit}${File.separator}bin${File.separator}" val eclairV = - s"eclair-node-${EclairRpcClient.version}-${EclairRpcClient.commit}.jar" - val fullPath = path + eclairV + if (sys.props("os.name").toLowerCase.contains("windows")) + eclairBinDir + "eclair-node.bat" + else + eclairBinDir + "eclair-node.sh" - val jar = new File(fullPath) + val jar = new File(path, eclairV) if (jar.exists) { - fullPath + jar.getPath } else { throw new NoSuchFileException( - s"Could not Eclair Jar at location $fullPath") + s"Could not Eclair Jar at location ${jar.getPath}") } case (None, None) => val msg = List( @@ -736,7 +740,7 @@ class EclairRpcClient(val instance: EclairInstance, binary: Option[File] = None) .map(path => s"-Dlogback.configurationFile=$path") .getOrElse("") val cmd = - s"java -jar -Declair.datadir=${instance.authCredentials.datadir.get} $logback $pathToEclairJar &" + s"${pathToEclairJar} -Declair.datadir=${instance.authCredentials.datadir.get} $logback" val p = Process(cmd) val result = p.run() logger.debug( @@ -942,8 +946,8 @@ object EclairRpcClient { implicit system: ActorSystem) = new EclairRpcClient(instance, binary) /** The current commit we support of Eclair */ - private[bitcoins] val commit = "12ac145" + private[bitcoins] val commit = "69c538e" /** The current version we support of Eclair */ - private[bitcoins] val version = "0.3.3" + private[bitcoins] val version = "0.4" } diff --git a/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala b/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala index 54e053b6cd..7f168bfb8b 100644 --- a/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala +++ b/testkit/src/main/scala/org/bitcoins/testkit/eclair/rpc/EclairRpcTestUtil.scala @@ -63,8 +63,13 @@ trait EclairRpcTestUtil extends BitcoinSLogger { val path = binaryDirectory .resolve(eclairVersionOpt.getOrElse(EclairRpcClient.version)) .resolve( - s"eclair-node-${eclairVersionOpt.getOrElse(EclairRpcClient.version)}-${eclairCommitOpt - .getOrElse(EclairRpcClient.commit)}.jar") + s"eclair-node-${EclairRpcClient.version}-${EclairRpcClient.commit}") + .resolve("bin") + .resolve( + if (sys.props("os.name").toLowerCase.contains("windows")) + "eclair-node.bat" + else + "eclair-node.sh") if (Files.exists(path)) { Some(path.toFile)