fa7bceb17a7635720d42b5ae5c29d1319ade3ff3
[ldk-java] / ts / structs / Filter.ts
1
2             
3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
5
6
7
8             export class Filter extends CommonBase {
9
10                 bindings_instance?: bindings.LDKFilter;
11
12                 constructor(ptr?: number, arg?: bindings.LDKFilter) {
13                     if (Number.isFinite(ptr)) {
14                                         super(ptr);
15                                         this.bindings_instance = null;
16                                     } else {
17                                         // TODO: private constructor instantiation
18                                         super(bindings.LDKFilter_new(arg));
19                                         this.ptrs_to.push(arg);
20                                         
21                                     }
22                 }
23
24                 protected finalize() {
25                     if (this.ptr != 0) {
26                         bindings.Filter_free(this.ptr);
27                     }
28                     super.finalize();
29                 }
30
31                 static new_impl(arg: FilterInterface): Filter {
32                     const impl_holder: LDKFilterHolder = new LDKFilterHolder();
33                     let structImplementation = <bindings.LDKFilter>{
34                         // todo: in-line interface filling
35                         register_tx (txid: Uint8Array, script_pubkey: Uint8Array): void {
36                                                         arg.register_tx(txid, script_pubkey);
37                                                 },
38
39                                                 register_output (outpoint: number, script_pubkey: Uint8Array): void {
40                                                         const outpoint_hu_conv: OutPoint = new OutPoint(null, outpoint);
41                                                         arg.register_output(outpoint_hu_conv, script_pubkey);
42                                                 },
43
44                                                 
45                     };
46                     impl_holder.held = new Filter (null, structImplementation);
47                 }
48             }
49
50             export interface FilterInterface {
51                 register_tx(txid: Uint8Array, script_pubkey: Uint8Array): void;
52                                 register_output(outpoint: OutPoint, script_pubkey: Uint8Array): void;
53                                 
54             }
55
56             class LDKFilterHolder {
57                 held: Filter;
58             }
59         public void register_tx(Uint8Array txid, Uint8Array script_pubkey) {
60                 bindings.Filter_register_tx(this.ptr, txid, script_pubkey);
61         }
62
63         public void register_output(OutPoint outpoint, Uint8Array script_pubkey) {
64                 bindings.Filter_register_output(this.ptr, outpoint == null ? 0 : outpoint.ptr & ~1, script_pubkey);
65                 this.ptrs_to.add(outpoint);
66         }
67
68 }