bd6d974dc475e1d56bbb5f423f7ad0c5d0eee2ec
[ldk-java] / c_sharp / src / org / ldk / structs / WriteableScore.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  * Refers to a scorer that is accessible under lock and also writeable to disk
10  * 
11  * We need this trait to be able to pass in a scorer to `lightning-background-processor` that will enable us to
12  * use the Persister to persist it.
13  */
14 public class WriteableScore : CommonBase {
15         internal readonly bindings.LDKWriteableScore bindings_instance;
16         internal WriteableScore(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
17         private WriteableScore(bindings.LDKWriteableScore arg, bindings.LDKLockableScore LockableScore) : base(bindings.LDKWriteableScore_new(arg, LockableScore)) {
18                 this.ptrs_to.AddLast(arg);
19                 this.ptrs_to.AddLast(LockableScore);
20                 this.bindings_instance = arg;
21         }
22         ~WriteableScore() {
23                 if (ptr != 0) { bindings.WriteableScore_free(ptr); }
24         }
25
26         public interface WriteableScoreInterface {
27                 /**
28                  * Serialize the object into a byte array
29                  */
30                 byte[] write();
31         }
32         private class LDKWriteableScoreHolder { internal WriteableScore held; }
33         private class LDKWriteableScoreImpl : bindings.LDKWriteableScore {
34                 internal LDKWriteableScoreImpl(WriteableScoreInterface arg, LDKWriteableScoreHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
35                 private WriteableScoreInterface arg;
36                 private LDKWriteableScoreHolder impl_holder;
37                 public byte[] write() {
38                         byte[] ret = arg.write();
39                                 GC.KeepAlive(arg);
40                         return ret;
41                 }
42         }
43         public static WriteableScore new_impl(WriteableScoreInterface arg, LockableScore.LockableScoreInterface LockableScore_impl) {
44                 LDKWriteableScoreHolder impl_holder = new LDKWriteableScoreHolder();
45                 impl_holder.held = new WriteableScore(new LDKWriteableScoreImpl(arg, impl_holder), LockableScore.new_impl(LockableScore_impl).bindings_instance);
46                 return impl_holder.held;
47         }
48
49         /**
50          * Gets the underlying LockableScore.
51          */
52         public LockableScore get_lockable_score() {
53                 LockableScore res = new LockableScore(null, bindings.LDKWriteableScore_get_LockableScore(this.ptr));
54                 this.ptrs_to.AddLast(res);
55                 return res;
56         }
57
58         /**
59          * Serialize the object into a byte array
60          */
61         public byte[] write() {
62                 byte[] ret = bindings.WriteableScore_write(this.ptr);
63                 GC.KeepAlive(this);
64                 return ret;
65         }
66
67 }
68 } } }