Set closing txid on execute from View Dialog (#3340)

This commit is contained in:
benthecarman 2021-06-29 12:28:35 -05:00 committed by GitHub
parent cc1cfe6594
commit 53cafa7898
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 13 deletions

View file

@ -72,8 +72,9 @@ class DLCPane(glassPane: VBox)(implicit ec: ExecutionContext) {
private val refundButton = new Button { private val refundButton = new Button {
text = "Refund" text = "Refund"
onAction = new EventHandler[ActionEvent] { onAction = _ => {
override def handle(event: ActionEvent): Unit = model.onRefund() model.onRefund()
()
} }
tooltip = Tooltip( tooltip = Tooltip(
"After the refund timeout, broadcasts the refund transaction to the blockchain.") "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 { private val executeButton = new Button {
text = "Execute" text = "Execute"
onAction = new EventHandler[ActionEvent] { onAction = _ => {
override def handle(event: ActionEvent): Unit = model.onExecute() model.onExecute()
()
} }
tooltip = Tooltip( tooltip = Tooltip(
"Given an oracle attestation, broadcasts the closing transaction to the blockchain.") "Given an oracle attestation, broadcasts the closing transaction to the blockchain.")

View file

@ -20,7 +20,8 @@ import upickle.default._
import java.io.File import java.io.File
import java.nio.file.Files 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} import scala.util.{Failure, Properties, Success}
class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext) class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
@ -91,9 +92,11 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
def printDLCDialogResult[T <: CliCommand]( def printDLCDialogResult[T <: CliCommand](
caption: String, caption: String,
dialog: DLCDialog[T], dialog: DLCDialog[T],
postProcessStr: String => String = str => str): Unit = { postProcessStr: String => String = str => str): String = {
val result = dialog.showAndWait(parentWindow.value) val result = dialog.showAndWait(parentWindow.value)
val promise = Promise[String]()
result match { result match {
case Some(command) => case Some(command) =>
taskRunner.run( taskRunner.run(
@ -102,15 +105,19 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
ConsoleCli.exec(command, GlobalData.consoleCliConfig) match { ConsoleCli.exec(command, GlobalData.consoleCliConfig) match {
case Success(commandReturn) => case Success(commandReturn) =>
resultArea.text = postProcessStr(commandReturn) resultArea.text = postProcessStr(commandReturn)
promise.success(commandReturn)
case Failure(err) => case Failure(err) =>
err.printStackTrace() err.printStackTrace()
resultArea.text = s"Error executing command:\n${err.getMessage}" resultArea.text = s"Error executing command:\n${err.getMessage}"
promise.success("")
} }
updateDLCs() updateDLCs()
} }
) )
case None => () case None => promise.success("")
} }
Await.result(promise.future, 15.seconds)
} }
def onOffer(): Unit = { def onOffer(): Unit = {
@ -211,11 +218,11 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
} }
} }
def onExecute(): Unit = { def onExecute(): String = {
printDLCDialogResult("ExecuteDLC", new ExecuteDLCDialog) printDLCDialogResult("ExecuteDLC", new ExecuteDLCDialog)
} }
def onRefund(): Unit = { def onRefund(): String = {
printDLCDialogResult("ExecuteDLCRefund", new RefundDLCDialog) printDLCDialogResult("ExecuteDLCRefund", new RefundDLCDialog)
} }

View file

@ -1,16 +1,17 @@
package org.bitcoins.gui.dlc.dialog 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.dlc.models._
import org.bitcoins.core.protocol.tlv.{ import org.bitcoins.core.protocol.tlv.{
EnumOutcome, EnumOutcome,
SignedNumericOutcome, SignedNumericOutcome,
UnsignedNumericOutcome UnsignedNumericOutcome
} }
import org.bitcoins.gui.GlobalData import org.bitcoins.gui._
import org.bitcoins.gui.dlc.{DLCPaneModel, DLCPlotUtil, GlobalDLCData} import org.bitcoins.gui.dlc.{DLCPaneModel, DLCPlotUtil, GlobalDLCData}
import org.bitcoins.gui.util.GUIUtil import org.bitcoins.gui.util.GUIUtil
import scalafx.Includes._ import scalafx.Includes._
import scalafx.beans.property.StringProperty
import scalafx.geometry.Insets import scalafx.geometry.Insets
import scalafx.scene.Node import scalafx.scene.Node
import scalafx.scene.control._ import scalafx.scene.control._
@ -28,6 +29,9 @@ object ViewDLCDialog {
title = "View DLC" title = "View DLC"
} }
val closingTxId: StringProperty = StringProperty(
DLCStatus.getClosingTxId(status).map(_.hex).getOrElse(""))
dialog.dialogPane().buttonTypes = Seq(ButtonType.Close) dialog.dialogPane().buttonTypes = Seq(ButtonType.Close)
dialog.dialogPane().stylesheets = GlobalData.currentStyleSheets dialog.dialogPane().stylesheets = GlobalData.currentStyleSheets
dialog.resizable = true dialog.resizable = true
@ -185,7 +189,7 @@ object ViewDLCDialog {
row += 1 row += 1
add(new Label("Closing TxId:"), 0, row) add(new Label("Closing TxId:"), 0, row)
add(new TextField() { add(new TextField() {
text = DLCStatus.getClosingTxId(status).map(_.hex).getOrElse("") text <== closingTxId
editable = false editable = false
}, },
columnIndex = 1, columnIndex = 1,
@ -210,7 +214,10 @@ object ViewDLCDialog {
// Set data for this DLC // Set data for this DLC
GlobalDLCData.lastContractId = contractId GlobalDLCData.lastContractId = contractId
GlobalDLCData.lastOracleSig = "" GlobalDLCData.lastOracleSig = ""
model.onExecute() val res = model.onExecute()
// Set closing txId in GUI
closingTxId.value = res
} }
} }
} }