1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 10:39:19 +01:00

Include payment preimage in PaymentSent event (#374)

Payment preimage is important for the sender of the payment as it proves
that he actually paid the request. It must then be available from the
`PaymentSent` event.

(gui) Payment preimage column is added to the 'payments sent' table in Activity tab
This commit is contained in:
Dominique 2018-01-22 16:10:17 +01:00 committed by GitHub
parent 1db673a631
commit aa90f94304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 5 deletions

View File

@ -9,7 +9,7 @@ sealed trait PaymentEvent {
val paymentHash: BinaryData
}
case class PaymentSent(amount: MilliSatoshi, feesPaid: MilliSatoshi, paymentHash: BinaryData) extends PaymentEvent
case class PaymentSent(amount: MilliSatoshi, feesPaid: MilliSatoshi, paymentHash: BinaryData, paymentPreimage: BinaryData) extends PaymentEvent
case class PaymentRelayed(amountIn: MilliSatoshi, amountOut: MilliSatoshi, paymentHash: BinaryData) extends PaymentEvent

View File

@ -73,7 +73,7 @@ class PaymentLifecycle(sourceNodeId: PublicKey, router: ActorRef, register: Acto
case Event(fulfill: UpdateFulfillHtlc, w: WaitingForComplete) =>
w.sender ! PaymentSucceeded(w.hops, fulfill.paymentPreimage)
context.system.eventStream.publish(PaymentSent(MilliSatoshi(w.c.amountMsat), MilliSatoshi(w.cmd.amountMsat - w.c.amountMsat), w.cmd.paymentHash))
context.system.eventStream.publish(PaymentSent(MilliSatoshi(w.c.amountMsat), MilliSatoshi(w.cmd.amountMsat - w.c.amountMsat), w.cmd.paymentHash, fulfill.paymentPreimage))
stop(FSM.Normal)
case Event(fail: UpdateFailHtlc, WaitingForComplete(s, c, _, failures, sharedSecrets, ignoreNodes, ignoreChannels, hops)) =>

View File

@ -177,8 +177,8 @@ class PaymentLifecycleSpec extends BaseRouterSpec {
sender.send(paymentFSM, UpdateFulfillHtlc("00" * 32, 0, "42" * 32))
sender.expectMsgType[PaymentSucceeded]
val PaymentSent(MilliSatoshi(request.amountMsat), feesPaid, request.paymentHash) = eventListener.expectMsgType[PaymentSent]
val paymentOK = sender.expectMsgType[PaymentSucceeded]
val PaymentSent(MilliSatoshi(request.amountMsat), feesPaid, request.paymentHash, paymentOK.paymentPreimage) = eventListener.expectMsgType[PaymentSent]
assert(feesPaid.amount > 0)
}

View File

@ -111,6 +111,8 @@
maxWidth="150.0"/>
<TableColumn fx:id="paymentSentHashColumn"
text="Payment Hash"/>
<TableColumn fx:id="paymentSentPreimageColumn"
text="Payment Preimage"/>
</columns>
</TableView>
</Tab>

View File

@ -99,6 +99,7 @@ class MainController(val handlers: Handlers, val hostServices: HostServices) ext
@FXML var paymentSentAmountColumn: TableColumn[PaymentSentRecord, Number] = _
@FXML var paymentSentFeesColumn: TableColumn[PaymentSentRecord, Number] = _
@FXML var paymentSentHashColumn: TableColumn[PaymentSentRecord, String] = _
@FXML var paymentSentPreimageColumn: TableColumn[PaymentSentRecord, String] = _
@FXML var paymentSentDateColumn: TableColumn[PaymentSentRecord, String] = _
// payment received table
@ -270,8 +271,11 @@ class MainController(val handlers: Handlers, val hostServices: HostServices) ext
def call(record: TableColumn[PaymentSentRecord, Number]) = buildMoneyTableCell
})
paymentSentHashColumn.setCellValueFactory(paymentHashCellValueFactory)
paymentSentPreimageColumn.setCellValueFactory(new Callback[CellDataFeatures[PaymentSentRecord, String], ObservableValue[String]]() {
def call(p: CellDataFeatures[PaymentSentRecord, String]) = new SimpleStringProperty(p.getValue.event.paymentPreimage.toString())
})
paymentSentDateColumn.setCellValueFactory(paymentDateCellValueFactory)
paymentSentTable.setRowFactory(paymentRowFactory)
paymentSentTable.setRowFactory(paymentSentRowFactory)
// init payment received
paymentReceivedTable.setItems(paymentReceivedList)
@ -371,6 +375,30 @@ class MainController(val handlers: Handlers, val hostServices: HostServices) ext
def call(p: CellDataFeatures[T, String]) = new SimpleStringProperty(p.getValue.date.format(PAYMENT_DATE_FORMAT))
}
private def paymentSentRowFactory = new Callback[TableView[PaymentSentRecord], TableRow[PaymentSentRecord]]() {
override def call(table: TableView[PaymentSentRecord]): TableRow[PaymentSentRecord] = {
val row = new TableRow[PaymentSentRecord]
val rowContextMenu = new ContextMenu
val copyHash = new MenuItem("Copy Payment Hash")
copyHash.setOnAction(new EventHandler[ActionEvent] {
override def handle(event: ActionEvent): Unit = Option(row.getItem) match {
case Some(p) => ContextMenuUtils.copyToClipboard(p.event.paymentHash.toString)
case None =>
}
})
val copyPreimage = new MenuItem("Copy Payment Preimage")
copyPreimage.setOnAction(new EventHandler[ActionEvent] {
override def handle(event: ActionEvent): Unit = Option(row.getItem) match {
case Some(p) => ContextMenuUtils.copyToClipboard(p.event.paymentPreimage.toString)
case None =>
}
})
rowContextMenu.getItems.addAll(copyHash, copyPreimage)
row.setContextMenu(rowContextMenu)
row
}
}
private def paymentRowFactory[T <: Record] = new Callback[TableView[T], TableRow[T]]() {
override def call(table: TableView[T]): TableRow[T] = {
val row = new TableRow[T]