X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FPaymentPurpose.cs;h=ebd6168e875bd450df98150a20a9d1eb7cb42984;hb=8de7213fbf663ff60322896282dad51e8ab2f001;hp=bf8752be035e91feac49503605fcc956174db880;hpb=8aa8a96fc6d8fcdd3fbb419b4b4c12482af14938;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/PaymentPurpose.cs b/c_sharp/src/org/ldk/structs/PaymentPurpose.cs index bf8752be..ebd6168e 100644 --- a/c_sharp/src/org/ldk/structs/PaymentPurpose.cs +++ b/c_sharp/src/org/ldk/structs/PaymentPurpose.cs @@ -34,10 +34,8 @@ public class PaymentPurpose : CommonBase { * * [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment * [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds - * - * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None */ - public byte[] payment_preimage; + public Option_ThirtyTwoBytesZ payment_preimage; /** * The \"payment secret\". This authenticates the sender to the recipient, preventing a * number of deanonymization attacks during the routing process. @@ -52,15 +50,22 @@ public class PaymentPurpose : CommonBase { */ public byte[] payment_secret; internal PaymentPurpose_InvoicePayment(long ptr) : base(null, ptr) { - this.payment_preimage = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_preimage(ptr); - this.payment_secret = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_secret(ptr); + long payment_preimage = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_preimage(ptr); + org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(payment_preimage); + if (payment_preimage_hu_conv != null) { payment_preimage_hu_conv.ptrs_to.AddLast(this); }; + this.payment_preimage = payment_preimage_hu_conv; + long payment_secret = bindings.LDKPaymentPurpose_InvoicePayment_get_payment_secret(ptr); + byte[] payment_secret_conv = InternalUtils.decodeUint8Array(payment_secret); + this.payment_secret = payment_secret_conv; } } /** A PaymentPurpose of type SpontaneousPayment */ public class PaymentPurpose_SpontaneousPayment : PaymentPurpose { public byte[] spontaneous_payment; internal PaymentPurpose_SpontaneousPayment(long ptr) : base(null, ptr) { - this.spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr); + long spontaneous_payment = bindings.LDKPaymentPurpose_SpontaneousPayment_get_spontaneous_payment(ptr); + byte[] spontaneous_payment_conv = InternalUtils.decodeUint8Array(spontaneous_payment); + this.spontaneous_payment = spontaneous_payment_conv; } } internal long clone_ptr() { @@ -84,13 +89,14 @@ public class PaymentPurpose : CommonBase { /** * Utility method to constructs a new InvoicePayment-variant PaymentPurpose */ - public static PaymentPurpose invoice_payment(byte[] payment_preimage, byte[] payment_secret) { - long ret = bindings.PaymentPurpose_invoice_payment(InternalUtils.check_arr_len(payment_preimage, 32), InternalUtils.check_arr_len(payment_secret, 32)); + public static PaymentPurpose invoice_payment(org.ldk.structs.Option_ThirtyTwoBytesZ payment_preimage, byte[] payment_secret) { + long ret = bindings.PaymentPurpose_invoice_payment(payment_preimage.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32))); GC.KeepAlive(payment_preimage); GC.KeepAlive(payment_secret); if (ret >= 0 && ret <= 4096) { return null; } 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.AddLast(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_preimage); }; return ret_hu_conv; } @@ -98,7 +104,7 @@ public class PaymentPurpose : CommonBase { * Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose */ public static PaymentPurpose spontaneous_payment(byte[] a) { - long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.check_arr_len(a, 32)); + long ret = bindings.PaymentPurpose_spontaneous_payment(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a, 32))); GC.KeepAlive(a); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.PaymentPurpose ret_hu_conv = org.ldk.structs.PaymentPurpose.constr_from_ptr(ret); @@ -106,20 +112,37 @@ public class PaymentPurpose : CommonBase { return ret_hu_conv; } + /** + * Checks if two PaymentPurposes contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + */ + public bool eq(org.ldk.structs.PaymentPurpose b) { + bool ret = bindings.PaymentPurpose_eq(this.ptr, b == null ? 0 : b.ptr); + GC.KeepAlive(this); + GC.KeepAlive(b); + return ret; + } + + public override bool Equals(object o) { + if (!(o is PaymentPurpose)) return false; + return this.eq((PaymentPurpose)o); + } /** * 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); + long ret = bindings.PaymentPurpose_write(this.ptr); GC.KeepAlive(this); - return ret; + if (ret >= 0 && ret <= 4096) { return null; } + byte[] ret_conv = InternalUtils.decodeUint8Array(ret); + return ret_conv; } /** * Read a PaymentPurpose from a byte array, created by PaymentPurpose_write */ public static Result_PaymentPurposeDecodeErrorZ read(byte[] ser) { - long ret = bindings.PaymentPurpose_read(ser); + long ret = bindings.PaymentPurpose_read(InternalUtils.encodeUint8Array(ser)); GC.KeepAlive(ser); if (ret >= 0 && ret <= 4096) { return null; } Result_PaymentPurposeDecodeErrorZ ret_hu_conv = Result_PaymentPurposeDecodeErrorZ.constr_from_ptr(ret);