1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Builds a [`Refund`] for the \"offer for money\" flow.
14 * See [module-level documentation] for usage.
16 * [module-level documentation]: self
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class RefundMaybeWithDerivedMetadataBuilder extends CommonBase {
20 RefundMaybeWithDerivedMetadataBuilder(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.RefundMaybeWithDerivedMetadataBuilder_free(ptr); }
28 long ret = bindings.RefundMaybeWithDerivedMetadataBuilder_clone_ptr(this.ptr);
29 Reference.reachabilityFence(this);
34 * Creates a copy of the RefundMaybeWithDerivedMetadataBuilder
36 public RefundMaybeWithDerivedMetadataBuilder clone() {
37 long ret = bindings.RefundMaybeWithDerivedMetadataBuilder_clone(this.ptr);
38 Reference.reachabilityFence(this);
39 if (ret >= 0 && ret <= 4096) { return null; }
40 org.ldk.structs.RefundMaybeWithDerivedMetadataBuilder ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RefundMaybeWithDerivedMetadataBuilder(null, ret); }
41 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
46 * Creates a new builder for a refund using the [`Refund::payer_id`] for the public node id to
47 * send to if no [`Refund::paths`] are set. Otherwise, it may be a transient pubkey.
49 * Additionally, sets the required (empty) [`Refund::description`], [`Refund::payer_metadata`],
50 * and [`Refund::amount_msats`].
54 * If constructing a [`Refund`] for use with a [`ChannelManager`], use
55 * [`ChannelManager::create_refund_builder`] instead of [`RefundBuilder::new`].
57 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
58 * [`ChannelManager::create_refund_builder`]: crate::ln::channelmanager::ChannelManager::create_refund_builder
60 public static Result_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ of(byte[] metadata, byte[] payer_id, long amount_msats) {
61 long ret = bindings.RefundMaybeWithDerivedMetadataBuilder_new(metadata, InternalUtils.check_arr_len(payer_id, 33), amount_msats);
62 Reference.reachabilityFence(metadata);
63 Reference.reachabilityFence(payer_id);
64 Reference.reachabilityFence(amount_msats);
65 if (ret >= 0 && ret <= 4096) { return null; }
66 Result_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ ret_hu_conv = Result_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
71 * Similar to [`RefundBuilder::new`] except, if [`RefundBuilder::path`] is called, the payer id
72 * is derived from the given [`ExpandedKey`] and nonce. This provides sender privacy by using a
73 * different payer id for each refund, assuming a different nonce is used. Otherwise, the
74 * provided `node_id` is used for the payer id.
76 * Also, sets the metadata when [`RefundBuilder::build`] is called such that it can be used to
77 * verify that an [`InvoiceRequest`] was produced for the refund given an [`ExpandedKey`].
79 * The `payment_id` is encrypted in the metadata and should be unique. This ensures that only
80 * one invoice will be paid for the refund and that payments can be uniquely identified.
82 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
83 * [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
85 public static Result_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ deriving_payer_id(byte[] node_id, org.ldk.structs.ExpandedKey expanded_key, org.ldk.structs.EntropySource entropy_source, long amount_msats, byte[] payment_id) {
86 long ret = bindings.RefundMaybeWithDerivedMetadataBuilder_deriving_payer_id(InternalUtils.check_arr_len(node_id, 33), expanded_key.ptr, entropy_source.ptr, amount_msats, InternalUtils.check_arr_len(payment_id, 32));
87 Reference.reachabilityFence(node_id);
88 Reference.reachabilityFence(expanded_key);
89 Reference.reachabilityFence(entropy_source);
90 Reference.reachabilityFence(amount_msats);
91 Reference.reachabilityFence(payment_id);
92 if (ret >= 0 && ret <= 4096) { return null; }
93 Result_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ ret_hu_conv = Result_RefundMaybeWithDerivedMetadataBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
94 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(expanded_key); };
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
100 * Sets the [`Refund::description`].
102 * Successive calls to this method will override the previous setting.
104 public void description(java.lang.String description) {
105 bindings.RefundMaybeWithDerivedMetadataBuilder_description(this.ptr, description);
106 Reference.reachabilityFence(this);
107 Reference.reachabilityFence(description);
108 if (this != null) { this.ptrs_to.add(this); };
112 * Sets the [`Refund::absolute_expiry`] as seconds since the Unix epoch. Any expiry that has
113 * already passed is valid and can be checked for using [`Refund::is_expired`].
115 * Successive calls to this method will override the previous setting.
117 public void absolute_expiry(long absolute_expiry) {
118 bindings.RefundMaybeWithDerivedMetadataBuilder_absolute_expiry(this.ptr, absolute_expiry);
119 Reference.reachabilityFence(this);
120 Reference.reachabilityFence(absolute_expiry);
121 if (this != null) { this.ptrs_to.add(this); };
125 * Sets the [`Refund::issuer`].
127 * Successive calls to this method will override the previous setting.
129 public void issuer(java.lang.String issuer) {
130 bindings.RefundMaybeWithDerivedMetadataBuilder_issuer(this.ptr, issuer);
131 Reference.reachabilityFence(this);
132 Reference.reachabilityFence(issuer);
133 if (this != null) { this.ptrs_to.add(this); };
137 * Adds a blinded path to [`Refund::paths`]. Must include at least one path if only connected
138 * by private channels or if [`Refund::payer_id`] is not a public node id.
140 * Successive calls to this method will add another blinded path. Caller is responsible for not
141 * adding duplicate paths.
143 public void path(org.ldk.structs.BlindedPath path) {
144 bindings.RefundMaybeWithDerivedMetadataBuilder_path(this.ptr, path.ptr);
145 Reference.reachabilityFence(this);
146 Reference.reachabilityFence(path);
147 if (this != null) { this.ptrs_to.add(path); };
148 if (this != null) { this.ptrs_to.add(this); };
152 * Sets the [`Refund::chain`] of the given [`Network`] for paying an invoice. If not
153 * called, [`Network::Bitcoin`] is assumed.
155 * Successive calls to this method will override the previous setting.
157 public void chain(org.ldk.enums.Network network) {
158 bindings.RefundMaybeWithDerivedMetadataBuilder_chain(this.ptr, network);
159 Reference.reachabilityFence(this);
160 Reference.reachabilityFence(network);
161 if (this != null) { this.ptrs_to.add(this); };
165 * Sets [`Refund::quantity`] of items. This is purely for informational purposes. It is useful
166 * when the refund pertains to a [`Bolt12Invoice`] that paid for more than one item from an
167 * [`Offer`] as specified by [`InvoiceRequest::quantity`].
169 * Successive calls to this method will override the previous setting.
171 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
172 * [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
173 * [`Offer`]: crate::offers::offer::Offer
175 public void quantity(long quantity) {
176 bindings.RefundMaybeWithDerivedMetadataBuilder_quantity(this.ptr, quantity);
177 Reference.reachabilityFence(this);
178 Reference.reachabilityFence(quantity);
179 if (this != null) { this.ptrs_to.add(this); };
183 * Sets the [`Refund::payer_note`].
185 * Successive calls to this method will override the previous setting.
187 public void payer_note(java.lang.String payer_note) {
188 bindings.RefundMaybeWithDerivedMetadataBuilder_payer_note(this.ptr, payer_note);
189 Reference.reachabilityFence(this);
190 Reference.reachabilityFence(payer_note);
191 if (this != null) { this.ptrs_to.add(this); };
195 * Builds a [`Refund`] after checking for valid semantics.
197 public Result_RefundBolt12SemanticErrorZ build() {
198 long ret = bindings.RefundMaybeWithDerivedMetadataBuilder_build(this.ptr);
199 Reference.reachabilityFence(this);
200 if (ret >= 0 && ret <= 4096) { return null; }
201 Result_RefundBolt12SemanticErrorZ ret_hu_conv = Result_RefundBolt12SemanticErrorZ.constr_from_ptr(ret);
202 if (this != null) { this.ptrs_to.add(this); };