1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Fallback address in case no LN payment is possible
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class Fallback extends CommonBase {
15 private Fallback(Object _dummy, long ptr) { super(ptr); }
16 @Override @SuppressWarnings("deprecation")
17 protected void finalize() throws Throwable {
19 if (ptr != 0) { bindings.Fallback_free(ptr); }
21 static Fallback constr_from_ptr(long ptr) {
22 bindings.LDKFallback raw_val = bindings.LDKFallback_ref_from_ptr(ptr);
23 if (raw_val.getClass() == bindings.LDKFallback.SegWitProgram.class) {
24 return new SegWitProgram(ptr, (bindings.LDKFallback.SegWitProgram)raw_val);
26 if (raw_val.getClass() == bindings.LDKFallback.PubKeyHash.class) {
27 return new PubKeyHash(ptr, (bindings.LDKFallback.PubKeyHash)raw_val);
29 if (raw_val.getClass() == bindings.LDKFallback.ScriptHash.class) {
30 return new ScriptHash(ptr, (bindings.LDKFallback.ScriptHash)raw_val);
32 assert false; return null; // Unreachable without extending the (internal) bindings interface
35 public final static class SegWitProgram extends Fallback {
36 public final UInt5 version;
37 public final byte[] program;
38 private SegWitProgram(long ptr, bindings.LDKFallback.SegWitProgram obj) {
40 byte version = obj.version;
41 UInt5 version_conv = new UInt5(version);
42 this.version = version_conv;
43 this.program = obj.program;
46 public final static class PubKeyHash extends Fallback {
47 public final byte[] pub_key_hash;
48 private PubKeyHash(long ptr, bindings.LDKFallback.PubKeyHash obj) {
50 this.pub_key_hash = obj.pub_key_hash;
53 public final static class ScriptHash extends Fallback {
54 public final byte[] script_hash;
55 private ScriptHash(long ptr, bindings.LDKFallback.ScriptHash obj) {
57 this.script_hash = obj.script_hash;
61 * Creates a copy of the Fallback
63 public Fallback clone() {
64 long ret = bindings.Fallback_clone(this.ptr);
65 if (ret < 1024) { return null; }
66 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
67 ret_hu_conv.ptrs_to.add(this);
72 * Utility method to constructs a new SegWitProgram-variant Fallback
74 public static Fallback seg_wit_program(UInt5 version, byte[] program) {
75 long ret = bindings.Fallback_seg_wit_program(version.getVal(), program);
76 if (ret < 1024) { return null; }
77 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
78 ret_hu_conv.ptrs_to.add(ret_hu_conv);
83 * Utility method to constructs a new PubKeyHash-variant Fallback
85 public static Fallback pub_key_hash(byte[] a) {
86 long ret = bindings.Fallback_pub_key_hash(a);
87 if (ret < 1024) { return null; }
88 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
89 ret_hu_conv.ptrs_to.add(ret_hu_conv);
94 * Utility method to constructs a new ScriptHash-variant Fallback
96 public static Fallback script_hash(byte[] a) {
97 long ret = bindings.Fallback_script_hash(a);
98 if (ret < 1024) { return null; }
99 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
100 ret_hu_conv.ptrs_to.add(ret_hu_conv);
105 * Checks if two Fallbacks contain equal inner contents.
108 long ret = bindings.Fallback_hash(this.ptr);
113 * Checks if two Fallbacks contain equal inner contents.
114 * This ignores pointers and is_owned flags and looks at the values in fields.
116 public boolean eq(Fallback b) {
117 boolean ret = bindings.Fallback_eq(this.ptr, b == null ? 0 : b.ptr & ~1);