7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of Score */
12 public interface ScoreInterface {
13 /**Serialize the object into a byte array
19 * A trait which can both lookup and update routing channel penalty scores.
21 * This is used in places where both bounds are required and implemented for all types which
22 * implement [`ScoreLookUp`] and [`ScoreUpdate`].
24 * Bindings users may need to manually implement this for their custom scoring implementations.
26 public class Score : CommonBase {
27 internal bindings.LDKScore bindings_instance;
28 internal long instance_idx;
30 internal Score(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
32 if (ptr != 0) { bindings.Score_free(ptr); }
35 private class LDKScoreHolder { internal Score held; }
36 private class LDKScoreImpl : bindings.LDKScore {
37 internal LDKScoreImpl(ScoreInterface arg, LDKScoreHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
38 private ScoreInterface arg;
39 private LDKScoreHolder impl_holder;
41 byte[] ret = arg.write();
43 long result = InternalUtils.encodeUint8Array(ret);
48 /** Creates a new instance of Score from a given implementation */
49 public static Score new_impl(ScoreInterface arg, ScoreLookUpInterface scoreLookUp_impl, ScoreUpdateInterface scoreUpdate_impl) {
50 LDKScoreHolder impl_holder = new LDKScoreHolder();
51 LDKScoreImpl impl = new LDKScoreImpl(arg, impl_holder);
52 ScoreLookUp scoreLookUp = ScoreLookUp.new_impl(scoreLookUp_impl);
53 ScoreUpdate scoreUpdate = ScoreUpdate.new_impl(scoreUpdate_impl);
54 long[] ptr_idx = bindings.LDKScore_new(impl, scoreLookUp.instance_idx, scoreUpdate.instance_idx);
56 impl_holder.held = new Score(null, ptr_idx[0]);
57 impl_holder.held.instance_idx = ptr_idx[1];
58 impl_holder.held.bindings_instance = impl;
59 impl_holder.held.ptrs_to.AddLast(scoreLookUp);
60 impl_holder.held.ptrs_to.AddLast(scoreUpdate);
61 return impl_holder.held;
65 * Serialize the object into a byte array
67 public byte[] write() {
68 long ret = bindings.Score_write(this.ptr);
70 if (ret >= 0 && ret <= 4096) { return null; }
71 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);