Skip to content

Commit

Permalink
BATM-5013 - LND sendpayment should contain remote transaction id (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
SMaros authored Oct 23, 2023
1 parent 3727194 commit 4776364
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -111,6 +113,14 @@ private Payment.FeeLimit getFeeLimit(String fee) {
return feeLimit;
}

private static Map<Long, byte[]> getCustomRecords(String description) {
Map<Long, byte[]> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Long, byte[]> dest_custom_records;

public static class FeeLimit {
/**
* The fee limit expressed as a fixed amount of satoshis
Expand All @@ -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 + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 4776364

Please sign in to comment.