3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export class Payer extends CommonBase {
10 bindings_instance?: bindings.LDKPayer;
12 constructor(ptr?: number, arg?: bindings.LDKPayer) {
13 if (Number.isFinite(ptr)) {
15 this.bindings_instance = null;
17 // TODO: private constructor instantiation
18 super(bindings.LDKPayer_new(arg));
19 this.ptrs_to.push(arg);
24 protected finalize() {
26 bindings.Payer_free(this.ptr);
31 static new_impl(arg: PayerInterface): Payer {
32 const impl_holder: LDKPayerHolder = new LDKPayerHolder();
33 let structImplementation = <bindings.LDKPayer>{
34 // todo: in-line interface filling
35 node_id (): Uint8Array {
36 Uint8Array ret = arg.node_id();
37 result: Uint8Array = InternalUtils.check_arr_len(ret, 33);
41 first_hops (): number[] {
42 ChannelDetails[] ret = arg.first_hops();
43 result: number[] = ret != null ? Arrays.stream(ret).map(ret_conv_16 -> ret_conv_16 == null ? 0 : ret_conv_16.clone_ptr()).toArray(number[]::new) : null;
47 send_payment (route: number, payment_hash: Uint8Array, payment_secret: Uint8Array): number {
48 const route_hu_conv: Route = new Route(null, route);
49 Result_PaymentIdPaymentSendFailureZ ret = arg.send_payment(route_hu_conv, payment_hash, payment_secret);
50 result: number = ret == null ? 0 : ret.clone_ptr();
54 send_spontaneous_payment (route: number, payment_preimage: Uint8Array): number {
55 const route_hu_conv: Route = new Route(null, route);
56 Result_PaymentIdPaymentSendFailureZ ret = arg.send_spontaneous_payment(route_hu_conv, payment_preimage);
57 result: number = ret == null ? 0 : ret.clone_ptr();
61 retry_payment (route: number, payment_id: Uint8Array): number {
62 const route_hu_conv: Route = new Route(null, route);
63 Result_NonePaymentSendFailureZ ret = arg.retry_payment(route_hu_conv, payment_id);
64 result: number = ret == null ? 0 : ret.clone_ptr();
68 abandon_payment (payment_id: Uint8Array): void {
69 arg.abandon_payment(payment_id);
74 impl_holder.held = new Payer (null, structImplementation);
78 export interface PayerInterface {
79 node_id(): Uint8Array;
80 first_hops(): ChannelDetails[];
81 send_payment(route: Route, payment_hash: Uint8Array, payment_secret: Uint8Array): Result_PaymentIdPaymentSendFailureZ;
82 send_spontaneous_payment(route: Route, payment_preimage: Uint8Array): Result_PaymentIdPaymentSendFailureZ;
83 retry_payment(route: Route, payment_id: Uint8Array): Result_NonePaymentSendFailureZ;
84 abandon_payment(payment_id: Uint8Array): void;
88 class LDKPayerHolder {
91 public Uint8Array node_id() {
92 Uint8Array ret = bindings.Payer_node_id(this.ptr);
96 public ChannelDetails[] first_hops() {
97 number[] ret = bindings.Payer_first_hops(this.ptr);
98 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
99 for (int q = 0; q < ret.length; q++) {
100 number ret_conv_16 = ret[q];
101 const ret_conv_16_hu_conv: ChannelDetails = new ChannelDetails(null, ret_conv_16);
102 ret_conv_16_hu_conv.ptrs_to.add(this);
103 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
105 return ret_conv_16_arr;
108 public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, Uint8Array payment_hash, Uint8Array payment_secret) {
109 number ret = bindings.Payer_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
110 Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
111 this.ptrs_to.add(route);
115 public Result_PaymentIdPaymentSendFailureZ send_spontaneous_payment(Route route, Uint8Array payment_preimage) {
116 number ret = bindings.Payer_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_preimage, 32));
117 Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
118 this.ptrs_to.add(route);
122 public Result_NonePaymentSendFailureZ retry_payment(Route route, Uint8Array payment_id) {
123 number ret = bindings.Payer_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_id, 32));
124 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
125 this.ptrs_to.add(route);
129 public void abandon_payment(Uint8Array payment_id) {
130 bindings.Payer_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));