X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FScorer.java;h=82b995792a6aad588ff985b57ef25f57265ffc32;hb=c6bac88847b7c09560af81f00ba8dd3c2ebe3a19;hp=f1f8ecd548f029d5ece646b7fe9b0713098898fe;hpb=0d48e557e83ef085cc92c2de63b9c81c061ce78c;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Scorer.java b/src/main/java/org/ldk/structs/Scorer.java index f1f8ecd5..82b99579 100644 --- a/src/main/java/org/ldk/structs/Scorer.java +++ b/src/main/java/org/ldk/structs/Scorer.java @@ -11,7 +11,7 @@ import javax.annotation.Nullable; * [`routing::Score`] implementation that provides reasonable default behavior. * * Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with - * slightly higher fees are available. + * slightly higher fees are available. Will further penalize channels that fail to relay payments. * * See [module-level documentation] for usage. * @@ -27,12 +27,12 @@ public class Scorer extends CommonBase { } /** - * Creates a new scorer using `base_penalty_msat` as the channel penalty. + * Creates a new scorer using the given scoring parameters. */ - public static Scorer of(long base_penalty_msat) { - long ret = bindings.Scorer_new(base_penalty_msat); - if (ret >= 0 && ret < 1024) { return null; } - Scorer ret_hu_conv = new Scorer(null, ret); + public static Scorer of(long params_base_penalty_msat_arg, long params_failure_penalty_msat_arg, long params_failure_penalty_half_life_arg) { + long ret = bindings.Scorer_new(bindings.ScoringParameters_new(params_base_penalty_msat_arg, params_failure_penalty_msat_arg, params_failure_penalty_half_life_arg)); + if (ret >= 0 && ret <= 4096) { return null; } + Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); } ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; } @@ -42,8 +42,8 @@ public class Scorer extends CommonBase { */ public static Scorer with_default() { long ret = bindings.Scorer_default(); - if (ret >= 0 && ret < 1024) { return null; } - Scorer ret_hu_conv = new Scorer(null, ret); + if (ret >= 0 && ret <= 4096) { return null; } + Scorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Scorer(null, ret); } ret_hu_conv.ptrs_to.add(ret_hu_conv); return ret_hu_conv; } @@ -54,10 +54,28 @@ public class Scorer extends CommonBase { */ public Score as_Score() { long ret = bindings.Scorer_as_Score(this.ptr); - if (ret >= 0 && ret < 1024) { return null; } + if (ret >= 0 && ret <= 4096) { return null; } Score ret_hu_conv = new Score(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } + /** + * Serialize the Scorer object into a byte array which can be read by Scorer_read + */ + public byte[] write() { + byte[] ret = bindings.Scorer_write(this.ptr); + return ret; + } + + /** + * Read a Scorer from a byte array, created by Scorer_write + */ + public static Result_ScorerDecodeErrorZ read(byte[] ser) { + long ret = bindings.Scorer_read(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_ScorerDecodeErrorZ ret_hu_conv = Result_ScorerDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; + } + }