Update C++ demo and ldk_net to new clone API and upstream changes
authorMatt Corallo <git@bluematt.me>
Sun, 18 Jul 2021 02:15:27 +0000 (02:15 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 28 Jul 2021 17:06:58 +0000 (17:06 +0000)
ldk-net/ldk_net.c
lightning-c-bindings/demo.cpp

index 18279541e0a88014f8b7621b6855e754be598f1b..dc19e8ee6794a900b1a2a3939940cd333c6d8a85 100644 (file)
@@ -142,12 +142,12 @@ static uint64_t sock_hash(const void* desc) {
        const struct Descriptor *descriptor = (const struct Descriptor*)desc;
        return (uint64_t)descriptor->fd;
 }
-static void* sock_clone(const void* desc) {
-       const struct Descriptor *descriptor = (const struct Descriptor*)desc;
+static void sock_cloned(LDKSocketDescriptor *NONNULL_PTR ldk_desc) {
+       const struct Descriptor *descriptor = (const struct Descriptor*)ldk_desc->this_arg;
        struct Descriptor *new_desc = malloc(sizeof(struct Descriptor));
        new_desc->handler = descriptor->handler;
        new_desc->fd = descriptor->fd;
-       return new_desc;
+       ldk_desc->this_arg = (void*) new_desc;
 }
 static void sock_free(void* desc) {
        free(desc);
@@ -163,7 +163,7 @@ static inline LDKSocketDescriptor get_descriptor(struct SocketHandler *handler,
                .disconnect_socket = sock_disconnect,
                .eq = sock_eq,
                .hash = sock_hash,
-               .clone = sock_clone,
+               .cloned = sock_cloned,
                .free = sock_free,
        };
        return ret;
index b71edc324581052dc102f17d3a0dcbe331a055f2..7c6dfda2e0f1c93ffbe83ba0a7dfbc9c0943ff53 100644 (file)
@@ -308,7 +308,7 @@ public:
                        .disconnect_socket = sock_disconnect_socket,
                        .eq = sock_eq,
                        .hash = sock_hash,
-                       .clone = NULL,
+                       .cloned = NULL,
                        .free = NULL,
                };
 
@@ -318,7 +318,7 @@ public:
                        .disconnect_socket = sock_disconnect_socket,
                        .eq = sock_eq,
                        .hash = sock_hash,
-                       .clone = NULL,
+                       .cloned = NULL,
                        .free = NULL,
                };
 
@@ -637,9 +637,11 @@ int main() {
                        assert(queue.events.size() == 1);
                        assert(queue.events[0]->tag == LDKEvent_PaymentReceived);
                        assert(!memcmp(queue.events[0]->payment_received.payment_hash.data, payment_hash.data, 32));
-                       assert(!memcmp(queue.events[0]->payment_received.payment_secret.data, Invoice_payment_secret(invoice->contents.result).data, 32));
+                       assert(queue.events[0]->payment_received.purpose.tag == LDKPaymentPurpose_InvoicePayment);
+                       assert(!memcmp(queue.events[0]->payment_received.purpose.invoice_payment.payment_secret.data,
+                                       Invoice_payment_secret(invoice->contents.result).data, 32));
                        assert(queue.events[0]->payment_received.amt == 5000);
-                       memcpy(payment_preimage.data, queue.events[0]->payment_received.payment_preimage.data, 32);
+                       memcpy(payment_preimage.data, queue.events[0]->payment_received.purpose.invoice_payment.payment_preimage.data, 32);
                        assert(ChannelManager_claim_funds(&cm2, payment_preimage));
                }
                PeerManager_process_events(&net2);