-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2740 from alvasw/verify_and_unpack_bitcoind_to_re…
…sources Verify and unpack bitcoind to resources
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ gradlePlugin { | |
|
||
dependencies { | ||
implementation(project(":gradle-tasks")) | ||
implementation(libs.google.guava) | ||
} |
20 changes: 20 additions & 0 deletions
20
...in-core-binaries/src/main/kotlin/bisq/gradle/bitcoin_core/BitcoinCoreBinaryUrlProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bisq.gradle.bitcoin_core | ||
|
||
import bisq.gradle.tasks.PerPlatformUrlProvider | ||
|
||
class BitcoinCoreBinaryUrlProvider(private val version: String) : PerPlatformUrlProvider { | ||
override val urlPrefix: String | ||
get() = "https://bitcoincore.org/bin/bitcoin-core-$version/bitcoin-$version-" | ||
|
||
override val LINUX_X86_64_URL: String | ||
get() = "x86_64-linux-gnu.tar.gz" | ||
|
||
override val MACOS_X86_64_URL: String | ||
get() = "x86_64-apple-darwin.tar.gz" | ||
|
||
override val MACOS_ARM_64_URL: String | ||
get() = "arm64-apple-darwin.tar.gz" | ||
|
||
override val WIN_X86_64_URL: String | ||
get() = "win64.zip" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ic/bitcoin-core-binaries/src/main/kotlin/bisq/gradle/bitcoin_core/HashVerificationTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package bisq.gradle.bitcoin_core | ||
|
||
import com.google.common.hash.Hashing | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
abstract class HashVerificationTask : DefaultTask() { | ||
@get:InputFile | ||
abstract val inputFile: RegularFileProperty | ||
|
||
@get:InputFile | ||
abstract val sha256File: RegularFileProperty | ||
|
||
@get:OutputFile | ||
abstract val resultFile: RegularFileProperty | ||
|
||
@TaskAction | ||
fun verify() { | ||
val input = inputFile.get().asFile.readBytes() | ||
val hash: String = Hashing.sha256() | ||
.hashBytes(input) | ||
.toString() | ||
|
||
val expectedHash = getExpectedHash() | ||
if (hash != expectedHash) { | ||
throw GradleException( | ||
"Hash verification failed for `${inputFile.get().asFile.absolutePath}`. " + | ||
"Expected: `$expectedHash, Actual: `$hash`" | ||
) | ||
} | ||
|
||
resultFile.get().asFile.writeText(hash) | ||
} | ||
|
||
private fun getExpectedHash(): String { | ||
val inputFileName = inputFile.get().asFile.name | ||
for (line in sha256File.get().asFile.readLines()) { | ||
if (line.endsWith(inputFileName)) { | ||
// '<sha256hash> filename.tar.gz' | ||
return line.split(" ").first() | ||
} | ||
} | ||
|
||
throw GradleException("Couldn't find expected hash for `$inputFile`.") | ||
} | ||
} |