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;
11 * A helper trait that describes an on-chain wallet capable of returning a (change) destination
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChangeDestinationSource extends CommonBase {
16 final bindings.LDKChangeDestinationSource bindings_instance;
17 ChangeDestinationSource(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18 private ChangeDestinationSource(bindings.LDKChangeDestinationSource arg) {
19 super(bindings.LDKChangeDestinationSource_new(arg));
20 this.ptrs_to.add(arg);
21 this.bindings_instance = arg;
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
25 if (ptr != 0) { bindings.ChangeDestinationSource_free(ptr); } super.finalize();
28 * Destroys the object, freeing associated resources. After this call, any access
29 * to this object may result in a SEGFAULT or worse.
31 * You should generally NEVER call this method. You should let the garbage collector
32 * do this for you when it finalizes objects. However, it may be useful for types
33 * which represent locks and should be closed immediately to avoid holding locks
36 public void destroy() {
37 if (ptr != 0) { bindings.ChangeDestinationSource_free(ptr); }
40 public static interface ChangeDestinationSourceInterface {
42 * Returns a script pubkey which can be used as a change destination for
43 * [`OutputSpender::spend_spendable_outputs`].
45 * This method should return a different value each time it is called, to avoid linking
46 * on-chain funds controlled to the same user.
48 Result_CVec_u8ZNoneZ get_change_destination_script();
50 private static class LDKChangeDestinationSourceHolder { ChangeDestinationSource held; }
51 public static ChangeDestinationSource new_impl(ChangeDestinationSourceInterface arg) {
52 final LDKChangeDestinationSourceHolder impl_holder = new LDKChangeDestinationSourceHolder();
53 impl_holder.held = new ChangeDestinationSource(new bindings.LDKChangeDestinationSource() {
54 @Override public long get_change_destination_script() {
55 Result_CVec_u8ZNoneZ ret = arg.get_change_destination_script();
56 Reference.reachabilityFence(arg);
57 long result = ret.clone_ptr();
61 return impl_holder.held;
64 * Returns a script pubkey which can be used as a change destination for
65 * [`OutputSpender::spend_spendable_outputs`].
67 * This method should return a different value each time it is called, to avoid linking
68 * on-chain funds controlled to the same user.
70 public Result_CVec_u8ZNoneZ get_change_destination_script() {
71 long ret = bindings.ChangeDestinationSource_get_change_destination_script(this.ptr);
72 Reference.reachabilityFence(this);
73 if (ret >= 0 && ret <= 4096) { return null; }
74 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);