Merge pull request #33 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9 public class Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ extends CommonBase {
10         private Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ(Object _dummy, long ptr) { super(ptr); }
11         protected void finalize() throws Throwable {
12                 if (ptr != 0) { bindings.CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(ptr); } super.finalize();
13         }
14
15         static Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ constr_from_ptr(long ptr) {
16                 if (bindings.LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_result_ok(ptr)) {
17                         return new Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK(null, ptr);
18                 } else {
19                         return new Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_Err(null, ptr);
20                 }
21         }
22         public static final class Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK extends Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
23                 public final TwoTuple<byte[], ChannelManager> res;
24                 private Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK(Object _dummy, long ptr) {
25                         super(_dummy, ptr);
26                         long res = bindings.LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_get_ok(ptr);
27                         byte[] res_a = bindings.LDKC2Tuple_BlockHashChannelManagerZ_get_a(res);
28                         long res_b = bindings.LDKC2Tuple_BlockHashChannelManagerZ_get_b(res);
29                         ChannelManager res_b_hu_conv = new ChannelManager(null, res_b);
30                         res_b_hu_conv.ptrs_to.add(this);;
31                         TwoTuple<byte[], ChannelManager> res_conv = new TwoTuple<byte[], ChannelManager>(res_a, res_b_hu_conv, () -> {
32                                 bindings.C2Tuple_BlockHashChannelManagerZ_free(res);
33                         });
34                         res_b_hu_conv.ptrs_to.add(res_conv);
35                         this.res = res_conv;
36                 }
37         }
38
39         public static final class Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_Err extends Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ {
40                 public final DecodeError err;
41                 private Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_Err(Object _dummy, long ptr) {
42                         super(_dummy, ptr);
43                         long err = bindings.LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_get_err(ptr);
44                         DecodeError err_hu_conv = new DecodeError(null, err);
45                         err_hu_conv.ptrs_to.add(this);
46                         this.err = err_hu_conv;
47                 }
48         }
49
50         /**
51          * Creates a new CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ in the success state.
52          */
53         public static Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ok(TwoTuple<byte[], ChannelManager> o) {
54                 long ret = bindings.CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(bindings.C2Tuple_BlockHashChannelManagerZ_new(o.a, o.b == null ? 0 : o.b.ptr & ~1));
55                 if (ret < 1024) { return null; }
56                 Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret);
57                 ret_hu_conv.ptrs_to.add(o.b);
58                 // Due to rust's strict-ownership memory model, in some cases we need to "move"
59                 // an object to pass exclusive ownership to the function being called.
60                 // In most cases, we avoid ret_hu_conv being visible in GC'd languages by cloning the object
61                 // at the FFI layer, creating a new object which Rust can claim ownership of
62                 // However, in some cases (eg here), there is no way to clone an object, and thus
63                 // we actually have to pass full ownership to Rust.
64                 // Thus, after ret_hu_conv call, o.b is reset to null and is now a dummy object.
65                 o.b.ptr = 0;
66                 return ret_hu_conv;
67         }
68
69         /**
70          * Creates a new CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ in the error state.
71          */
72         public static Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ err(DecodeError e) {
73                 long ret = bindings.CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e == null ? 0 : e.ptr & ~1);
74                 if (ret < 1024) { return null; }
75                 Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret);
76                 ret_hu_conv.ptrs_to.add(e);
77                 return ret_hu_conv;
78         }
79
80 }