Implement rebroadcast closing tx (#3564)

* Implement rebroadcast closing tx

* Add minWidth to Rebroadcast buttons
This commit is contained in:
user411 2021-08-17 11:16:46 -06:00 committed by GitHub
parent 7f7bc1f4bf
commit b545915fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 35 deletions

View File

@ -5,6 +5,7 @@ import org.bitcoins.cli.CliCommand._
import org.bitcoins.cli.{CliCommand, ConsoleCli}
import org.bitcoins.commons.serializers.Picklers._
import org.bitcoins.core.protocol.dlc.models._
import org.bitcoins.core.protocol.transaction.Transaction
import org.bitcoins.core.util.FutureUtil
import org.bitcoins.crypto._
import org.bitcoins.gui._
@ -297,10 +298,7 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
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 Success(_) => logger.info(s"Successfully rebroadcast funding tx")
case Failure(err) => throw err
}
}
@ -308,27 +306,29 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext)
}
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")
DLCStatus.getClosingTxId(status) match {
case Some(txId) =>
taskRunner.run(
"Rebroadcast Funding Tx",
op = {
ConsoleCli.exec(GetTransaction(txId),
GlobalData.consoleCliConfig) match {
case Success(tx) => {
val t = Transaction.fromHex(tx)
logger.info(s"Successfully found closing tx")
ConsoleCli.exec(SendRawTransaction(t),
GlobalData.consoleCliConfig) match {
case Success(_) =>
logger.info(s"Successfully rebroadcast closing tx")
case Failure(err) => throw err
}
}
case Failure(err) => throw err
}
}
)
case None => ()
}
}
def exportResult(result: String): Unit = {

View File

@ -53,14 +53,6 @@ object ViewDLCDialog {
}
}
// 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(
DLCStatus.getClosingTxId(status).map(_.hex).getOrElse(""))
@ -164,6 +156,7 @@ object ViewDLCDialog {
hgrow = Priority.Always
},
new Button("Rebroadcast") {
minWidth = 90
disable = !DLCStatus.getFundingTxId(status).isDefined
onAction = _ => {
DLCStatus.getContractId(status) match {
@ -187,8 +180,8 @@ object ViewDLCDialog {
hgrow = Priority.Always
},
new Button("Rebroadcast") {
disable =
true // Until operation is supported, correct value = closingTxId.isEmpty.getValue
minWidth = 90
disable = closingTxId.isEmpty.getValue
onAction = _ => {
model.rebroadcastClosingTx(status)
}