mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-13 11:35:40 +01:00
Set closing txid on execute from View Dialog (#3340)
This commit is contained in:
parent
cc1cfe6594
commit
53cafa7898
3 changed files with 29 additions and 13 deletions
|
@ -72,8 +72,9 @@ class DLCPane(glassPane: VBox)(implicit ec: ExecutionContext) {
|
|||
|
||||
private val refundButton = new Button {
|
||||
text = "Refund"
|
||||
onAction = new EventHandler[ActionEvent] {
|
||||
override def handle(event: ActionEvent): Unit = model.onRefund()
|
||||
onAction = _ => {
|
||||
model.onRefund()
|
||||
()
|
||||
}
|
||||
tooltip = Tooltip(
|
||||
"After the refund timeout, broadcasts the refund transaction to the blockchain.")
|
||||
|
@ -82,8 +83,9 @@ class DLCPane(glassPane: VBox)(implicit ec: ExecutionContext) {
|
|||
|
||||
private val executeButton = new Button {
|
||||
text = "Execute"
|
||||
onAction = new EventHandler[ActionEvent] {
|
||||
override def handle(event: ActionEvent): Unit = model.onExecute()
|
||||
onAction = _ => {
|
||||
model.onExecute()
|
||||
()
|
||||
}
|
||||
tooltip = Tooltip(
|
||||
"Given an oracle attestation, broadcasts the closing transaction to the blockchain.")
|
||||
|
|
|
@ -20,7 +20,8 @@ import upickle.default._
|
|||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.concurrent.duration.DurationInt
|
||||
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
|
||||
import scala.util.{Failure, Properties, Success}
|
||||
|
||||
class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
|
||||
|
@ -91,9 +92,11 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
|
|||
def printDLCDialogResult[T <: CliCommand](
|
||||
caption: String,
|
||||
dialog: DLCDialog[T],
|
||||
postProcessStr: String => String = str => str): Unit = {
|
||||
postProcessStr: String => String = str => str): String = {
|
||||
val result = dialog.showAndWait(parentWindow.value)
|
||||
|
||||
val promise = Promise[String]()
|
||||
|
||||
result match {
|
||||
case Some(command) =>
|
||||
taskRunner.run(
|
||||
|
@ -102,15 +105,19 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
|
|||
ConsoleCli.exec(command, GlobalData.consoleCliConfig) match {
|
||||
case Success(commandReturn) =>
|
||||
resultArea.text = postProcessStr(commandReturn)
|
||||
promise.success(commandReturn)
|
||||
case Failure(err) =>
|
||||
err.printStackTrace()
|
||||
resultArea.text = s"Error executing command:\n${err.getMessage}"
|
||||
promise.success("")
|
||||
}
|
||||
updateDLCs()
|
||||
}
|
||||
)
|
||||
case None => ()
|
||||
case None => promise.success("")
|
||||
}
|
||||
|
||||
Await.result(promise.future, 15.seconds)
|
||||
}
|
||||
|
||||
def onOffer(): Unit = {
|
||||
|
@ -211,11 +218,11 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
|
|||
}
|
||||
}
|
||||
|
||||
def onExecute(): Unit = {
|
||||
def onExecute(): String = {
|
||||
printDLCDialogResult("ExecuteDLC", new ExecuteDLCDialog)
|
||||
}
|
||||
|
||||
def onRefund(): Unit = {
|
||||
def onRefund(): String = {
|
||||
printDLCDialogResult("ExecuteDLCRefund", new RefundDLCDialog)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package org.bitcoins.gui.dlc.dialog
|
||||
|
||||
import org.bitcoins.core.protocol.dlc.models.DLCStatus.Offered
|
||||
import org.bitcoins.core.protocol.dlc.models.DLCStatus._
|
||||
import org.bitcoins.core.protocol.dlc.models._
|
||||
import org.bitcoins.core.protocol.tlv.{
|
||||
EnumOutcome,
|
||||
SignedNumericOutcome,
|
||||
UnsignedNumericOutcome
|
||||
}
|
||||
import org.bitcoins.gui.GlobalData
|
||||
import org.bitcoins.gui._
|
||||
import org.bitcoins.gui.dlc.{DLCPaneModel, DLCPlotUtil, GlobalDLCData}
|
||||
import org.bitcoins.gui.util.GUIUtil
|
||||
import scalafx.Includes._
|
||||
import scalafx.beans.property.StringProperty
|
||||
import scalafx.geometry.Insets
|
||||
import scalafx.scene.Node
|
||||
import scalafx.scene.control._
|
||||
|
@ -28,6 +29,9 @@ object ViewDLCDialog {
|
|||
title = "View DLC"
|
||||
}
|
||||
|
||||
val closingTxId: StringProperty = StringProperty(
|
||||
DLCStatus.getClosingTxId(status).map(_.hex).getOrElse(""))
|
||||
|
||||
dialog.dialogPane().buttonTypes = Seq(ButtonType.Close)
|
||||
dialog.dialogPane().stylesheets = GlobalData.currentStyleSheets
|
||||
dialog.resizable = true
|
||||
|
@ -185,7 +189,7 @@ object ViewDLCDialog {
|
|||
row += 1
|
||||
add(new Label("Closing TxId:"), 0, row)
|
||||
add(new TextField() {
|
||||
text = DLCStatus.getClosingTxId(status).map(_.hex).getOrElse("")
|
||||
text <== closingTxId
|
||||
editable = false
|
||||
},
|
||||
columnIndex = 1,
|
||||
|
@ -210,7 +214,10 @@ object ViewDLCDialog {
|
|||
// Set data for this DLC
|
||||
GlobalDLCData.lastContractId = contractId
|
||||
GlobalDLCData.lastOracleSig = ""
|
||||
model.onExecute()
|
||||
val res = model.onExecute()
|
||||
|
||||
// Set closing txId in GUI
|
||||
closingTxId.value = res
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue