1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * An interface to send a transaction to the Bitcoin network.
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class BroadcasterInterface extends CommonBase {
15 final bindings.LDKBroadcasterInterface bindings_instance;
16 BroadcasterInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17 private BroadcasterInterface(bindings.LDKBroadcasterInterface arg) {
18 super(bindings.LDKBroadcasterInterface_new(arg));
19 this.ptrs_to.add(arg);
20 this.bindings_instance = arg;
22 @Override @SuppressWarnings("deprecation")
23 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.BroadcasterInterface_free(ptr); } super.finalize();
27 * Destroys the object, freeing associated resources. After this call, any access
28 * to this object may result in a SEGFAULT or worse.
30 * You should generally NEVER call this method. You should let the garbage collector
31 * do this for you when it finalizes objects. However, it may be useful for types
32 * which represent locks and should be closed immediately to avoid holding locks
35 public void destroy() {
36 if (ptr != 0) { bindings.BroadcasterInterface_free(ptr); }
39 public static interface BroadcasterInterfaceInterface {
41 * Sends a list of transactions out to (hopefully) be mined.
42 * This only needs to handle the actual broadcasting of transactions, LDK will automatically
43 * rebroadcast transactions that haven't made it into a block.
45 * In some cases LDK may attempt to broadcast a transaction which double-spends another
46 * and this isn't a bug and can be safely ignored.
48 * If more than one transaction is given, these transactions should be considered to be a
49 * package and broadcast together. Some of the transactions may or may not depend on each other,
50 * be sure to manage both cases correctly.
52 * Bitcoin transaction packages are defined in BIP 331 and here:
53 * <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md>
55 void broadcast_transactions(byte[][] txs);
57 private static class LDKBroadcasterInterfaceHolder { BroadcasterInterface held; }
58 public static BroadcasterInterface new_impl(BroadcasterInterfaceInterface arg) {
59 final LDKBroadcasterInterfaceHolder impl_holder = new LDKBroadcasterInterfaceHolder();
60 impl_holder.held = new BroadcasterInterface(new bindings.LDKBroadcasterInterface() {
61 @Override public void broadcast_transactions(byte[][] txs) {
62 arg.broadcast_transactions(txs);
63 Reference.reachabilityFence(arg);
66 return impl_holder.held;
69 * Sends a list of transactions out to (hopefully) be mined.
70 * This only needs to handle the actual broadcasting of transactions, LDK will automatically
71 * rebroadcast transactions that haven't made it into a block.
73 * In some cases LDK may attempt to broadcast a transaction which double-spends another
74 * and this isn't a bug and can be safely ignored.
76 * If more than one transaction is given, these transactions should be considered to be a
77 * package and broadcast together. Some of the transactions may or may not depend on each other,
78 * be sure to manage both cases correctly.
80 * Bitcoin transaction packages are defined in BIP 331 and here:
81 * <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md>
83 public void broadcast_transactions(byte[][] txs) {
84 bindings.BroadcasterInterface_broadcast_transactions(this.ptr, txs);
85 Reference.reachabilityFence(this);
86 Reference.reachabilityFence(txs);