From 4776364c82494c67cd1b94468b6661aa6c4761ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maro=C5=A1=20Silady?= <38668012+SMaros@users.noreply.github.com> Date: Mon, 23 Oct 2023 08:38:01 +0200 Subject: [PATCH] BATM-5013 - LND sendpayment should contain remote transaction id (#849) --- .../lightningbitcoin/wallets/lnd/LndWallet.java | 10 ++++++++++ .../wallets/lnd/dto/Payment.java | 17 ++++++++++++++++- .../wallets/lnd/LndWalletTest.java | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWallet.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWallet.java index 69c7f962d..0471730ec 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWallet.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWallet.java @@ -39,6 +39,7 @@ import java.net.ConnectException; import java.security.GeneralSecurityException; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -81,6 +82,7 @@ public String sendCoins(String destinationAddress, BigDecimal amount, String cry payment.amt = CoinUnit.bitcoinToSat(amount).toString(); payment.payment_request = destinationAddress; payment.fee_limit = getFeeLimit(feeLimit); + payment.dest_custom_records = getCustomRecords(description); log.info("Sending payment: {}", payment); SendPaymentResponse paymentResponse = callChecked(() -> api.sendPayment(payment)); @@ -111,6 +113,14 @@ private Payment.FeeLimit getFeeLimit(String fee) { return feeLimit; } + private static Map getCustomRecords(String description) { + Map customRecords = new HashMap<>(); + if (description != null && !description.trim().isEmpty()) { + customRecords.put(1L, description.getBytes()); + } + return customRecords; + } + @Override public String getInvoice(BigDecimal cryptoAmount, String cryptoCurrency, Long paymentValidityInSec, String description) { Invoice invoice = new Invoice(); diff --git a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/dto/Payment.java b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/dto/Payment.java index 74cb8c4b4..f14ef05fe 100644 --- a/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/dto/Payment.java +++ b/server_extensions_extra/src/main/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/dto/Payment.java @@ -17,6 +17,9 @@ ************************************************************************************/ package com.generalbytes.batm.server.extensions.extra.lightningbitcoin.wallets.lnd.dto; +import java.nio.charset.StandardCharsets; +import java.util.Map; + public class Payment { /** * A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient @@ -34,6 +37,14 @@ public class Payment { */ public FeeLimit fee_limit; + /** + * An optional field that can be used to pass an arbitrary set of TLV records to a peer which understands the new records. + * This can be used to pass application specific data during the payment attempt. + * Record types are required to be in the custom range >= 65536. + * When using REST, the values must be encoded as base64. + */ + public Map dest_custom_records; + public static class FeeLimit { /** * The fee limit expressed as a fixed amount of satoshis @@ -52,6 +63,10 @@ public String toString() { @Override public String toString() { - return "Payment{" + amt + " sat, fee limit: " + fee_limit + " to " + payment_request + '}'; + String rid = ""; + if (dest_custom_records != null && !dest_custom_records.containsKey(1L)) { + rid = new String(dest_custom_records.get(1L), StandardCharsets.UTF_8); + } + return "Payment{" + amt + " sat, fee limit: " + fee_limit + " to " + payment_request + ", rid: " + rid + '}'; } } diff --git a/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWalletTest.java b/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWalletTest.java index a08ab3057..84a1c7ab7 100644 --- a/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWalletTest.java +++ b/server_extensions_extra/src/test/java/com/generalbytes/batm/server/extensions/extra/lightningbitcoin/wallets/lnd/LndWalletTest.java @@ -21,7 +21,7 @@ public LndWalletTest() throws GeneralSecurityException { public void sendCoins() { IWalletInformation i = w.getWalletInformation(); String paymentHash = w.sendCoins("LNBC1U1PWJMJJNPP5YRDV8EPPK74UZ69QVHK940EHE9469H8GHXE626MZGCLZ202REZKQDPY2PKXZ7FQVYSXWCTDV5SX7E3QWD3HYCT5VD5QCQZPGQNL8L0227LDNLEJA3HQWUFHF788ADMD640YKFZ8A9FAGYG4RQE7XGC4CXFMTVU8SAWPE3WVU8WNUHW52R6LSD4797RZ0DPMPTHH3K0CQ378HK2", - new BigDecimal("0.000001"), CryptoCurrency.LBTC.getCode(), ""); + new BigDecimal("0.000001"), CryptoCurrency.LBTC.getCode(), "R23V4C"); System.out.println(paymentHash); }