X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FNodeAnnouncement.java;h=40c01d80ac1a3c7a13b9827b078aaed972af45dd;hb=c6bac88847b7c09560af81f00ba8dd3c2ebe3a19;hp=b114815fbef867cb40caf4acd7d485202d07f33d;hpb=2ed9081562d00a8645604b07629e963231d49e0f;p=ldk-java diff --git a/src/main/java/org/ldk/structs/NodeAnnouncement.java b/src/main/java/org/ldk/structs/NodeAnnouncement.java index b114815f..40c01d80 100644 --- a/src/main/java/org/ldk/structs/NodeAnnouncement.java +++ b/src/main/java/org/ldk/structs/NodeAnnouncement.java @@ -2,50 +2,94 @@ package org.ldk.structs; import org.ldk.impl.bindings; import org.ldk.enums.*; +import org.ldk.util.*; +import java.util.Arrays; +import javax.annotation.Nullable; + +/** + * A node_announcement message to be sent or received from a peer + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class NodeAnnouncement extends CommonBase { NodeAnnouncement(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.NodeAnnouncement_free(ptr); super.finalize(); + super.finalize(); + if (ptr != 0) { bindings.NodeAnnouncement_free(ptr); } } - public NodeAnnouncement(NodeAnnouncement orig) { - super(bindings.NodeAnnouncement_clone(orig == null ? 0 : orig.ptr & ~1)); - this.ptrs_to.add(orig); + /** + * The signature by the node key + */ + public byte[] get_signature() { + byte[] ret = bindings.NodeAnnouncement_get_signature(this.ptr); + return ret; } - public byte[] get_signature(NodeAnnouncement this_ptr) { - byte[] ret = bindings.NodeAnnouncement_get_signature(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); - return ret; + /** + * The signature by the node key + */ + public void set_signature(byte[] val) { + bindings.NodeAnnouncement_set_signature(this.ptr, val); } - public void set_signature(NodeAnnouncement this_ptr, byte[] val) { - bindings.NodeAnnouncement_set_signature(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * The actual content of the announcement + */ + public UnsignedNodeAnnouncement get_contents() { + long ret = bindings.NodeAnnouncement_get_contents(this.ptr); + if (ret >= 0 && ret <= 4096) { return null; } + UnsignedNodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UnsignedNodeAnnouncement(null, ret); } + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } - public UnsignedNodeAnnouncement get_contents(NodeAnnouncement this_ptr) { - UnsignedNodeAnnouncement ret = new UnsignedNodeAnnouncement(null, bindings.NodeAnnouncement_get_contents(this_ptr == null ? 0 : this_ptr.ptr & ~1)); - this.ptrs_to.add(this_ptr); - return ret; + /** + * The actual content of the announcement + */ + public void set_contents(UnsignedNodeAnnouncement val) { + bindings.NodeAnnouncement_set_contents(this.ptr, val == null ? 0 : val.ptr & ~1); } - public void set_contents(NodeAnnouncement this_ptr, UnsignedNodeAnnouncement val) { - bindings.NodeAnnouncement_set_contents(this_ptr == null ? 0 : this_ptr.ptr & ~1, val == null ? 0 : val.ptr & ~1); - this.ptrs_to.add(this_ptr); - this.ptrs_to.add(val); + /** + * Constructs a new NodeAnnouncement given each field + */ + public static NodeAnnouncement of(byte[] signature_arg, UnsignedNodeAnnouncement contents_arg) { + long ret = bindings.NodeAnnouncement_new(signature_arg, contents_arg == null ? 0 : contents_arg.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } + NodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeAnnouncement(null, ret); } + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; } - public NodeAnnouncement(byte[] signature_arg, UnsignedNodeAnnouncement contents_arg) { - super(bindings.NodeAnnouncement_new(signature_arg, contents_arg == null ? 0 : contents_arg.ptr & ~1)); - this.ptrs_to.add(contents_arg); + /** + * Creates a copy of the NodeAnnouncement + */ + public NodeAnnouncement clone() { + long ret = bindings.NodeAnnouncement_clone(this.ptr); + if (ret >= 0 && ret <= 4096) { return null; } + NodeAnnouncement ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeAnnouncement(null, ret); } + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + + /** + * Serialize the NodeAnnouncement object into a byte array which can be read by NodeAnnouncement_read + */ + public byte[] write() { + byte[] ret = bindings.NodeAnnouncement_write(this.ptr); + return ret; } - // Skipped NodeAnnouncement_write - public NodeAnnouncement(byte[] ser) { - super(bindings.NodeAnnouncement_read(ser)); + /** + * Read a NodeAnnouncement from a byte array, created by NodeAnnouncement_write + */ + public static Result_NodeAnnouncementDecodeErrorZ read(byte[] ser) { + long ret = bindings.NodeAnnouncement_read(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_NodeAnnouncementDecodeErrorZ ret_hu_conv = Result_NodeAnnouncementDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } }