Merge pull request #42 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / HTLCFailChannelUpdate.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
10 /**
11  * The information we received from a peer along the route of a payment we originated. This is
12  * returned by ChannelMessageHandler::handle_update_fail_htlc to be passed into
13  * RoutingMessageHandler::handle_htlc_fail_channel_update to update our network map.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class HTLCFailChannelUpdate extends CommonBase {
17         private HTLCFailChannelUpdate(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.HTLCFailChannelUpdate_free(ptr); }
22         }
23         static HTLCFailChannelUpdate constr_from_ptr(long ptr) {
24                 bindings.LDKHTLCFailChannelUpdate raw_val = bindings.LDKHTLCFailChannelUpdate_ref_from_ptr(ptr);
25                 if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage.class) {
26                         return new ChannelUpdateMessage(ptr, (bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage)raw_val);
27                 }
28                 if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.ChannelClosed.class) {
29                         return new ChannelClosed(ptr, (bindings.LDKHTLCFailChannelUpdate.ChannelClosed)raw_val);
30                 }
31                 if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.NodeFailure.class) {
32                         return new NodeFailure(ptr, (bindings.LDKHTLCFailChannelUpdate.NodeFailure)raw_val);
33                 }
34                 assert false; return null; // Unreachable without extending the (internal) bindings interface
35         }
36
37         public final static class ChannelUpdateMessage extends HTLCFailChannelUpdate {
38                 /**
39                  * The unwrapped message we received
40                 */
41                 public final ChannelUpdate msg;
42                 private ChannelUpdateMessage(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage obj) {
43                         super(null, ptr);
44                         long msg = obj.msg;
45                         ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
46                         msg_hu_conv.ptrs_to.add(this);
47                         this.msg = msg_hu_conv;
48                 }
49         }
50         public final static class ChannelClosed extends HTLCFailChannelUpdate {
51                 /**
52                  * The short_channel_id which has now closed.
53                 */
54                 public final long short_channel_id;
55                 /**
56                  * when this true, this channel should be permanently removed from the
57                  * consideration. Otherwise, this channel can be restored as new channel_update is received
58                 */
59                 public final boolean is_permanent;
60                 private ChannelClosed(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelClosed obj) {
61                         super(null, ptr);
62                         this.short_channel_id = obj.short_channel_id;
63                         this.is_permanent = obj.is_permanent;
64                 }
65         }
66         public final static class NodeFailure extends HTLCFailChannelUpdate {
67                 /**
68                  * The node_id that has failed.
69                 */
70                 public final byte[] node_id;
71                 /**
72                  * when this true, node should be permanently removed from the
73                  * consideration. Otherwise, the channels connected to this node can be
74                  * restored as new channel_update is received
75                 */
76                 public final boolean is_permanent;
77                 private NodeFailure(long ptr, bindings.LDKHTLCFailChannelUpdate.NodeFailure obj) {
78                         super(null, ptr);
79                         this.node_id = obj.node_id;
80                         this.is_permanent = obj.is_permanent;
81                 }
82         }
83         /**
84          * Creates a copy of the HTLCFailChannelUpdate
85          */
86         public HTLCFailChannelUpdate clone() {
87                 long ret = bindings.HTLCFailChannelUpdate_clone(this.ptr);
88                 if (ret < 1024) { return null; }
89                 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
90                 ret_hu_conv.ptrs_to.add(this);
91                 return ret_hu_conv;
92         }
93
94         /**
95          * Utility method to constructs a new ChannelUpdateMessage-variant HTLCFailChannelUpdate
96          */
97         public static HTLCFailChannelUpdate channel_update_message(ChannelUpdate msg) {
98                 long ret = bindings.HTLCFailChannelUpdate_channel_update_message(msg == null ? 0 : msg.ptr & ~1);
99                 if (ret < 1024) { return null; }
100                 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
101                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
102                 ret_hu_conv.ptrs_to.add(msg);
103                 return ret_hu_conv;
104         }
105
106         /**
107          * Utility method to constructs a new ChannelClosed-variant HTLCFailChannelUpdate
108          */
109         public static HTLCFailChannelUpdate channel_closed(long short_channel_id, boolean is_permanent) {
110                 long ret = bindings.HTLCFailChannelUpdate_channel_closed(short_channel_id, is_permanent);
111                 if (ret < 1024) { return null; }
112                 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
113                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Utility method to constructs a new NodeFailure-variant HTLCFailChannelUpdate
119          */
120         public static HTLCFailChannelUpdate node_failure(byte[] node_id, boolean is_permanent) {
121                 long ret = bindings.HTLCFailChannelUpdate_node_failure(node_id, is_permanent);
122                 if (ret < 1024) { return null; }
123                 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
124                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
125                 return ret_hu_conv;
126         }
127
128 }