Update auto-generated bindings to 0.0.103
[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 javax.annotation.Nullable;
8
9 /**
10  * An interface used to score payment channels for path finding.
11  * 
12  * \tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Score extends CommonBase {
16         final bindings.LDKScore bindings_instance;
17         Score(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18         private Score(bindings.LDKScore arg) {
19                 super(bindings.LDKScore_new(arg));
20                 this.ptrs_to.add(arg);
21                 this.bindings_instance = arg;
22         }
23         @Override @SuppressWarnings("deprecation")
24         protected void finalize() throws Throwable {
25                 if (ptr != 0) { bindings.Score_free(ptr); } super.finalize();
26         }
27
28         public static interface ScoreInterface {
29                 /**
30                  * Returns the fee in msats willing to be paid to avoid routing through the given channel
31                  * in the direction from `source` to `target`.
32                  */
33                 long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target);
34                 /**
35                  * Handles updating channel penalties after failing to route through a channel.
36                  */
37                 void payment_path_failed(RouteHop[] path, long short_channel_id);
38                 /**
39                  * Serialize the object into a byte array
40                  */
41                 byte[] write();
42         }
43         private static class LDKScoreHolder { Score held; }
44         public static Score new_impl(ScoreInterface arg) {
45                 final LDKScoreHolder impl_holder = new LDKScoreHolder();
46                 impl_holder.held = new Score(new bindings.LDKScore() {
47                         @Override public long channel_penalty_msat(long short_channel_id, long source, long target) {
48                                 NodeId source_hu_conv = null; if (source < 0 || source > 4096) { source_hu_conv = new NodeId(null, source); }
49                                 NodeId target_hu_conv = null; if (target < 0 || target > 4096) { target_hu_conv = new NodeId(null, target); }
50                                 long ret = arg.channel_penalty_msat(short_channel_id, source_hu_conv, target_hu_conv);
51                                 return ret;
52                         }
53                         @Override public void payment_path_failed(long[] path, long short_channel_id) {
54                                 RouteHop[] path_conv_10_arr = new RouteHop[path.length];
55                                 for (int k = 0; k < path.length; k++) {
56                                         long path_conv_10 = path[k];
57                                         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); }
58                                         path_conv_10_hu_conv.ptrs_to.add(this);
59                                         path_conv_10_arr[k] = path_conv_10_hu_conv;
60                                 }
61                                 arg.payment_path_failed(path_conv_10_arr, short_channel_id);
62                         }
63                         @Override public byte[] write() {
64                                 byte[] ret = arg.write();
65                                 return ret;
66                         }
67                 });
68                 return impl_holder.held;
69         }
70         /**
71          * Returns the fee in msats willing to be paid to avoid routing through the given channel
72          * in the direction from `source` to `target`.
73          */
74         public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target) {
75                 long ret = bindings.Score_channel_penalty_msat(this.ptr, short_channel_id, source == null ? 0 : source.ptr & ~1, target == null ? 0 : target.ptr & ~1);
76                 this.ptrs_to.add(source);
77                 this.ptrs_to.add(target);
78                 return ret;
79         }
80
81         /**
82          * Handles updating channel penalties after failing to route through a channel.
83          */
84         public void payment_path_failed(RouteHop[] path, long short_channel_id) {
85                 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);
86         }
87
88         /**
89          * Serialize the object into a byte array
90          */
91         public byte[] write() {
92                 byte[] ret = bindings.Score_write(this.ptr);
93                 return ret;
94         }
95
96 }