[Java] Update auto-generated Java bindings for 0.0.108
[ldk-java] / src / main / java / org / ldk / structs / Score.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * An interface used to score payment channels for path finding.
12  * 
13  * \tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Score extends CommonBase {
17         final bindings.LDKScore bindings_instance;
18         Score(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
19         private Score(bindings.LDKScore arg) {
20                 super(bindings.LDKScore_new(arg));
21                 this.ptrs_to.add(arg);
22                 this.bindings_instance = arg;
23         }
24         @Override @SuppressWarnings("deprecation")
25         protected void finalize() throws Throwable {
26                 if (ptr != 0) { bindings.Score_free(ptr); } super.finalize();
27         }
28
29         public static interface ScoreInterface {
30                 /**
31                  * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
32                  * given channel in the direction from `source` to `target`.
33                  * 
34                  * The channel's capacity (less any other MPP parts that are also being considered for use in
35                  * the same payment) is given by `capacity_msat`. It may be determined from various sources
36                  * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
37                  * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
38                  * Thus, implementations should be overflow-safe.
39                  */
40                 long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage);
41                 /**
42                  * Handles updating channel penalties after failing to route through a channel.
43                  */
44                 void payment_path_failed(RouteHop[] path, long short_channel_id);
45                 /**
46                  * Handles updating channel penalties after successfully routing along a path.
47                  */
48                 void payment_path_successful(RouteHop[] path);
49                 /**
50                  * Serialize the object into a byte array
51                  */
52                 byte[] write();
53         }
54         private static class LDKScoreHolder { Score held; }
55         public static Score new_impl(ScoreInterface arg) {
56                 final LDKScoreHolder impl_holder = new LDKScoreHolder();
57                 impl_holder.held = new Score(new bindings.LDKScore() {
58                         @Override public long channel_penalty_msat(long short_channel_id, long source, long target, long usage) {
59                                 org.ldk.structs.NodeId source_hu_conv = null; if (source < 0 || source > 4096) { source_hu_conv = new org.ldk.structs.NodeId(null, source); }
60                                 org.ldk.structs.NodeId target_hu_conv = null; if (target < 0 || target > 4096) { target_hu_conv = new org.ldk.structs.NodeId(null, target); }
61                                 org.ldk.structs.ChannelUsage usage_hu_conv = null; if (usage < 0 || usage > 4096) { usage_hu_conv = new org.ldk.structs.ChannelUsage(null, usage); }
62                                 usage_hu_conv.ptrs_to.add(this);
63                                 long ret = arg.channel_penalty_msat(short_channel_id, source_hu_conv, target_hu_conv, usage_hu_conv);
64                                 Reference.reachabilityFence(arg);
65                                 return ret;
66                         }
67                         @Override public void payment_path_failed(long[] path, long short_channel_id) {
68                                 int path_conv_10_len = path.length;
69                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
70                                 for (int k = 0; k < path_conv_10_len; k++) {
71                                         long path_conv_10 = path[k];
72                                         org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
73                                         path_conv_10_hu_conv.ptrs_to.add(this);
74                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
75                                 }
76                                 arg.payment_path_failed(path_conv_10_arr, short_channel_id);
77                                 Reference.reachabilityFence(arg);
78                         }
79                         @Override public void payment_path_successful(long[] path) {
80                                 int path_conv_10_len = path.length;
81                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
82                                 for (int k = 0; k < path_conv_10_len; k++) {
83                                         long path_conv_10 = path[k];
84                                         org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
85                                         path_conv_10_hu_conv.ptrs_to.add(this);
86                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
87                                 }
88                                 arg.payment_path_successful(path_conv_10_arr);
89                                 Reference.reachabilityFence(arg);
90                         }
91                         @Override public byte[] write() {
92                                 byte[] ret = arg.write();
93                                 Reference.reachabilityFence(arg);
94                                 return ret;
95                         }
96                 });
97                 return impl_holder.held;
98         }
99         /**
100          * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
101          * given channel in the direction from `source` to `target`.
102          * 
103          * The channel's capacity (less any other MPP parts that are also being considered for use in
104          * the same payment) is given by `capacity_msat`. It may be determined from various sources
105          * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
106          * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
107          * Thus, implementations should be overflow-safe.
108          */
109         public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage) {
110                 long ret = bindings.Score_channel_penalty_msat(this.ptr, short_channel_id, source == null ? 0 : source.ptr & ~1, target == null ? 0 : target.ptr & ~1, usage == null ? 0 : usage.ptr & ~1);
111                 Reference.reachabilityFence(this);
112                 Reference.reachabilityFence(short_channel_id);
113                 Reference.reachabilityFence(source);
114                 Reference.reachabilityFence(target);
115                 Reference.reachabilityFence(usage);
116                 this.ptrs_to.add(source);
117                 this.ptrs_to.add(target);
118                 return ret;
119         }
120
121         /**
122          * Handles updating channel penalties after failing to route through a channel.
123          */
124         public void payment_path_failed(RouteHop[] path, long short_channel_id) {
125                 bindings.Score_payment_path_failed(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray() : null, short_channel_id);
126                 Reference.reachabilityFence(this);
127                 Reference.reachabilityFence(path);
128                 Reference.reachabilityFence(short_channel_id);
129         }
130
131         /**
132          * Handles updating channel penalties after successfully routing along a path.
133          */
134         public void payment_path_successful(RouteHop[] path) {
135                 bindings.Score_payment_path_successful(this.ptr, path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray() : null);
136                 Reference.reachabilityFence(this);
137                 Reference.reachabilityFence(path);
138         }
139
140         /**
141          * Serialize the object into a byte array
142          */
143         public byte[] write() {
144                 byte[] ret = bindings.Score_write(this.ptr);
145                 Reference.reachabilityFence(this);
146                 return ret;
147         }
148
149 }