Merge pull request #123 from tnull/patch-1
[ldk-java] / src / main / java / org / ldk / structs / PaymentPurpose.java
index 10bce2748752794520fb4bb31339dbc125da081c..636ffec5a4454e93543f3d1151183f84cf42b830 100644 (file)
@@ -89,8 +89,8 @@ public class PaymentPurpose extends CommonBase {
                long ret = bindings.PaymentPurpose_clone(this.ptr);
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
-               PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(this);
+               org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }
 
@@ -102,8 +102,8 @@ public class PaymentPurpose extends CommonBase {
                Reference.reachabilityFence(payment_preimage);
                Reference.reachabilityFence(payment_secret);
                if (ret >= 0 && ret <= 4096) { return null; }
-               PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
                return ret_hu_conv;
        }
 
@@ -114,8 +114,28 @@ public class PaymentPurpose extends CommonBase {
                long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32));
                Reference.reachabilityFence(a);
                if (ret >= 0 && ret <= 4096) { return null; }
-               PaymentPurpose ret_hu_conv = PaymentPurpose.constr_from_ptr(ret);
-               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
+               return ret_hu_conv;
+       }
+
+       /**
+        * Serialize the PaymentPurpose object into a byte array which can be read by PaymentPurpose_read
+        */
+       public byte[] write() {
+               byte[] ret = bindings.PaymentPurpose_write(this.ptr);
+               Reference.reachabilityFence(this);
+               return ret;
+       }
+
+       /**
+        * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write
+        */
+       public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) {
+               long ret = bindings.PaymentPurpose_read(ser);
+               Reference.reachabilityFence(ser);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);
                return ret_hu_conv;
        }