]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/NetAddress.ts
Merge pull request #17 from TheBlueMatt/main
[ldk-java] / ts / structs / NetAddress.ts
1
2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
4
5 export default class NetAddress extends CommonBase {
6         protected constructor(_dummy: object, ptr: number) { super(ptr); }
7         protected finalize() {
8                 super.finalize();
9                 if (this.ptr != 0) { bindings.NetAddress_free(this.ptr); }
10         }
11         static constr_from_ptr(ptr: number): NetAddress {
12                 const raw_val: bindings.LDKNetAddress = bindings.LDKNetAddress_ref_from_ptr(ptr);
13                 if (raw_val instanceof bindings.LDKNetAddress.IPv4) {
14                         return new IPv4(this.ptr, raw_val);
15                 }
16                 if (raw_val instanceof bindings.LDKNetAddress.IPv6) {
17                         return new IPv6(this.ptr, raw_val);
18                 }
19                 if (raw_val instanceof bindings.LDKNetAddress.OnionV2) {
20                         return new OnionV2(this.ptr, raw_val);
21                 }
22                 if (raw_val instanceof bindings.LDKNetAddress.OnionV3) {
23                         return new OnionV3(this.ptr, raw_val);
24                 }
25                 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
26         }
27
28 }
29 export class IPv4 extends NetAddress {
30         public addr: Uint8Array;
31         public port: number;
32         private constructor(ptr: number, obj: bindings.LDKNetAddress.IPv4) {
33                 super(null, ptr);
34                 this.addr = obj.addr;
35                 this.port = obj.port;
36         }
37 }
38 export class IPv6 extends NetAddress {
39         public addr: Uint8Array;
40         public port: number;
41         private constructor(ptr: number, obj: bindings.LDKNetAddress.IPv6) {
42                 super(null, ptr);
43                 this.addr = obj.addr;
44                 this.port = obj.port;
45         }
46 }
47 export class OnionV2 extends NetAddress {
48         public addr: Uint8Array;
49         public port: number;
50         private constructor(ptr: number, obj: bindings.LDKNetAddress.OnionV2) {
51                 super(null, ptr);
52                 this.addr = obj.addr;
53                 this.port = obj.port;
54         }
55 }
56 export class OnionV3 extends NetAddress {
57         public ed25519_pubkey: Uint8Array;
58         public checksum: number;
59         public version: number;
60         public port: number;
61         private constructor(ptr: number, obj: bindings.LDKNetAddress.OnionV3) {
62                 super(null, ptr);
63                 this.ed25519_pubkey = obj.ed25519_pubkey;
64                 this.checksum = obj.checksum;
65                 this.version = obj.version;
66                 this.port = obj.port;
67         }
68 }
69         public NetAddress clone() {
70                 number ret = bindings.NetAddress_clone(this.ptr);
71                 NetAddress ret_hu_conv = NetAddress.constr_from_ptr(ret);
72                 ret_hu_conv.ptrs_to.add(this);
73                 return ret_hu_conv;
74         }
75
76         public Uint8Array write() {
77                 Uint8Array ret = bindings.NetAddress_write(this.ptr);
78                 return ret;
79         }
80
81 }