bitcoin-s/bitcoind-rpc/bitcoind-rpc.sbt
Ben Carman 5206353a4a Bitcoind v19 RPC (#910)
* bitcoind v19 new RPC calls and tests (#863)

* bitcoind v19 new RPC calls and tests

* Code review changes

* Review part 2

* Rename variable to be more descriptive

* Explanitory comment

* Ignore broken test cases

* Add missing signing functions

* Add test to check avoid_reuse flag is on (#870)

* Add test to check avoid_reuse flag is on

* Add test to make sure flags weren't set

* bitcoind v19 Update mempool RPCs and tests (#868)

* Update mempool RPC calls to bitcoind v19 compatibility

* Typo fix

* Add parameter name to calls

* Fix remaining rpc calls

* Formatting

* scaladoc for param

* Change param to correct type

* Clarify on scaladoc

* Add missing fees parmater to mempool rpcs (#875)

* Add weight field to mempool entries after v19 (#876)

* Move DescriptorRpc to be able to be used by future versions of bitcoind (#878)

* Add window_final_block_height to GetChainTxStatsResult (#880)

* Add passphrase argument to createwallet for later versions (#883)

* Add passphrase argument to createwallet for later versions

* Scaladoc + empty passphrase requirement

* Error message

* Add new services names parameter to P2P rpcs (#874)

* Add new services names parameter to P2P rpcs

* Add ServiceIdentifier Reads

* Add fallback case

* Address review

* Change to Try

* Move PsbtRpc to be able to be used by future versions of bitcoind (#877)

* Move PsbtRpc to be able to be used by future versions of bitcoind

* Add test

* Address comment

* Enable bloom filters for v19

* Enable bip 61 for tests

* Change to official binaries

* Force v18 for Spv Tests

* Remove unused config line
2019-12-04 07:44:44 -06:00

85 lines
2.7 KiB
Scala

import scala.util.Properties
import scala.collection.JavaConverters._
import scala.concurrent.{Future, Await}
import scala.concurrent.duration.DurationInt
import java.nio.file.Files
import java.nio.file.Paths
name := "bitcoin-s-bitcoind-rpc"
libraryDependencies ++= Deps.bitcoindRpc
dependsOn(Projects.core)
CommonSettings.prodSettings
TaskKeys.downloadBitcoind := {
val logger = streams.value.log
import scala.sys.process._
val binaryDir = Paths.get("binaries", "bitcoind")
if (Files.notExists(binaryDir)) {
logger.info(s"Creating directory for bitcoind binaries: $binaryDir")
Files.createDirectories(binaryDir)
}
val experimentalVersion = "0.18.99" // TODO: change this when new version compiled on suredbits server
val versions =
List("0.19.0.1", "0.18.1", "0.17.0.1", "0.16.3", experimentalVersion)
logger.debug(
s"(Maybe) downloading Bitcoin Core binaries for versions: ${versions.mkString(",")}")
val (platform, suffix) =
if (Properties.isLinux) ("x86_64-linux-gnu", "tar.gz")
else if (Properties.isMac) ("osx64", "tar.gz")
else if (Properties.isWin) ("win64", "zip")
else sys.error(s"Unsupported OS: ${Properties.osName}")
implicit val ec = scala.concurrent.ExecutionContext.global
val downloads = versions.map { version =>
val versionDir = binaryDir resolve version
val archiveLocation = binaryDir resolve s"$version.$suffix"
val location =
if (version == experimentalVersion)
s"https://s3-us-west-1.amazonaws.com/suredbits.com/bitcoin-core-$version/bitcoin-$version-$platform.$suffix"
else
s"https://bitcoincore.org/bin/bitcoin-core-$version/bitcoin-$version-$platform.$suffix"
val expectedEndLocation = binaryDir resolve s"bitcoin-$version"
if (Files
.list(binaryDir)
.iterator
.asScala
.map(_.toString)
.exists(expectedEndLocation.toString.startsWith(_))) {
logger.debug(
s"Directory $expectedEndLocation already exists, skipping download of version $version")
Future.unit
} else {
Future {
logger.info(
s"Downloading bitcoind version $version from location: $location")
logger.info(s"Placing the file in $archiveLocation")
val downloadCommand = url(location) #> archiveLocation.toFile
downloadCommand.!!
logger.info(s"Download complete, unzipping result")
val extractCommand = s"tar -xzf $archiveLocation --directory $binaryDir"
logger.info(s"Extracting archive with command: $extractCommand")
extractCommand.!!
logger.info(s"Deleting archive")
Files.delete(archiveLocation)
}
}
}
//timeout if we cannot download in 60 seconds
Await.result(Future.sequence(downloads), 60.seconds)
}