2021 08 17 rebroadcast funding tx (#3561)

* Add check for valid broadcast states

* Add rebroadcast funding tx button

* remove printlns

* Add status to error message to get compile working

* println -> logger.info

Co-authored-by: Ivan <erickson.ivan@gmail.com>
This commit is contained in:
Chris Stewart 2021-08-17 08:41:55 -05:00 committed by GitHub
parent 706c9fe961
commit 7cd21edb12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 13 deletions

View file

@ -16,6 +16,7 @@ import scalafx.scene.control.Alert.AlertType
import scalafx.scene.control.{Alert, ButtonType, TextArea}
import scalafx.stage.FileChooser.ExtensionFilter
import scalafx.stage.{FileChooser, Window}
import scodec.bits.ByteVector
import upickle.default._
import java.io.File
@ -290,6 +291,46 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
}
}
def rebroadcastFundingTx(contractId: ByteVector): Unit = {
taskRunner.run(
"Rebroadcast Funding Tx",
op = {
ConsoleCli.exec(BroadcastDLCFundingTx(contractId),
GlobalData.consoleCliConfig) match {
case Success(_) => {
logger.info(s"Successfully rebroadcast funding tx")
// TODO : Want to show Alert or success data in view
}
case Failure(err) => throw err
}
}
)
}
def rebroadcastClosingTx(status: DLCStatus): Unit = {
// (DLCStatus.getContractId(status), getOracleSignatures(status)) match {
// case (Some(contractId), Some(sigs)) =>
// taskRunner.run(
// "Rebroadcast Closing Tx",
// op = {
// // TODO : Where do these sigs come from?
// println("Rebroadcasting " + contractId + " sigs: " + sigs)
// ConsoleCli.exec(ExecuteDLC(contractId, sigs, false),
// GlobalData.consoleCliConfig) match {
// case Success(_) => {
// println("Rebroadcast Closing Tx Success")
// }
// case Failure(err) => throw err
// }
// }
// )
// case _ => // Nothing to do
// }
sys.error(
s"Rebroadcasting of closing transaction is not implemented yet, status=$status")
}
def exportResult(result: String): Unit = {
val txtFilter = new ExtensionFilter("Text Files", "*.txt")
val allExtensionFilter = new ExtensionFilter("All Files", "*")

View file

@ -15,7 +15,7 @@ import scalafx.beans.property.StringProperty
import scalafx.geometry.{Insets, Pos}
import scalafx.scene.Node
import scalafx.scene.control._
import scalafx.scene.layout.GridPane
import scalafx.scene.layout.{GridPane, HBox, Priority}
import scalafx.stage.Window
object ViewDLCDialog {
@ -53,13 +53,13 @@ object ViewDLCDialog {
}
}
private def getTextField(property: StringProperty): TextField = {
new TextField {
styleClass += "view-dlc-textfield"
text <== property
editable = false
}
}
// private def getTextField(property: StringProperty): TextField = {
// new TextField {
// styleClass += "view-dlc-textfield"
// text <== property
// editable = false
// }
// }
def buildView(status: DLCStatus, model: DLCPaneModel) = {
val closingTxId: StringProperty = StringProperty(
@ -155,15 +155,48 @@ object ViewDLCDialog {
rowIndex = row)
row += 1
// TODO : Status filtering for showing this view vs just the TextField
val fundingHBox = new HBox() {
children = Seq(
new TextField {
text = DLCStatus.getFundingTxId(status).map(_.hex).getOrElse("")
editable = false
hgrow = Priority.Always
},
new Button("Rebroadcast") {
disable = !DLCStatus.getFundingTxId(status).isDefined
onAction = _ => {
DLCStatus.getContractId(status) match {
case Some(contractId) => model.rebroadcastFundingTx(contractId)
case None => // Nothing to do
}
}
}
)
}
add(getLabel("Funding TxId"), 0, row)
add(
getTextField(DLCStatus.getFundingTxId(status).map(_.hex).getOrElse("")),
columnIndex = 1,
rowIndex = row)
add(fundingHBox, columnIndex = 1, rowIndex = row)
row += 1
// TODO : Status filtering for showing this view vs just the TextField
val closingHBox = new HBox {
children = Seq(
new TextField() {
text <== closingTxId
editable = false
hgrow = Priority.Always
},
new Button("Rebroadcast") {
disable =
true // Until operation is supported, correct value = closingTxId.isEmpty.getValue
onAction = _ => {
model.rebroadcastClosingTx(status)
}
}
)
}
add(getLabel("Closing TxId"), 0, row)
add(getTextField(closingTxId), columnIndex = 1, rowIndex = row)
add(closingHBox, columnIndex = 1, rowIndex = row)
row += 1
add(getLabel("Oracle Signatures"), 0, row)