]> git.bitcoin.ninja Git - ldk-java/commitdiff
Update HumanObjectPeerTest to use new constructor
authorMatt Corallo <git@bluematt.me>
Mon, 8 Mar 2021 02:56:41 +0000 (21:56 -0500)
committerMatt Corallo <git@bluematt.me>
Mon, 8 Mar 2021 02:59:04 +0000 (21:59 -0500)
src/test/java/org/ldk/HumanObjectPeerTest.java

index cb79ff664310b7e934d88e4b63ee203129903fa8..a2d364be6b71f94fbd8a0002de10596084a10ae5 100644 (file)
@@ -4,6 +4,7 @@ import org.bitcoinj.core.*;
 import org.bitcoinj.core.Transaction;
 import org.bitcoinj.script.Script;
 import org.junit.jupiter.api.Test;
+import org.ldk.batteries.ChannelManagerConstructor;
 import org.ldk.batteries.NioPeerHandler;
 import org.ldk.enums.LDKNetwork;
 import org.ldk.impl.bindings;
@@ -13,6 +14,7 @@ import org.ldk.util.TwoTuple;
 import java.io.IOException;
 import java.lang.ref.WeakReference;
 import java.net.InetSocketAddress;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -264,28 +266,39 @@ class HumanObjectPeerTestInstance {
         Object ptr_to;
         Peer(Peer orig) {
             this(null, orig.seed);
-            ChannelMonitor[] monitors = new ChannelMonitor[1];
-            synchronized (monitors) {
-                assert orig.monitors.size() == 1;
-                monitors[0] = orig.monitors.values().stream().iterator().next();
-                if (break_cross_peer_refs) {
-                    Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = UtilMethods.constructor_BlockHashChannelMonitorZ_read(monitors[0].write(), keys_interface);
-                    assert res instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
-                    monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.b;
+            if (!break_cross_peer_refs) {
+                ChannelMonitor[] monitors = new ChannelMonitor[1];
+                synchronized (monitors) {
+                    assert orig.monitors.size() == 1;
+                    monitors[0] = orig.monitors.values().stream().iterator().next();
+                }
+                byte[] serialized = orig.chan_manager.write();
+                Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res =
+                        UtilMethods.constructor_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.constructor_default(), monitors);
+                assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK;
+                this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b;
+                this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]);
+            } else {
+                final ArrayList<byte[]> channel_monitors = new ArrayList();
+                synchronized (monitors) {
+                    assert orig.monitors.size() == 1;
+                    channel_monitors.add(orig.monitors.values().stream().iterator().next().write());
+                }
+                byte[] serialized = orig.chan_manager.write();
+                try {
+                    ChannelManagerConstructor constructed = new ChannelManagerConstructor(serialized, channel_monitors.toArray(new byte[1][]), this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger);
+                    this.chan_manager = constructed.channel_manager;
+                    constructed.chain_sync_completed();
+                } catch (ChannelManagerConstructor.InvalidSerializedDataException e) {
+                    assert false;
                 }
             }
-            byte[] serialized = orig.chan_manager.write();
-            Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res =
-                    UtilMethods.constructor_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.constructor_default(), monitors);
             if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) {
                 // When we pass monitors[0] into chain_watch.watch_channel we create a reference from the new Peer to a
                 // field in the old peer, preventing freeing of the original Peer until the new Peer is freed. Thus, we
                 // shouldn't bother waiting for the original to be freed later on.
                 cross_reload_ref_pollution = true;
             }
-            this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]);
-            assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK;
-            this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b;
             this.node_id = chan_manager.get_our_node_id();
             this.chan_manager_events = chan_manager.as_EventsProvider();