f5abed57eb6e772d3ef634a846cc69eb67715a14
[ldk-java] / c_sharp / src / org / ldk / structs / BlindedPath.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * Onion messages can be sent and received to blinded paths, which serve to hide the identity of
11  * the recipient.
12  */
13 public class BlindedPath : CommonBase {
14         internal BlindedPath(object _dummy, long ptr) : base(ptr) { }
15         ~BlindedPath() {
16                 if (ptr != 0) { bindings.BlindedPath_free(ptr); }
17         }
18
19         internal long clone_ptr() {
20                 long ret = bindings.BlindedPath_clone_ptr(this.ptr);
21                 GC.KeepAlive(this);
22                 return ret;
23         }
24
25         /**
26          * Creates a copy of the BlindedPath
27          */
28         public BlindedPath clone() {
29                 long ret = bindings.BlindedPath_clone(this.ptr);
30                 GC.KeepAlive(this);
31                 if (ret >= 0 && ret <= 4096) { return null; }
32                 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
33                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
34                 return ret_hu_conv;
35         }
36
37         /**
38          * Create a blinded path to be forwarded along `node_pks`. The last node pubkey in `node_pks`
39          * will be the destination node.
40          * 
41          * Errors if less than two hops are provided or if `node_pk`(s) are invalid.
42          */
43         public static Result_BlindedPathNoneZ of(byte[][] node_pks, org.ldk.structs.KeysInterface keys_manager) {
44                 long ret = bindings.BlindedPath_new(node_pks != null ? InternalUtils.mapArray(node_pks, node_pks_conv_8 => InternalUtils.check_arr_len(node_pks_conv_8, 33)) : null, keys_manager == null ? 0 : keys_manager.ptr);
45                 GC.KeepAlive(node_pks);
46                 GC.KeepAlive(keys_manager);
47                 if (ret >= 0 && ret <= 4096) { return null; }
48                 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
49                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(keys_manager); };
50                 return ret_hu_conv;
51         }
52
53         /**
54          * Serialize the BlindedPath object into a byte array which can be read by BlindedPath_read
55          */
56         public byte[] write() {
57                 byte[] ret = bindings.BlindedPath_write(this.ptr);
58                 GC.KeepAlive(this);
59                 return ret;
60         }
61
62         /**
63          * Read a BlindedPath from a byte array, created by BlindedPath_write
64          */
65         public static Result_BlindedPathDecodeErrorZ read(byte[] ser) {
66                 long ret = bindings.BlindedPath_read(ser);
67                 GC.KeepAlive(ser);
68                 if (ret >= 0 && ret <= 4096) { return null; }
69                 Result_BlindedPathDecodeErrorZ ret_hu_conv = Result_BlindedPathDecodeErrorZ.constr_from_ptr(ret);
70                 return ret_hu_conv;
71         }
72
73 }
74 } } }