Remove unused AcceptDLCDialog file (#3158)

* Remove unused AcceptDLCDialog file

* Remove others
This commit is contained in:
benthecarman 2021-05-27 05:13:37 -07:00 committed by GitHub
parent 180d7dfcd3
commit 521a1e2555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 585 deletions

View File

@ -1,92 +0,0 @@
package org.bitcoins.gui.dlc.dialog
import org.bitcoins.cli.CliCommand._
import org.bitcoins.core.protocol.dlc.models.{OracleInfo, SingleOracleInfo}
import org.bitcoins.core.protocol.tlv._
import scalafx.scene.Node
import scalafx.scene.control.Alert.AlertType
import scalafx.scene.control.{Alert, ButtonType, TextField}
class AcceptDLCDialog
extends DLCDialog[AcceptDLCCliCommand](
"Accept DLC Offer",
"Enter DLC Offer to accept or open from file",
Vector(
DLCDialog.dlcOfferStr -> DLCDialog.textArea(),
DLCDialog.dlcOfferFileStr -> DLCDialog.fileChooserButton(
open = true,
file => {
DLCDialog.offerDLCFile = Some(file)
DLCDialog.offerFileChosenLabel.text = file.toString
}),
DLCDialog.fileChosenStr -> DLCDialog.offerFileChosenLabel,
DLCDialog.dlcAcceptFileDestStr -> DLCDialog.fileChooserButton(
open = false,
file => {
DLCDialog.acceptDestDLCFile = Some(file)
DLCDialog.acceptDestFileChosenLabel.text = file.toString
}),
DLCDialog.fileChosenStr -> DLCDialog.acceptDestFileChosenLabel,
DLCDialog.oracleAnnouncementsStr -> new TextField() {
promptText = "(optional)"
}
),
Vector(DLCDialog.dlcOfferStr,
DLCDialog.dlcOfferFileStr,
DLCDialog.dlcAcceptFileDestStr,
DLCDialog.oracleAnnouncementsStr)) {
import DLCDialog._
def validateMatchingAnnouncements(
offer: LnMessage[DLCOfferTLV],
announcements: Vector[OracleAnnouncementTLV]): Boolean = {
val fromOffer = OracleInfo.fromTLV(offer.tlv.contractInfo.oracleInfo)
val singles = announcements.map(SingleOracleInfo(_))
singles.forall(an => fromOffer.singleOracleInfos.contains(an))
}
override def constructFromInput(
inputs: Map[String, Node]): AcceptDLCCliCommand = {
offerDLCFile match {
case Some(file) =>
// TODO figure how to validate when using a file
offerDLCFile = None // reset
offerFileChosenLabel.text = "" // reset
val destPathOpt = acceptDestDLCFile
acceptDestDLCFile = None // reset
acceptDestFileChosenLabel.text = "" // reset
AcceptDLCOfferFromFile(file.toPath, destPathOpt.map(_.toPath))
case None =>
val offerHex = readStringFromNode(inputs(dlcOfferStr))
val offer = LnMessageFactory(DLCOfferTLV).fromHex(offerHex)
val announcementsHex = readStringFromNode(
inputs(oracleAnnouncementsStr))
if (announcementsHex.nonEmpty) {
val announcements =
announcementsHex.split(",").map(OracleAnnouncementTLV.fromHex)
if (!validateMatchingAnnouncements(offer, announcements.toVector)) {
throw new RuntimeException(
"Offer given does not have the same oracle info as announcement!")
}
} else {
new Alert(AlertType.Confirmation) {
resizable = true
initOwner(owner)
title = "Confirm no Oracle Announcement"
contentText =
s"Are you sure you would like sign to accept this DLC Offer without verifying it has the correct oracle?"
dialogPane().getScene.getWindow.sizeToScene()
}.showAndWait() match {
case Some(ButtonType.OK) => ()
case None | Some(_) => throw new RuntimeException("Did not accept")
}
}
AcceptDLCOffer(offer)
}
}
}

View File

@ -1,117 +0,0 @@
package org.bitcoins.gui.dlc.dialog
import org.bitcoins.core.currency.Satoshis
import org.bitcoins.core.protocol.dlc.models.EnumContractDescriptor
import org.bitcoins.core.protocol.tlv._
import org.bitcoins.gui.GlobalData
import org.bitcoins.gui.util.GUIUtil.setNumericInput
import scalafx.Includes._
import scalafx.geometry.{Insets, Pos}
import scalafx.scene.control._
import scalafx.scene.layout._
import scalafx.stage.Window
import scala.collection._
object InitEnumContractDialog {
def showAndWait(parentWindow: Window): Option[
(EnumContractDescriptor, Option[OracleAnnouncementTLV])] = {
val dialog =
new Dialog[
Option[(EnumContractDescriptor, Option[OracleAnnouncementTLV])]]() {
initOwner(parentWindow)
title = "Initialize Demo Oracle"
headerText = "Enter contract outcomes and their outcome values"
}
dialog.dialogPane().buttonTypes = Seq(ButtonType.OK, ButtonType.Cancel)
dialog.dialogPane().stylesheets = GlobalData.currentStyleSheets
dialog.resizable = true
val fields: mutable.Map[Int, (TextField, TextField)] = mutable.Map.empty
val announcementTF = new TextField() {
promptText = "(optional)"
}
var nextRow: Int = 2
val gridPane = new GridPane {
alignment = Pos.Center
padding = Insets(top = 10, right = 10, bottom = 10, left = 10)
hgap = 5
vgap = 5
add(new Label("Announcement"), 0, 0)
add(announcementTF, 1, 0)
add(new Label("Outcomes"), 0, 1)
add(new Label("Values"), 1, 1)
}
def addOutcomeRow(): Unit = {
val outcomeTF = new TextField()
val amtTF = new TextField() {
promptText = "Satoshis"
}
setNumericInput(amtTF)
val row = nextRow
val _ = fields.put(row, (outcomeTF, amtTF))
gridPane.add(outcomeTF, 0, row)
gridPane.add(amtTF, 1, row)
nextRow += 1
dialog.dialogPane().getScene.getWindow.sizeToScene()
}
addOutcomeRow()
addOutcomeRow()
val addPointButton: Button = new Button("+ Outcome") {
onAction = _ => addOutcomeRow()
}
val bottom = new HBox() {
spacing = 10
alignment = Pos.BottomRight
children = Vector(addPointButton)
}
dialog.dialogPane().content = new VBox(gridPane, bottom)
// When the OK button is clicked, convert the result to a CreateDLCOffer.
dialog.resultConverter = dialogButton =>
if (dialogButton == ButtonType.OK) {
val inputs = fields.values.flatMap { case (str, value) =>
if (str.text.value.nonEmpty && value.text.value.nonEmpty)
Some((str.text(), value.text()))
else None
}
val contractMap = inputs.map { case (str, value) =>
EnumOutcome(str) -> Satoshis(BigInt(value))
}.toVector
val announcementStr = announcementTF.text.value
val announcementOpt = if (announcementStr.nonEmpty) {
Some(OracleAnnouncementTLV(announcementStr))
} else None
Some((EnumContractDescriptor(contractMap), announcementOpt))
} else None
val result = dialog.showAndWait()
result match {
case Some(
Some(
(contractInfo: EnumContractDescriptor,
announcementOpt: Option[_]))) =>
Some(
(contractInfo,
announcementOpt.asInstanceOf[Option[OracleAnnouncementTLV]]))
case Some(_) | None => None
}
}
}

View File

@ -1,339 +0,0 @@
package org.bitcoins.gui.dlc.dialog
import org.bitcoins.core.currency.Satoshis
import org.bitcoins.core.protocol.dlc.models.{
DLCPayoutCurve,
NumericContractDescriptor,
OutcomePayoutPoint,
RoundingIntervals
}
import org.bitcoins.core.protocol.tlv.OracleAnnouncementTLV
import org.bitcoins.gui.GlobalData
import org.bitcoins.gui.dlc.DLCPlotUtil
import org.bitcoins.gui.util.GUIUtil.setNumericInput
import scalafx.Includes._
import scalafx.application.Platform
import scalafx.geometry.{Insets, Pos}
import scalafx.scene.Node
import scalafx.scene.control._
import scalafx.scene.layout.{GridPane, HBox, VBox}
import scalafx.stage.Window
import scala.util.{Failure, Success, Try}
object InitNumericContractDialog {
def showAndWait(parentWindow: Window): Option[
(Satoshis, NumericContractDescriptor, Option[OracleAnnouncementTLV])] = {
val dialog =
new Dialog[Option[(
Satoshis,
NumericContractDescriptor,
Option[OracleAnnouncementTLV])]]() {
initOwner(parentWindow)
title = "Initialize Demo Oracle"
headerText = "Enter contract interpolation points"
}
dialog.dialogPane().buttonTypes = Seq(ButtonType.OK, ButtonType.Cancel)
dialog.dialogPane().stylesheets = GlobalData.currentStyleSheets
dialog.resizable = true
val baseTF = new TextField() {
text = "2"
}
val numDigitsTF = new TextField()
val totalCollateralTF = new TextField() {
promptText = "Satoshis"
}
setNumericInput(baseTF)
setNumericInput(numDigitsTF)
setNumericInput(totalCollateralTF)
val announcementTF = new TextField() {
promptText = "(optional)"
}
val pointMap: scala.collection.mutable.Map[
Int,
(TextField, TextField, CheckBox)] =
scala.collection.mutable.Map.empty
var nextPointRow: Int = 2
val pointGrid: GridPane = new GridPane {
alignment = Pos.Center
padding = Insets(top = 10, right = 10, bottom = 10, left = 10)
hgap = 5
vgap = 5
add(new Label("Outcome"), 0, 0)
add(new Label("Payout"), 1, 0)
add(new Label("Endpoint"), 2, 0)
}
def addPointRow(
xOpt: Option[String] = None,
yOpt: Option[String] = None): Unit = {
val xTF = new TextField() {
promptText = "Outcome (base 10)"
}
xOpt match {
case Some(value) =>
xTF.text = value
case None => ()
}
val yTF = new TextField() {
promptText = "Satoshis"
}
yOpt match {
case Some(value) =>
yTF.text = value
case None => ()
}
val endPointBox = new CheckBox() {
selected = true
}
setNumericInput(xTF)
setNumericInput(yTF)
val row = nextPointRow
val _ = pointMap.put(row, (xTF, yTF, endPointBox))
pointGrid.add(xTF, 0, row)
pointGrid.add(yTF, 1, row)
pointGrid.add(new Label("Endpoint:"), 2, row)
pointGrid.add(endPointBox, 3, row)
nextPointRow += 1
dialog.dialogPane().getScene.getWindow.sizeToScene()
}
addPointRow(Some("0"), Some("0"))
addPointRow()
val addPointButton: Button = new Button("+") {
onAction = _ => addPointRow()
}
val roundingMap: scala.collection.mutable.Map[Int, (TextField, TextField)] =
scala.collection.mutable.Map.empty
var nextRoundingRow: Int = 2
val roundingGrid: GridPane = new GridPane {
alignment = Pos.Center
padding = Insets(top = 10, right = 10, bottom = 10, left = 10)
hgap = 5
vgap = 5
add(new Label("Outcome"), 0, 0)
add(new Label("Rounding Level"), 1, 0)
}
def addRoundingRow(): Unit = {
val outcomeTF = new TextField() {
promptText = "Outcome (base 10)"
}
val roundingLevelTF = new TextField() {
promptText = "Satoshis"
}
setNumericInput(outcomeTF)
setNumericInput(roundingLevelTF)
val row = nextRoundingRow
val _ = roundingMap.put(row, (outcomeTF, roundingLevelTF))
roundingGrid.add(outcomeTF, 0, row)
roundingGrid.add(roundingLevelTF, 1, row)
nextRoundingRow += 1
dialog.dialogPane().getScene.getWindow.sizeToScene()
}
addRoundingRow()
addRoundingRow()
val addRoundingRowButton: Button = new Button("+") {
onAction = _ => addRoundingRow()
}
def getContractInfo: Try[(Satoshis, NumericContractDescriptor)] = {
Try {
val numDigits = numDigitsTF.text.value.toInt
val totalCollateral = Satoshis(totalCollateralTF.text.value.toLong)
val points = pointMap.values.toVector
val outcomesValuePoints = points.flatMap { case (xTF, yTF, checkBox) =>
if (xTF.text.value.nonEmpty && yTF.text.value.nonEmpty) {
val x = xTF.text.value.toLong
val y = yTF.text.value.toLong
Some(OutcomePayoutPoint(x, Satoshis(y), checkBox.selected.value))
} else {
None
}
}
val roundingIntervalStartsTF = roundingMap.values.toVector
val roundingIntervalsStarts = roundingIntervalStartsTF.flatMap {
case (outcomeTF, roundingModTF) =>
if (
outcomeTF.text.value.nonEmpty && roundingModTF.text.value.nonEmpty
) {
val outcome = outcomeTF.text.value.toLong
val roundingMod = roundingModTF.text.value.toLong
Some(
RoundingIntervals.IntervalStart(BigDecimal(outcome),
roundingMod))
} else None
}
val sorted = outcomesValuePoints.sortBy(_.outcome)
require(sorted == outcomesValuePoints, "Must be sorted by outcome")
val func = DLCPayoutCurve(outcomesValuePoints)
(totalCollateral,
NumericContractDescriptor(func,
numDigits,
RoundingIntervals(roundingIntervalsStarts)))
}
}
def getRoundingIntervals: RoundingIntervals = {
val roundingIntervalsT = Try {
roundingMap.values.toVector.flatMap {
case (outcomeTF, roundingLevelTF) =>
if (
outcomeTF.text.value.nonEmpty && roundingLevelTF.text.value.nonEmpty
) {
val outcome = BigDecimal(outcomeTF.text.value.toDouble)
val level = roundingLevelTF.text.value.toLong
Some((outcome, level))
} else {
None
}
}
}
roundingIntervalsT match {
case Failure(_) => RoundingIntervals.noRounding
case Success(intervals) =>
RoundingIntervals(intervals.map { case (firstOutcome, roundingMod) =>
RoundingIntervals.IntervalStart(firstOutcome, roundingMod)
})
}
}
val vBoxContent: VBox = new VBox() {
padding = Insets(20, 10, 10, 10)
spacing = 10
alignment = Pos.Center
val eventDataGrid: GridPane = new GridPane {
padding = Insets(top = 10, right = 10, bottom = 10, left = 10)
hgap = 5
vgap = 5
add(new Label("Base"), 0, 0)
add(baseTF, 1, 0)
add(new Label("Num Digits"), 0, 1)
add(numDigitsTF, 1, 1)
add(new Label("Total Collateral"), 0, 2)
add(totalCollateralTF, 1, 2)
add(new Label("Announcement"), 0, 3)
add(announcementTF, 1, 3)
}
val outcomes: Node = new VBox {
alignment = Pos.Center
val label: HBox = new HBox {
alignment = Pos.Center
spacing = 10
children = Vector(new Label("Points"), addPointButton)
}
children = Vector(label, pointGrid)
}
val roundingIntervals: VBox = new VBox {
alignment = Pos.Center
val label: HBox = new HBox {
alignment = Pos.Center
spacing = 10
children =
Vector(new Label("Rounding Intervals"), addRoundingRowButton)
}
children = Vector(label, roundingGrid)
}
val roundingPane: TitledPane = new TitledPane() {
text = "Rounding Info"
content = roundingIntervals
}
val roundingAccordion: Accordion = new Accordion() {
panes = Vector(roundingPane)
}
val previewGraphButton: Button = new Button("Preview Graph") {
onAction = _ => {
getContractInfo match {
case Failure(_) => ()
case Success((totalCollateral, descriptor)) =>
DLCPlotUtil.plotCETsWithOriginalCurve(base = 2,
descriptor.numDigits,
descriptor.outcomeValueFunc,
totalCollateral,
getRoundingIntervals)
()
}
}
}
children = Vector(eventDataGrid,
new Separator(),
outcomes,
roundingAccordion,
previewGraphButton)
}
dialog.dialogPane().content = new ScrollPane() {
content = vBoxContent
}
// Enable/Disable OK button depending on whether all data was entered.
val okButton = dialog.dialogPane().lookupButton(ButtonType.OK)
// Simple validation that sufficient data was entered
okButton.disable <== baseTF.text.isEmpty || totalCollateralTF.text.isEmpty
Platform.runLater(numDigitsTF.requestFocus())
// When the OK button is clicked, convert the result to a CreateDLCOffer.
dialog.resultConverter = dialogButton =>
if (dialogButton == ButtonType.OK) {
getContractInfo match {
case Failure(exception) => throw exception
case Success((sats, contractInfo)) =>
val announcementStr = announcementTF.text.value
val announcementOpt = if (announcementStr.nonEmpty) {
Some(OracleAnnouncementTLV(announcementStr))
} else None
Some((sats, contractInfo, announcementOpt))
}
} else None
dialog.showAndWait() match {
case Some(
Some(
(totalCollateral: Satoshis,
descriptor: NumericContractDescriptor,
announcementOpt: Option[_]))) =>
Some(
(totalCollateral,
descriptor,
announcementOpt.asInstanceOf[Option[OracleAnnouncementTLV]]))
case Some(_) | None => None
}
}
}

View File

@ -1,37 +0,0 @@
package org.bitcoins.gui.dlc.dialog
import org.bitcoins.cli.CliCommand.CreateDLCOffer
import org.bitcoins.core.currency.Satoshis
import org.bitcoins.core.number.UInt32
import org.bitcoins.core.protocol.tlv._
import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte
import scalafx.scene.Node
class OfferDLCDialog
extends DLCDialog[CreateDLCOffer]("Create DLC Offer",
"Enter DLC details",
DLCDialog.constructOfferFields(),
Vector(DLCDialog.feeRateStr)) {
import DLCDialog._
override def constructFromInput(inputs: Map[String, Node]): CreateDLCOffer = {
val feeRate = if (readStringFromNode(inputs(feeRateStr)).isEmpty) {
None
} else {
Some(
SatoshisPerVirtualByte(
Satoshis(BigInt(readStringFromNode(inputs(feeRateStr))))
)
)
}
CreateDLCOffer(
contractInfo =
ContractInfoV0TLV.fromHex(readStringFromNode(inputs(contractInfoStr))),
collateral = Satoshis(BigInt(readStringFromNode(inputs(collateralStr)))),
feeRateOpt = feeRate,
locktime = UInt32.zero,
refundLT = UInt32(BigInt(readStringFromNode(inputs(refundLocktimeStr))))
)
}
}