af08050a6b282615cd8395a2ba4d9cecfb6a0ff8
[ldk-java] / c_sharp / src / org / ldk / structs / P2PGossipSync.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  * Receives and validates network updates from peers,
11  * stores authentic and relevant data as a network graph.
12  * This network graph is then used for routing payments.
13  * Provides interface to help with initial routing sync by
14  * serving historical announcements.
15  */
16 public class P2PGossipSync : CommonBase {
17         internal P2PGossipSync(object _dummy, long ptr) : base(ptr) { }
18         ~P2PGossipSync() {
19                 if (ptr != 0) { bindings.P2PGossipSync_free(ptr); }
20         }
21
22         /**
23          * Creates a new tracker of the actual state of the network of channels and nodes,
24          * assuming an existing Network Graph.
25          * Chain monitor is used to make sure announced channels exist on-chain,
26          * channel data is correct, and that the announcement is signed with
27          * channel owners' keys.
28          */
29         public static P2PGossipSync of(org.ldk.structs.NetworkGraph network_graph, org.ldk.structs.Option_AccessZ chain_access, org.ldk.structs.Logger logger) {
30                 long ret = bindings.P2PGossipSync_new(network_graph == null ? 0 : network_graph.ptr, chain_access.ptr, logger == null ? 0 : logger.ptr);
31                 GC.KeepAlive(network_graph);
32                 GC.KeepAlive(chain_access);
33                 GC.KeepAlive(logger);
34                 if (ret >= 0 && ret <= 4096) { return null; }
35                 org.ldk.structs.P2PGossipSync ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.P2PGossipSync(null, ret); }
36                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
37                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(network_graph); };
38                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(chain_access); };
39                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
40                 return ret_hu_conv;
41         }
42
43         /**
44          * Adds a provider used to check new announcements. Does not affect
45          * existing announcements unless they are updated.
46          * Add, update or remove the provider would replace the current one.
47          */
48         public void add_chain_access(org.ldk.structs.Option_AccessZ chain_access) {
49                 bindings.P2PGossipSync_add_chain_access(this.ptr, chain_access.ptr);
50                 GC.KeepAlive(this);
51                 GC.KeepAlive(chain_access);
52                 if (this != null) { this.ptrs_to.AddLast(chain_access); };
53         }
54
55         /**
56          * Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
57          * This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
58          */
59         public RoutingMessageHandler as_RoutingMessageHandler() {
60                 long ret = bindings.P2PGossipSync_as_RoutingMessageHandler(this.ptr);
61                 GC.KeepAlive(this);
62                 if (ret >= 0 && ret <= 4096) { return null; }
63                 RoutingMessageHandler ret_hu_conv = new RoutingMessageHandler(null, ret);
64                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
65                 return ret_hu_conv;
66         }
67
68         /**
69          * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
70          * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
71          */
72         public MessageSendEventsProvider as_MessageSendEventsProvider() {
73                 long ret = bindings.P2PGossipSync_as_MessageSendEventsProvider(this.ptr);
74                 GC.KeepAlive(this);
75                 if (ret >= 0 && ret <= 4096) { return null; }
76                 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
77                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
78                 return ret_hu_conv;
79         }
80
81 }
82 } } }