Skip to content

Commit

Permalink
Regtest: Implement seednode start tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Sep 11, 2023
1 parent 4575d2a commit e013b5b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,57 @@ import org.gradle.kotlin.dsl.register

class RegtestPlugin : Plugin<Project> {

companion object {
const val RPC_USER = "bisqdao"
const val RPC_PASSWORD = "bsq"
}

override fun apply(project: Project) {
val startBitcoindTask = project.tasks.register<StartBitcoindTask>("startBitcoindRegtest") {
val startBitcoindTask = project.tasks.register<StartBitcoindTask>("startRegtestBitcoind") {
dataDirectory.set(project.layout.projectDirectory.dir(".localnet/bitcoind"))
rpcUser.set("bisqdao")
rpcPassword.set("bsq")
rpcUser.set(RPC_USER)
rpcPassword.set(RPC_PASSWORD)
blockNotifyArg.set(".localnet/bitcoind/blocknotify %s")
}

val startFirstSeedNodeTask = project.tasks.register<StartSeedNodeTask>("startRegtestFirstSeednode") {
dependsOn(startBitcoindTask)
startScriptFile.set(project.layout.projectDirectory.file("bisq-seednode"))

arguments.set(
createSeedNodeArgs(5120, 2002, "seednode")
)

workingDirectory.set(project.layout.projectDirectory)
logFile.set(project.layout.projectDirectory.file(".localnet/seednode_1_shell.log"))
}

val startSecondSeedNodeTask = project.tasks.register<StartSeedNodeTask>("startRegtestSecondSeednode") {
dependsOn(startBitcoindTask)
dependsOn(startFirstSeedNodeTask)
startScriptFile.set(project.layout.projectDirectory.file("bisq-seednode"))

arguments.set(
createSeedNodeArgs(5121, 3002, "seednode2")
)

workingDirectory.set(project.layout.projectDirectory)
logFile.set(project.layout.projectDirectory.file(".localnet/seednode_2_shell.log"))
}
}

private fun createSeedNodeArgs(blockNotificationPort: Int, nodePort: Int, appName: String): List<String> = listOf(
"--baseCurrencyNetwork=BTC_REGTEST",
"--useLocalhostForP2P=true",
"--useDevPrivilegeKeys=true",
"--fullDaoNode=true",

"--rpcUser=${RPC_USER}",
"--rpcPassword=${RPC_PASSWORD}",
"--rpcBlockNotificationPort=$blockNotificationPort",

"--nodePort=$nodePort",
"--userDataDir=.localnet",
"--appName=$appName"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package bisq.gradle.regtest_plugin

import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction

abstract class StartSeedNodeTask : DefaultTask() {

@get:InputFile
abstract val startScriptFile: RegularFileProperty

@get:Input
abstract val arguments: ListProperty<String>

@get:InputDirectory
abstract val workingDirectory: DirectoryProperty

@get:Internal
abstract val logFile: RegularFileProperty

@TaskAction
fun run() {
val processBuilder = ProcessBuilder(
"bash", startScriptFile.asFile.get().absolutePath, arguments.get().joinToString(" ")
)

processBuilder.directory(workingDirectory.asFile.get())
processBuilder.redirectErrorStream(true)
processBuilder.redirectOutput(logFile.asFile.get())

processBuilder.start()
}
}

0 comments on commit e013b5b

Please sign in to comment.