[Java] Update auto-generated bindings to 0.0.105.0
[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, long send_amt_msat, long capacity_msat, NodeId source, NodeId target);
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 send_amt_msat, long capacity_msat, long source, long target) {
59                                 NodeId source_hu_conv = null; if (source < 0 || source > 4096) { source_hu_conv = new NodeId(null, source); }
60                                 NodeId target_hu_conv = null; if (target < 0 || target > 4096) { target_hu_conv = new NodeId(null, target); }
61                                 long ret = arg.channel_penalty_msat(short_channel_id, send_amt_msat, capacity_msat, source_hu_conv, target_hu_conv);
62                                 Reference.reachabilityFence(arg);
63                                 return ret;
64                         }
65                         @Override public void payment_path_failed(long[] path, long short_channel_id) {
66                                 int path_conv_10_len = path.length;
67                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
68                                 for (int k = 0; k < path_conv_10_len; k++) {
69                                         long path_conv_10 = path[k];
70                                         RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new RouteHop(null, path_conv_10); }
71                                         path_conv_10_hu_conv.ptrs_to.add(this);
72                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
73                                 }
74                                 arg.payment_path_failed(path_conv_10_arr, short_channel_id);
75                                 Reference.reachabilityFence(arg);
76                         }
77                         @Override public void payment_path_successful(long[] path) {
78                                 int path_conv_10_len = path.length;
79                                 RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
80                                 for (int k = 0; k < path_conv_10_len; k++) {
81                                         long path_conv_10 = path[k];
82                                         RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new RouteHop(null, path_conv_10); }
83                                         path_conv_10_hu_conv.ptrs_to.add(this);
84                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
85                                 }
86                                 arg.payment_path_successful(path_conv_10_arr);
87                                 Reference.reachabilityFence(arg);
88                         }
89                         @Override public byte[] write() {
90                                 byte[] ret = arg.write();
91                                 Reference.reachabilityFence(arg);
92                                 return ret;
93                         }
94                 });
95                 return impl_holder.held;
96         }
97         /**
98          * Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
99          * given channel in the direction from `source` to `target`.
100          * 
101          * The channel's capacity (less any other MPP parts that are also being considered for use in
102          * the same payment) is given by `capacity_msat`. It may be determined from various sources
103          * such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
104          * [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
105          * Thus, implementations should be overflow-safe.
106          */
107         public long channel_penalty_msat(long short_channel_id, long send_amt_msat, long capacity_msat, NodeId source, NodeId target) {
108                 long ret = bindings.Score_channel_penalty_msat(this.ptr, short_channel_id, send_amt_msat, capacity_msat, source == null ? 0 : source.ptr & ~1, target == null ? 0 : target.ptr & ~1);
109                 Reference.reachabilityFence(this);
110                 Reference.reachabilityFence(short_channel_id);
111                 Reference.reachabilityFence(send_amt_msat);
112                 Reference.reachabilityFence(capacity_msat);
113                 Reference.reachabilityFence(source);
114                 Reference.reachabilityFence(target);
115                 this.ptrs_to.add(source);
116                 this.ptrs_to.add(target);
117                 return ret;
118         }
119
120         /**
121          * Handles updating channel penalties after failing to route through a channel.
122          */
123         public void payment_path_failed(RouteHop[] path, long short_channel_id) {
124                 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);
125                 Reference.reachabilityFence(this);
126                 Reference.reachabilityFence(path);
127                 Reference.reachabilityFence(short_channel_id);
128         }
129
130         /**
131          * Handles updating channel penalties after successfully routing along a path.
132          */
133         public void payment_path_successful(RouteHop[] path) {
134                 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);
135                 Reference.reachabilityFence(this);
136                 Reference.reachabilityFence(path);
137         }
138
139         /**
140          * Serialize the object into a byte array
141          */
142         public byte[] write() {
143                 byte[] ret = bindings.Score_write(this.ptr);
144                 Reference.reachabilityFence(this);
145                 return ret;
146         }
147
148 }