3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export class Score extends CommonBase {
10 bindings_instance?: bindings.LDKScore;
12 constructor(ptr?: number, arg?: bindings.LDKScore) {
13 if (Number.isFinite(ptr)) {
15 this.bindings_instance = null;
17 // TODO: private constructor instantiation
18 super(bindings.LDKScore_new(arg));
19 this.ptrs_to.push(arg);
24 protected finalize() {
26 bindings.Score_free(this.ptr);
31 static new_impl(arg: ScoreInterface): Score {
32 const impl_holder: LDKScoreHolder = new LDKScoreHolder();
33 let structImplementation = <bindings.LDKScore>{
34 // todo: in-line interface filling
35 channel_penalty_msat (short_channel_id: number, source: number, target: number): number {
36 const source_hu_conv: NodeId = new NodeId(null, source);
37 const target_hu_conv: NodeId = new NodeId(null, target);
38 number ret = arg.channel_penalty_msat(short_channel_id, source_hu_conv, target_hu_conv);
42 payment_path_failed (path: number[], short_channel_id: number): void {
43 RouteHop[] path_conv_10_arr = new RouteHop[path.length];
44 for (int k = 0; k < path.length; k++) {
45 number path_conv_10 = path[k];
46 const path_conv_10_hu_conv: RouteHop = new RouteHop(null, path_conv_10);
47 path_conv_10_hu_conv.ptrs_to.add(this);
48 path_conv_10_arr[k] = path_conv_10_hu_conv;
50 arg.payment_path_failed(path_conv_10_arr, short_channel_id);
53 write (): Uint8Array {
54 Uint8Array ret = arg.write();
60 impl_holder.held = new Score (null, structImplementation);
64 export interface ScoreInterface {
65 channel_penalty_msat(short_channel_id: number, source: NodeId, target: NodeId): number;
66 payment_path_failed(path: RouteHop[], short_channel_id: number): void;
71 class LDKScoreHolder {
74 public number channel_penalty_msat(number short_channel_id, NodeId source, NodeId target) {
75 number 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);
81 public void payment_path_failed(RouteHop[] path, number short_channel_id) {
82 bindings.Score_payment_path_failed(this.ptr, path != null ? Arrays.stream(path).map(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray(number[]::new) : null, short_channel_id);
85 public Uint8Array write() {
86 Uint8Array ret = bindings.Score_write(this.ptr);