1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * `ScoreUpdate` is used to update the scorer's internal state after a payment attempt.
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class ScoreUpdate extends CommonBase {
15 final bindings.LDKScoreUpdate bindings_instance;
16 ScoreUpdate(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17 private ScoreUpdate(bindings.LDKScoreUpdate arg) {
18 super(bindings.LDKScoreUpdate_new(arg));
19 this.ptrs_to.add(arg);
20 this.bindings_instance = arg;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.ScoreUpdate_free(ptr); } super.finalize();
27 * Destroys the object, freeing associated resources. After this call, any access
28 * to this object may result in a SEGFAULT or worse.
30 * You should generally NEVER call this method. You should let the garbage collector
31 * do this for you when it finalizes objects. However, it may be useful for types
32 * which represent locks and should be closed immediately to avoid holding locks
35 public void destroy() {
36 if (ptr != 0) { bindings.ScoreUpdate_free(ptr); }
39 public static interface ScoreUpdateInterface {
41 * Handles updating channel penalties after failing to route through a channel.
43 void payment_path_failed(Path path, long short_channel_id, long duration_since_epoch);
45 * Handles updating channel penalties after successfully routing along a path.
47 void payment_path_successful(Path path, long duration_since_epoch);
49 * Handles updating channel penalties after a probe over the given path failed.
51 void probe_failed(Path path, long short_channel_id, long duration_since_epoch);
53 * Handles updating channel penalties after a probe over the given path succeeded.
55 void probe_successful(Path path, long duration_since_epoch);
57 * Scorers may wish to reduce their certainty of channel liquidity information over time.
58 * Thus, this method is provided to allow scorers to observe the passage of time - the holder
59 * of this object should call this method regularly (generally via the
60 * `lightning-background-processor` crate).
62 void time_passed(long duration_since_epoch);
64 private static class LDKScoreUpdateHolder { ScoreUpdate held; }
65 public static ScoreUpdate new_impl(ScoreUpdateInterface arg) {
66 final LDKScoreUpdateHolder impl_holder = new LDKScoreUpdateHolder();
67 impl_holder.held = new ScoreUpdate(new bindings.LDKScoreUpdate() {
68 @Override public void payment_path_failed(long path, long short_channel_id, long duration_since_epoch) {
69 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
70 arg.payment_path_failed(path_hu_conv, short_channel_id, duration_since_epoch);
71 Reference.reachabilityFence(arg);
73 @Override public void payment_path_successful(long path, long duration_since_epoch) {
74 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
75 arg.payment_path_successful(path_hu_conv, duration_since_epoch);
76 Reference.reachabilityFence(arg);
78 @Override public void probe_failed(long path, long short_channel_id, long duration_since_epoch) {
79 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
80 arg.probe_failed(path_hu_conv, short_channel_id, duration_since_epoch);
81 Reference.reachabilityFence(arg);
83 @Override public void probe_successful(long path, long duration_since_epoch) {
84 org.ldk.structs.Path path_hu_conv = null; if (path < 0 || path > 4096) { path_hu_conv = new org.ldk.structs.Path(null, path); }
85 arg.probe_successful(path_hu_conv, duration_since_epoch);
86 Reference.reachabilityFence(arg);
88 @Override public void time_passed(long duration_since_epoch) {
89 arg.time_passed(duration_since_epoch);
90 Reference.reachabilityFence(arg);
93 return impl_holder.held;
96 * Handles updating channel penalties after failing to route through a channel.
98 public void payment_path_failed(org.ldk.structs.Path path, long short_channel_id, long duration_since_epoch) {
99 bindings.ScoreUpdate_payment_path_failed(this.ptr, path.ptr, short_channel_id, duration_since_epoch);
100 Reference.reachabilityFence(this);
101 Reference.reachabilityFence(path);
102 Reference.reachabilityFence(short_channel_id);
103 Reference.reachabilityFence(duration_since_epoch);
104 if (this != null) { this.ptrs_to.add(path); };
108 * Handles updating channel penalties after successfully routing along a path.
110 public void payment_path_successful(org.ldk.structs.Path path, long duration_since_epoch) {
111 bindings.ScoreUpdate_payment_path_successful(this.ptr, path.ptr, duration_since_epoch);
112 Reference.reachabilityFence(this);
113 Reference.reachabilityFence(path);
114 Reference.reachabilityFence(duration_since_epoch);
115 if (this != null) { this.ptrs_to.add(path); };
119 * Handles updating channel penalties after a probe over the given path failed.
121 public void probe_failed(org.ldk.structs.Path path, long short_channel_id, long duration_since_epoch) {
122 bindings.ScoreUpdate_probe_failed(this.ptr, path.ptr, short_channel_id, duration_since_epoch);
123 Reference.reachabilityFence(this);
124 Reference.reachabilityFence(path);
125 Reference.reachabilityFence(short_channel_id);
126 Reference.reachabilityFence(duration_since_epoch);
127 if (this != null) { this.ptrs_to.add(path); };
131 * Handles updating channel penalties after a probe over the given path succeeded.
133 public void probe_successful(org.ldk.structs.Path path, long duration_since_epoch) {
134 bindings.ScoreUpdate_probe_successful(this.ptr, path.ptr, duration_since_epoch);
135 Reference.reachabilityFence(this);
136 Reference.reachabilityFence(path);
137 Reference.reachabilityFence(duration_since_epoch);
138 if (this != null) { this.ptrs_to.add(path); };
142 * Scorers may wish to reduce their certainty of channel liquidity information over time.
143 * Thus, this method is provided to allow scorers to observe the passage of time - the holder
144 * of this object should call this method regularly (generally via the
145 * `lightning-background-processor` crate).
147 public void time_passed(long duration_since_epoch) {
148 bindings.ScoreUpdate_time_passed(this.ptr, duration_since_epoch);
149 Reference.reachabilityFence(this);
150 Reference.reachabilityFence(duration_since_epoch);