import org.bitcoinj.script.Script;
import org.junit.jupiter.api.Test;
import org.ldk.batteries.NioPeerHandler;
+import org.ldk.enums.LDKCurrency;
import org.ldk.enums.LDKNetwork;
import org.ldk.impl.bindings;
import org.ldk.structs.*;
public Result_SignDecodeErrorZ read_chan_signer(byte[] reader) {
return underlying_if.read_chan_signer(reader);
}
+
+ @Override
+ public Result_RecoverableSignatureNoneZ sign_invoice(byte[] invoice_preimage) {
+ return underlying_if.sign_invoice(invoice_preimage);
+ }
});
}
txn = new TwoTuple[0];
if (chain_monitor != null) {
chan_manager.as_Listen().block_connected(b.bitcoinSerialize(), height);
- chain_monitor.block_connected(header, txn, height);
+ chain_monitor.as_Listen().block_connected(b.bitcoinSerialize(), height);
} else {
- chan_manager.transactions_confirmed(header, height, txn);
- chan_manager.update_best_block(header, height);
+ chan_manager.as_Confirm().transactions_confirmed(header, txn, height);
+ chan_manager.as_Confirm().best_block_updated(header, height);
// Connect manually if we aren't using a ChainMonitor and are implementing Watch ourselves
synchronized (monitors) {
assert monitors.size() == 1;
assert Arrays.equals(peer1_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
assert Arrays.equals(peer2_chans[0].get_channel_id(), funding.getTxId().getReversedBytes());
- byte[] payment_preimage = new byte[32];
- for (int i = 0; i < 32; i++) payment_preimage[i] = (byte) (i ^ 0x0f);
- byte[] payment_hash = Sha256Hash.hash(payment_preimage);
+ Result_InvoiceNoneZ invoice = UtilMethods.constructor_invoice_from_channelmanager(peer2.chan_manager, peer2.keys_interface, LDKCurrency.LDKCurrency_Bitcoin, Option_u64Z.constructor_none(), new byte[0]);
+ assert invoice instanceof Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK;
+ byte[] payment_hash = ((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) invoice).res.payment_hash();
+ byte[] payment_secret = ((Result_InvoiceNoneZ.Result_InvoiceNoneZ_OK) invoice).res.payment_secret();
+
Route route = peer1.get_route(peer2.node_id, peer1_chans);
- Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, new byte[32]);
+ Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, payment_secret);
assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK;
wait_events_processed(peer1, peer2);
hop_pubkey[1] = 42;
hops[0][0] = RouteHop.constructor_new(hop_pubkey, NodeFeatures.constructor_known(), 42, ChannelFeatures.constructor_known(), 100, 0);
Route r2 = Route.constructor_new(hops);
- payment_res = peer1.chan_manager.send_payment(r2, payment_hash, new byte[32]);
+ payment_res = peer1.chan_manager.send_payment(r2, payment_hash, payment_secret);
assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_Err;
assert peer1.get_monitor_events().length == 0;
WeakReference<Peer> op1 = new WeakReference<Peer>(peer1);
peer1 = new Peer(peer1);
peer2 = new Peer(peer2);
- return new TestState(op1, peer1, peer2, payment_preimage, b.getHash());
+ return new TestState(op1, peer1, peer2, b.getHash());
}
- return new TestState(null, peer1, peer2, payment_preimage, b.getHash());
+ return new TestState(null, peer1, peer2, b.getHash());
}
boolean cross_reload_ref_pollution = false;
private final WeakReference<Peer> ref_block;
private final Peer peer1;
private final Peer peer2;
- private final byte[] payment_preimage;
public Sha256Hash best_blockhash;
- public TestState(WeakReference<Peer> ref_block, Peer peer1, Peer peer2, byte[] payment_preimage, Sha256Hash best_blockhash) {
+ public TestState(WeakReference<Peer> ref_block, Peer peer1, Peer peer2, Sha256Hash best_blockhash) {
this.ref_block = ref_block;
this.peer1 = peer1;
this.peer2 = peer2;
- this.payment_preimage = payment_preimage;
this.best_blockhash = best_blockhash;
}
}
events = state.peer2.chan_manager_events.get_and_clear_pending_events();
assert events.length == 1;
assert events[0] instanceof Event.PaymentReceived;
- state.peer2.chan_manager.claim_funds(state.payment_preimage, new byte[32], ((Event.PaymentReceived) events[0]).amt);
+ byte[] payment_preimage = ((Event.PaymentReceived)events[0]).payment_preimage;
+ assert !Arrays.equals(payment_preimage, new byte[32]);
+ state.peer2.chan_manager.claim_funds(payment_preimage);
wait_events_processed(state.peer1, state.peer2);
events = state.peer1.chan_manager_events.get_and_clear_pending_events();
assert events.length == 1;
assert events[0] instanceof Event.PaymentSent;
- assert Arrays.equals(((Event.PaymentSent) events[0]).payment_preimage, state.payment_preimage);
+ assert Arrays.equals(((Event.PaymentSent) events[0]).payment_preimage, payment_preimage);
wait_events_processed(state.peer1, state.peer2);
ChannelDetails[] peer1_chans = state.peer1.chan_manager.list_channels();
assert Arrays.equals(bindings.ChannelDetails_get_channel_id(peer2_chans[0]), funding.getTxId().getReversedBytes());
for (long chan : peer2_chans) bindings.ChannelDetails_free(chan);
- byte[] payment_preimage = new byte[32];
- for (int i = 0; i < 32; i++) payment_preimage[i] = (byte) (i ^ 0x0f);
- byte[] payment_hash = Sha256Hash.hash(payment_preimage);
+ long no_min_val = bindings.COption_u64Z_none();
+ long inbound_payment = bindings.ChannelManager_create_inbound_payment(peer2.chan_manager, no_min_val, 7200, 42);
+ bindings.COption_u64Z_free(no_min_val);
long netgraph = bindings.NetGraphMsgHandler_read_locked_graph(peer1.router);
long route = bindings.get_route(peer1.node_id, bindings.LockedNetworkGraph_graph(netgraph), peer2.node_id, 0L, peer1_chans,
new long[0], 1000, 42, peer1.logger);
for (long chan : peer1_chans) bindings.ChannelDetails_free(chan);
assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(route);
bindings.LockedNetworkGraph_free(netgraph);
- long payment_res = bindings.ChannelManager_send_payment(peer1.chan_manager, bindings.LDKCResult_RouteLightningErrorZ_get_ok(route), payment_hash, new byte[32]);
+ long payment_res = bindings.ChannelManager_send_payment(peer1.chan_manager, bindings.LDKCResult_RouteLightningErrorZ_get_ok(route),
+ bindings.LDKC2Tuple_PaymentHashPaymentSecretZ_get_a(inbound_payment), bindings.LDKC2Tuple_PaymentHashPaymentSecretZ_get_b(inbound_payment));
bindings.CResult_RouteLightningErrorZ_free(route);
+ bindings.C2Tuple_PaymentHashPaymentSecretZ_free(inbound_payment);
assert bindings.LDKCResult_NonePaymentSendFailureZ_result_ok(payment_res);
bindings.CResult_NonePaymentSendFailureZ_free(payment_res);
assert peer2_events.length == 1;
bindings.LDKEvent payment_recvd = bindings.LDKEvent_ref_from_ptr(peer2_events[0]);
assert payment_recvd instanceof bindings.LDKEvent.PaymentReceived;
- assert bindings.ChannelManager_claim_funds(peer2.chan_manager, payment_preimage, new byte[32], ((bindings.LDKEvent.PaymentReceived)payment_recvd).amt);
+ assert bindings.ChannelManager_claim_funds(peer2.chan_manager, ((bindings.LDKEvent.PaymentReceived) payment_recvd).payment_preimage);
bindings.CVec_EventZ_free(peer2_events);
bindings.PeerManager_process_events(peer2.peer_manager);
assert peer1_events.length == 1;
bindings.LDKEvent sent = bindings.LDKEvent_ref_from_ptr(peer1_events[0]);
assert sent instanceof bindings.LDKEvent.PaymentSent;
- assert Arrays.equals(((bindings.LDKEvent.PaymentSent)sent).payment_preimage, payment_preimage);
bindings.CVec_EventZ_free(peer1_events);
peer1.free();