11package org .ldk ;
22
3- import org .bitcoinj .base .BitcoinNetwork ;
43import org .bitcoinj .base .Coin ;
54import org .bitcoinj .base .Sha256Hash ;
65import org .bitcoinj .core .*;
7- import org .bitcoinj .params .BitcoinNetworkParams ;
86import org .bitcoinj .script .Script ;
97import org .junit .jupiter .api .Test ;
108import org .ldk .batteries .ChannelManagerConstructor ;
1917import java .io .IOException ;
2018import java .lang .ref .WeakReference ;
2119import java .net .InetSocketAddress ;
20+ import java .nio .ByteBuffer ;
21+ import java .time .Instant ;
2222import java .util .*;
2323import java .util .function .IntConsumer ;
2424
@@ -35,6 +35,7 @@ class HumanObjectPeerTestInstance {
3535 private final boolean use_chan_manager_constructor ;
3636 private final boolean use_invoice_payer ;
3737 TxOut gossip_txout = null ;
38+ final Instant TIME_42 = Instant .ofEpochSecond (42 );
3839
3940 HumanObjectPeerTestInstance (boolean nice_close , boolean use_km_wrapper , boolean use_full_km_wrapper , boolean use_manual_watch , boolean reload_peers , boolean break_cross_peer_refs , boolean use_nio_peer_handler , boolean use_filter , boolean use_ignore_handler , boolean use_chan_manager_constructor , boolean use_invoice_payer ) {
4041 this .nice_close = nice_close ;
@@ -653,17 +654,17 @@ public Result_CVec_BlindedMessagePathZNoneZ create_compact_blinded_paths(byte[]
653654 }
654655
655656 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ [] connect_block (Block b , int height , long expected_monitor_update_len ) {
656- byte [] header = Arrays .copyOfRange (b .bitcoinSerialize (), 0 , 80 );
657+ byte [] header = Arrays .copyOfRange (b .serialize (), 0 , 80 );
657658 TwoTuple_usizeTransactionZ [] txn ;
658659 if (b .hasTransactions ()) {
659660 assert b .getTransactions ().size () == 1 ;
660- TwoTuple_usizeTransactionZ txp = TwoTuple_usizeTransactionZ .of ((long ) 0 , b .getTransactions ().get (0 ).bitcoinSerialize ());
661+ TwoTuple_usizeTransactionZ txp = TwoTuple_usizeTransactionZ .of ((long ) 0 , b .getTransactions ().get (0 ).serialize ());
661662 txn = new TwoTuple_usizeTransactionZ []{txp };
662663 } else
663664 txn = new TwoTuple_usizeTransactionZ [0 ];
664665 if (chain_monitor != null ) {
665- chan_manager .as_Listen ().block_connected (b .bitcoinSerialize (), height );
666- chain_monitor .as_Listen ().block_connected (b .bitcoinSerialize (), height );
666+ chan_manager .as_Listen ().block_connected (b .serialize (), height );
667+ chain_monitor .as_Listen ().block_connected (b .serialize (), height );
667668 } else {
668669 chan_manager .as_Confirm ().transactions_confirmed (header , txn , height );
669670 chan_manager .as_Confirm ().best_block_updated (header , height );
@@ -769,7 +770,7 @@ Event[] get_manager_events(int expected_len, Peer peer1, Peer peer2) {
769770 static class DescriptorHolder { SocketDescriptor val ; }
770771
771772 boolean running = false ;
772- final LinkedList <Runnable > runqueue = new LinkedList ();
773+ final LinkedList <Runnable > runqueue = new LinkedList <> ();
773774 boolean ran = false ;
774775 Thread t = new Thread (() -> {
775776 while (true ) {
@@ -913,16 +914,13 @@ TestState do_test_message_handler() throws InterruptedException {
913914 ChannelId chan_id = ((Event .FundingGenerationReady ) events [0 ]).temporary_channel_id ;
914915 mid_test_must_free_objs .add (new WeakReference <>(chan_id ));
915916
916- BitcoinNetworkParams bitcoinj_net = BitcoinNetworkParams .of (BitcoinNetwork .MAINNET );
917-
918- Transaction funding_input = new Transaction (bitcoinj_net );
919- funding_input .addOutput (Coin .SATOSHI .multiply (100000 ), new Script (funding_spk ));
920- Transaction funding = new Transaction (bitcoinj_net );
917+ Transaction funding_input = new Transaction ();
918+ funding_input .addOutput (Coin .ofSat (100000 ), Script .parse (funding_spk ));
919+ Transaction funding = new Transaction ();
921920 funding .addInput (funding_input .getOutput (0 ));
922- funding .getInputs ().get (0 ).setWitness (new TransactionWitness (2 )); // Make sure we don't complain about lack of witness
923- funding .getInput (0 ).getWitness ().setPush (0 , new byte []{0x1 });
924- funding .addOutput (Coin .SATOSHI .multiply (100000 ), new Script (funding_spk ));
925- Result_NoneAPIErrorZ funding_res = peer1 .chan_manager .funding_transaction_generated (chan_id , peer2 .node_id , funding .bitcoinSerialize ());
921+ funding .getInput (0 ).setWitness (TransactionWitness .of (new byte []{0x1 })); // Make sure we don't complain about lack of witness
922+ funding .addOutput (Coin .ofSat (100000 ), Script .parse (funding_spk ));
923+ Result_NoneAPIErrorZ funding_res = peer1 .chan_manager .funding_transaction_generated (chan_id , peer2 .node_id , funding .serialize ());
926924 assert funding_res instanceof Result_NoneAPIErrorZ .Result_NoneAPIErrorZ_OK ;
927925
928926 gossip_txout = new TxOut (100000 , funding_spk );
@@ -943,16 +941,16 @@ TestState do_test_message_handler() throws InterruptedException {
943941 mid_test_must_free_objs .add (new WeakReference <>(events [0 ]));
944942
945943 assert peer1 .broadcast_set .size () == 1 ;
946- assert Arrays .equals (peer1 .broadcast_set .get (0 ), funding .bitcoinSerialize ());
944+ assert Arrays .equals (peer1 .broadcast_set .get (0 ), funding .serialize ());
947945 mid_test_must_free_objs .add (new WeakReference <>(peer1 .broadcast_set .get (0 )));
948946 peer1 .broadcast_set .clear ();
949947
950- Block b = new Block (bitcoinj_net , 2 , Sha256Hash .ZERO_HASH , Sha256Hash .ZERO_HASH , 42 , 0 , 0 , Arrays . asList ( new Transaction []{ funding } ));
948+ Block b = new Block (2 , Sha256Hash .ZERO_HASH , Sha256Hash .ZERO_HASH , TIME_42 , 0 , 0 , List . of ( funding ));
951949 peer1 .connect_block (b , 1 , 0 );
952950 peer2 .connect_block (b , 1 , 0 );
953951
954952 for (int height = 2 ; height < 10 ; height ++) {
955- b = new Block (bitcoinj_net , 2 , b .getHash (), Sha256Hash .ZERO_HASH , 42 , 0 , 0 , Arrays . asList ( new Transaction [ 0 ] ));
953+ b = new Block (2 , b .getHash (), Sha256Hash .ZERO_HASH , TIME_42 , 0 , 0 , List . of ( ));
956954 peer1 .connect_block (b , height , 0 );
957955 peer2 .connect_block (b , height , 0 );
958956 }
@@ -977,8 +975,8 @@ TestState do_test_message_handler() throws InterruptedException {
977975 Option_u64Z short_chan_id = peer1_chans [0 ].get_short_channel_id ();
978976 assert short_chan_id instanceof Option_u64Z .Some ;
979977 assert ((Option_u64Z .Some )short_chan_id ).some == (1L << 40 ); // 0th output in the 0th transaction in the 1st block
980- assert Arrays .equals (peer1_chans [0 ].get_channel_id ().get_a (), funding .getTxId ().getReversedBytes ());
981- assert Arrays .equals (peer2_chans [0 ].get_channel_id ().get_a (), funding .getTxId ().getReversedBytes ());
978+ assert Arrays .equals (peer1_chans [0 ].get_channel_id ().get_a (), funding .getTxId ().serialize ());
979+ assert Arrays .equals (peer2_chans [0 ].get_channel_id ().get_a (), funding .getTxId ().serialize ());
982980 mid_test_must_free_objs .add (new WeakReference <>(peer1_chans [0 ]));
983981 mid_test_must_free_objs .add (new WeakReference <>(peer2_chans [0 ]));
984982
@@ -1222,21 +1220,19 @@ void do_test_message_handler_b(TestState state) throws Exception {
12221220 }
12231221
12241222 if (!nice_close ) {
1225- BitcoinNetworkParams bitcoinj_net = BitcoinNetworkParams .of (BitcoinNetwork .MAINNET );
1226- Transaction tx = new Transaction (bitcoinj_net , state .peer1 .broadcast_set .getFirst ());
1227- Block b = new Block (bitcoinj_net , 2 , state .best_blockhash , Sha256Hash .ZERO_HASH , 42 , 0 , 0 ,
1228- Arrays .asList (new Transaction []{tx }));
1223+ Transaction tx = Transaction .read (ByteBuffer .wrap (state .peer1 .broadcast_set .getFirst ()));
1224+ Block b = new Block (2 , state .best_blockhash , Sha256Hash .ZERO_HASH , TIME_42 , 0 , 0 , List .of (tx ));
12291225 TwoTuple_ThirtyTwoBytesCVec_C2Tuple_u32TxOutZZZ [] watch_outputs = state .peer2 .connect_block (b , 10 , 1 );
12301226 if (watch_outputs != null ) { // We only process watch_outputs manually when we use a manually-build Watch impl
12311227 assert watch_outputs .length == 1 ;
1232- assert Arrays .equals (watch_outputs [0 ].get_a (), tx .getTxId ().getReversedBytes ());
1228+ assert Arrays .equals (watch_outputs [0 ].get_a (), tx .getTxId ().serialize ());
12331229 assert watch_outputs [0 ].get_b ().length == 2 ;
12341230 assert watch_outputs [0 ].get_b ()[0 ].get_a () == 0 ;
12351231 assert watch_outputs [0 ].get_b ()[1 ].get_a () == 1 ;
12361232 }
12371233
12381234 for (int i = 11 ; i < 21 ; i ++) {
1239- b = new Block (bitcoinj_net , 2 , b .getHash (), Sha256Hash .ZERO_HASH , 42 , 0 , 0 , new ArrayList <> ());
1235+ b = new Block (2 , b .getHash (), Sha256Hash .ZERO_HASH , TIME_42 , 0 , 0 , List . of ());
12401236 state .peer2 .connect_block (b , i , 0 );
12411237 }
12421238
@@ -1247,7 +1243,7 @@ void do_test_message_handler_b(TestState state) throws Exception {
12471243 TxOut [] additional_outputs = new TxOut []{new TxOut (420 , new byte []{0x42 })};
12481244 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 ());
12491245 assert tx_res instanceof Result_TransactionNoneZ .Result_TransactionNoneZ_OK ;
1250- Transaction built_tx = new Transaction ( bitcoinj_net , (( Result_TransactionNoneZ .Result_TransactionNoneZ_OK ) tx_res ).res );
1246+ Transaction built_tx = Transaction . read ( ByteBuffer . wrap ((( Result_TransactionNoneZ .Result_TransactionNoneZ_OK ) tx_res ).res ) );
12511247 assert built_tx .getOutputs ().size () == 2 ;
12521248 assert Arrays .equals (built_tx .getOutput (1 ).getScriptBytes (), new byte []{0x00 });
12531249 assert Arrays .equals (built_tx .getOutput (0 ).getScriptBytes (), new byte []{0x42 });
@@ -1323,8 +1319,8 @@ void do_test_message_handler_b(TestState state) throws Exception {
13231319 }
13241320 }
13251321
1326- LinkedList <WeakReference <Object >> must_free_objs = new LinkedList ();
1327- LinkedList <WeakReference <Object >> mid_test_must_free_objs = new LinkedList ();
1322+ LinkedList <WeakReference <Object >> must_free_objs = new LinkedList <> ();
1323+ LinkedList <WeakReference <Object >> mid_test_must_free_objs = new LinkedList <> ();
13281324 int gc_count = 0 ;
13291325 int gc_exp_count = 0 ;
13301326 class GcCheck {
0 commit comments