[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / src / test / java / org / ldk / HumanObjectPeerTest.java
index 322b5695f9f27d265984d658eefe10a804db47e9..7a30f10ada867b8d3057def08919c140fb18c059 100644 (file)
@@ -78,7 +78,7 @@ class HumanObjectPeerTestInstance {
             SignerProvider underlying_sp = underlying_km.as_SignerProvider();
             must_free_objs.add(new WeakReference<>(underlying_sp));
             return SignerProvider.new_impl(new SignerProvider.SignerProviderInterface() {
-                @Override public Result_CVec_u8ZNoneZ get_destination_script() { return underlying_sp.get_destination_script(); }
+                @Override public Result_CVec_u8ZNoneZ get_destination_script(byte[] channel_keys_id) { return underlying_sp.get_destination_script(channel_keys_id); }
                 @Override public Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey() { return underlying_sp.get_shutdown_scriptpubkey(); }
                 @Override public byte[] generate_channel_keys_id(boolean inbound, long channel_value_satoshis, UInt128 user_channel_id) {
                     return underlying_sp.generate_channel_keys_id(inbound, channel_value_satoshis, user_channel_id);
@@ -99,17 +99,17 @@ class HumanObjectPeerTestInstance {
                             @Override public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] preimages) {
                                 return underlying_cs.validate_holder_commitment(holder_tx, preimages);
                             }
+                            @Override public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
+                                return underlying_cs.validate_counterparty_revocation(idx, secret);
+                            }
                             @Override public byte[] channel_keys_id() { return underlying_cs.channel_keys_id(); }
                             @Override public void provide_channel_parameters(ChannelTransactionParameters channel_parameters) {
                                 underlying_cs.provide_channel_parameters(channel_parameters);
                             }
                         };
                         EcdsaChannelSigner.EcdsaChannelSignerInterface ecsi = new EcdsaChannelSigner.EcdsaChannelSignerInterface() {
-                            @Override public Result_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] preimages) {
-                                return underlying_ecs.sign_counterparty_commitment(commitment_tx, preimages);
-                            }
-                            @Override public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
-                                return underlying_ecs.validate_counterparty_revocation(idx, secret);
+                            @Override public Result_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] inbound_htlc_preimages, byte[][] outbound_htlc_preimages) {
+                                return underlying_ecs.sign_counterparty_commitment(commitment_tx, inbound_htlc_preimages, outbound_htlc_preimages);
                             }
                             @Override public Result_ECDSASignatureNoneZ sign_holder_commitment(HolderCommitmentTransaction commitment_tx) {
                                 return underlying_ecs.sign_holder_commitment(commitment_tx);
@@ -178,16 +178,16 @@ class HumanObjectPeerTestInstance {
                 }
 
                 @Override
-                public ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events() {
+                public FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] release_pending_monitor_events() {
                     synchronized (monitors) {
                         assert monitors.size() <= 1;
                         for (ChannelMonitor mon : monitors.values()) {
-                            ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[] res = new ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[1];
-                            res[0] = ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ.of(mon.get_funding_txo().get_a(), mon.get_and_clear_pending_monitor_events(), mon.get_counterparty_node_id());
+                            FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[] res = new FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[1];
+                            res[0] = FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ.of(mon.get_funding_txo().get_a(), ChannelId.of(new byte[32]), mon.get_and_clear_pending_monitor_events(), mon.get_counterparty_node_id());
                             return res;
                         }
                     }
-                    return new ThreeTuple_OutPointCVec_MonitorEventZPublicKeyZ[0];
+                    return new FourTuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZ[0];
                 }
             };
             Watch watch = Watch.new_impl(watch_impl);
@@ -277,7 +277,7 @@ class HumanObjectPeerTestInstance {
                 @Override
                 public ChannelMonitorUpdateStatus persist_new_channel(OutPoint id, ChannelMonitor data, MonitorUpdateId update_id) {
                     synchronized (monitors) {
-                        String key = Arrays.toString(id.to_channel_id());
+                        String key = Arrays.toString(ChannelId.v1_from_funding_outpoint(id).get_a());
                         ChannelMonitor res = test_mon_roundtrip(id, data.write());
                         assert monitors.put(key, res) == null;
                     }
@@ -287,7 +287,7 @@ class HumanObjectPeerTestInstance {
                 @Override
                 public ChannelMonitorUpdateStatus update_persisted_channel(OutPoint id, ChannelMonitorUpdate update, ChannelMonitor data, MonitorUpdateId update_id) {
                     synchronized (monitors) {
-                        String key = Arrays.toString(id.to_channel_id());
+                        String key = Arrays.toString(ChannelId.v1_from_funding_outpoint(id).get_a());
                         ChannelMonitor res = test_mon_roundtrip(id, data.write());
                         // Note that we use a serialization-roundtrip copy of data here, not the original, as this can
                         // expose the JVM JIT bug where it finalize()s things still being called.
@@ -295,6 +295,11 @@ class HumanObjectPeerTestInstance {
                     }
                     return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed;
                 }
+
+                @Override
+                public void archive_persisted_channel(OutPoint channel_funding_outpoint) {
+                    assert false;
+                }
             });
 
             filter_additions = new HashSet<>();
@@ -438,6 +443,11 @@ class HumanObjectPeerTestInstance {
                         return find_route(payer, route_params, first_hops, inflight_htlcs);
                     }
 
+                    @Override
+                    public Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, ReceiveTlvs tlvs, long amount_msats) {
+                        return Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ.err();
+                    }
+
                     @Override
                     public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs) {
                         while (true) {
@@ -457,9 +467,16 @@ class HumanObjectPeerTestInstance {
                                 break;
                             }
                         }
-                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, ScoreLookUp.new_impl(new ScoreLookUp.ScoreLookUpInterface() {
-                            @Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage, ProbabilisticScoringFeeParameters params) { return 0; }
-                        }), ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger,
+                                ScoreLookUp.new_impl((candidate, usage, params1) -> candidate.source().as_slice()[1]),
+                                ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                    }
+                }, new MessageRouter.MessageRouterInterface() {
+                    @Override public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination) {
+                        return Result_OnionMessagePathNoneZ.err();
+                    }
+                    @Override public Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers) {
+                        return Result_CVec_BlindedPathZNoneZ.err();
                     }
                 });
                 ChainParameters params = ChainParameters.of(Network.LDKNetwork_Bitcoin, BestBlock.of(new byte[32], 0));
@@ -543,6 +560,11 @@ class HumanObjectPeerTestInstance {
                         return find_route(payer, route_params, first_hops, inflight_htlcs);
                     }
 
+                    @Override
+                    public Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ create_blinded_payment_paths(byte[] recipient, ChannelDetails[] first_hops, ReceiveTlvs tlvs, long amount_msats) {
+                        return Result_CVec_C2Tuple_BlindedPayInfoBlindedPathZZNoneZ.err();
+                    }
+
                     @Override
                     public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters params, ChannelDetails[] first_hops, InFlightHtlcs inflight_htlcs) {
                         while (true) {
@@ -562,9 +584,16 @@ class HumanObjectPeerTestInstance {
                                 break;
                             }
                         }
-                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger, ScoreLookUp.new_impl(new ScoreLookUp.ScoreLookUpInterface() {
-                            @Override public long channel_penalty_msat(long short_channel_id, NodeId source, NodeId target, ChannelUsage usage, ProbabilisticScoringFeeParameters params) { return 0; }
-                        }), ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                        return UtilMethods.find_route(payer, params, net_graph, first_hops, logger,
+                                ScoreLookUp.new_impl((candidate, usage, params1) -> candidate.source().as_slice()[0]),
+                                ProbabilisticScoringFeeParameters.with_default(), new byte[32]);
+                    }
+                }, new MessageRouter.MessageRouterInterface() {
+                    @Override public Result_OnionMessagePathNoneZ find_path(byte[] sender, byte[][] peers, Destination destination) {
+                        return Result_OnionMessagePathNoneZ.err();
+                    }
+                    @Override public Result_CVec_BlindedPathZNoneZ create_blinded_paths(byte[] recipient, byte[][] peers) {
+                        return Result_CVec_BlindedPathZNoneZ.err();
                     }
                 });
                 this.setup_route_handler();
@@ -798,7 +827,7 @@ class HumanObjectPeerTestInstance {
             try {
                 peer1.nio_peer_handler.connect(peer2.chan_manager.get_our_node_id(), new InetSocketAddress("127.0.0.1", peer2.nio_port), 100);
             } catch (IOException e) { assert false; }
-            while (peer1.peer_manager.get_peer_node_ids().length == 0 || peer2.peer_manager.get_peer_node_ids().length == 0) {
+            while (peer1.peer_manager.list_peers().length == 0 || peer2.peer_manager.list_peers().length == 0) {
                 Thread.yield();
             }
         } else {
@@ -847,8 +876,8 @@ class HumanObjectPeerTestInstance {
 
         UInt128 user_id = new UInt128(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
 
-        Result_ThirtyTwoBytesAPIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, user_id, null);
-        assert cc_res instanceof Result_ThirtyTwoBytesAPIErrorZ.Result_ThirtyTwoBytesAPIErrorZ_OK;
+        Result_ChannelIdAPIErrorZ cc_res = peer1.chan_manager.create_channel(peer2.node_id, 100000, 1000, user_id, null, null);
+        assert cc_res instanceof Result_ChannelIdAPIErrorZ.Result_ChannelIdAPIErrorZ_OK;
 
         // Previously, this was a SEGFAULT instead of get_funding_txo() returning null.
         ChannelDetails pre_funding_chan = peer1.chan_manager.list_channels()[0];
@@ -860,7 +889,7 @@ class HumanObjectPeerTestInstance {
         assert ((Event.FundingGenerationReady) events[0]).user_channel_id.equals(user_id);
         byte[] funding_spk = ((Event.FundingGenerationReady) events[0]).output_script;
         assert funding_spk.length == 34 && funding_spk[0] == 0 && funding_spk[1] == 32; // P2WSH
-        byte[] chan_id = ((Event.FundingGenerationReady) events[0]).temporary_channel_id;
+        ChannelId chan_id = ((Event.FundingGenerationReady) events[0]).temporary_channel_id;
 
         BitcoinNetworkParams bitcoinj_net = BitcoinNetworkParams.of(BitcoinNetwork.MAINNET);
 
@@ -921,8 +950,8 @@ class HumanObjectPeerTestInstance {
         Option_u64Z short_chan_id = peer1_chans[0].get_short_channel_id();
         assert short_chan_id instanceof Option_u64Z.Some;
         assert ((Option_u64Z.Some)short_chan_id).some == (1L << 40); // 0th output in the 0th transaction in the 1st block
-        assert Arrays.equals(peer1_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
-        assert Arrays.equals(peer2_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
+        assert Arrays.equals(peer1_chans[0].get_channel_id().get_a(), funding.getTxId().getReversedBytes());
+        assert Arrays.equals(peer2_chans[0].get_channel_id().get_a(), funding.getTxId().getReversedBytes());
 
         // Generate a random invoice description to exercise the string conversion logic a good bit
         String invoice_description;
@@ -948,7 +977,7 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
         RawBolt11Invoice raw_invoice = signed_raw.raw_invoice();
         byte[] desc_hash = raw_invoice.signable_hash();
         Description raw_invoice_description = raw_invoice.description();
-        String description_string = raw_invoice_description.into_inner();
+        String description_string = raw_invoice_description.into_inner().get_a();
         boolean has_null = false;
         for (byte db : invoice_description.getBytes())
             if (db == 0)
@@ -981,7 +1010,7 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
             RouteHint[] route_hints = ((Result_Bolt11InvoiceSignOrCreationErrorZ.Result_Bolt11InvoiceSignOrCreationErrorZ_OK) invoice).res.route_hints();
 
             Payee payee = Payee.clear(peer2.node_id, route_hints, invoice_features, 42);
-            PaymentParameters pay_params = PaymentParameters.of(payee, Option_u64Z.none(), 6*24*14, (byte)1, (byte)2, new long[0]);
+            PaymentParameters pay_params = PaymentParameters.of(payee, Option_u64Z.none(), 6*24*14, (byte)1, (byte)2, new long[0], new long[0]);
             RouteParameters route_params = RouteParameters.from_payment_params_and_value(pay_params, 10000000);
             Result_RouteLightningErrorZ route_res = UtilMethods.find_route(
                     peer1.chan_manager.get_our_node_id(), route_params, peer1.net_graph,
@@ -1011,8 +1040,13 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
             payment_res = peer1.chan_manager.send_payment_with_route(r2, payment_hash, RecipientOnionFields.secret_only(payment_secret), payment_id);
             assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err;
         } else {
-            Result_ThirtyTwoBytesPaymentErrorZ send_res = UtilMethods.pay_invoice(((Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res, Retry.attempts(0), peer1.chan_manager);
-            assert send_res instanceof Result_ThirtyTwoBytesPaymentErrorZ.Result_ThirtyTwoBytesPaymentErrorZ_OK;
+            Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ pay_params_res =
+                UtilMethods.payment_parameters_from_invoice(((Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_Bolt11InvoiceParseOrSemanticErrorZ_OK) parsed_invoice).res);
+            assert pay_params_res.is_ok();
+            Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK pay_params =
+                (Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ.Result_C3Tuple_ThirtyTwoBytesRecipientOnionFieldsRouteParametersZNoneZ_OK)pay_params_res;
+            Result_NoneRetryableSendFailureZ pay_res = peer1.chan_manager.send_payment(pay_params.res.get_a(), pay_params.res.get_b(), new byte[32], pay_params.res.get_c(), Retry.attempts(0));
+            assert pay_res.is_ok();
         }
 
         if (reload_peers) {
@@ -1072,17 +1106,17 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
 
         events = state.peer2.get_manager_events(1, state.peer1, state.peer2);
         assert events[0] instanceof Event.PaymentClaimable;
-        assert ((Event.PaymentClaimable)events[0]).purpose instanceof PaymentPurpose.InvoicePayment;
-        assert ((PaymentPurpose.InvoicePayment) ((Event.PaymentClaimable)events[0]).purpose).payment_preimage instanceof Option_ThirtyTwoBytesZ.Some;
-        byte[] payment_preimage = ((Option_ThirtyTwoBytesZ.Some) ((PaymentPurpose.InvoicePayment)((Event.PaymentClaimable)events[0]).purpose).payment_preimage).some;
+        assert ((Event.PaymentClaimable)events[0]).purpose instanceof PaymentPurpose.Bolt11InvoicePayment;
+        assert ((PaymentPurpose.Bolt11InvoicePayment) ((Event.PaymentClaimable)events[0]).purpose).payment_preimage instanceof Option_ThirtyTwoBytesZ.Some;
+        byte[] payment_preimage = ((Option_ThirtyTwoBytesZ.Some) ((PaymentPurpose.Bolt11InvoicePayment)((Event.PaymentClaimable)events[0]).purpose).payment_preimage).some;
         assert !Arrays.equals(payment_preimage, new byte[32]);
         state.peer2.chan_manager.claim_funds(payment_preimage);
 
         events = state.peer2.get_manager_events(1, state.peer1, state.peer2);
         assert events[0] instanceof Event.PaymentClaimed;
-        assert ((Event.PaymentClaimed)events[0]).purpose instanceof PaymentPurpose.InvoicePayment;
-        assert ((PaymentPurpose.InvoicePayment) ((Event.PaymentClaimed)events[0]).purpose).payment_preimage instanceof  Option_ThirtyTwoBytesZ.Some;
-        payment_preimage = ((Option_ThirtyTwoBytesZ.Some)((PaymentPurpose.InvoicePayment)((Event.PaymentClaimed)events[0]).purpose).payment_preimage).some;
+        assert ((Event.PaymentClaimed)events[0]).purpose instanceof PaymentPurpose.Bolt11InvoicePayment;
+        assert ((PaymentPurpose.Bolt11InvoicePayment) ((Event.PaymentClaimed)events[0]).purpose).payment_preimage instanceof  Option_ThirtyTwoBytesZ.Some;
+        payment_preimage = ((Option_ThirtyTwoBytesZ.Some)((PaymentPurpose.Bolt11InvoicePayment)((Event.PaymentClaimed)events[0]).purpose).payment_preimage).some;
         assert !Arrays.equals(payment_preimage, new byte[32]);
 
         events = state.peer1.get_manager_events(2, state.peer1, state.peer2);
@@ -1173,15 +1207,11 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
             }
 
             Event[] broadcastable_event = state.peer2.get_monitor_events(1);
-            for (ChannelMonitor mon : state.peer2.monitors.values()) {
-                // This used to be buggy and double-free, so go ahead and fetch them!
-                byte[][] txn = mon.get_latest_holder_commitment_txn(state.peer2.logger);
-            }
             assert broadcastable_event.length == 1;
             assert broadcastable_event[0] instanceof Event.SpendableOutputs;
             if (state.peer2.explicit_keys_manager != null) {
                 TxOut[] additional_outputs = new TxOut[]{new TxOut(420, new byte[]{0x42})};
-                Result_TransactionNoneZ tx_res = state.peer2.explicit_keys_manager.spend_spendable_outputs(((Event.SpendableOutputs) broadcastable_event[0]).outputs, additional_outputs, new byte[]{0x00}, 253, Option_u32Z.none());
+                Result_TransactionNoneZ tx_res = state.peer2.explicit_keys_manager.as_OutputSpender().spend_spendable_outputs(((Event.SpendableOutputs) broadcastable_event[0]).outputs, additional_outputs, new byte[]{0x00}, 253, Option_u32Z.none());
                 assert tx_res instanceof Result_TransactionNoneZ.Result_TransactionNoneZ_OK;
                 Transaction built_tx = new Transaction(bitcoinj_net, ((Result_TransactionNoneZ.Result_TransactionNoneZ_OK) tx_res).res);
                 assert built_tx.getOutputs().size() == 2;
@@ -1190,7 +1220,7 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
                 assert built_tx.getOutput(0).getValue().value == 420;
             }
 
-            while (state.peer1.peer_manager.get_peer_node_ids().length != 0 || state.peer2.peer_manager.get_peer_node_ids().length != 0) {
+            while (state.peer1.peer_manager.list_peers().length != 0 || state.peer2.peer_manager.list_peers().length != 0) {
                 // LDK disconnects peers before sending an error message, so wait for disconnection.
                 Thread.sleep(10);
             }
@@ -1221,8 +1251,8 @@ if (parsed_invoice instanceof Result_Bolt11InvoiceParseOrSemanticErrorZ.Result_B
 
         if (use_nio_peer_handler) {
             state.peer1.peer_manager.disconnect_by_node_id(state.peer2.chan_manager.get_our_node_id());
-            while (state.peer1.peer_manager.get_peer_node_ids().length != 0) Thread.yield();
-            while (state.peer2.peer_manager.get_peer_node_ids().length != 0) Thread.yield();
+            while (state.peer1.peer_manager.list_peers().length != 0) Thread.yield();
+            while (state.peer2.peer_manager.list_peers().length != 0) Thread.yield();
             state.peer1.nio_peer_handler.interrupt();
             state.peer2.nio_peer_handler.interrupt();
         }
@@ -1359,6 +1389,7 @@ public class HumanObjectPeerTest {
         } catch (Exception e) {
             System.err.println("Caught exception:");
             System.err.println(e);
+            e.printStackTrace();
             System.exit(1);
         }
     }