final Logger logger;
final FeeEstimator fee_estimator;
final BroadcasterInterface tx_broadcaster;
- final KeysManager keys;
final KeysInterface keys_interface;
final ChannelManager chan_manager;
final EventsProvider chan_manager_events;
final PeerManager peer_manager;
final HashMap<String, ChannelMonitor> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
byte[] node_id;
- final LinkedList<org.ldk.structs.Transaction> broadcast_set = new LinkedList<>();
+ final LinkedList<byte[]> broadcast_set = new LinkedList<>();
Peer(byte seed) {
- logger = new Logger((String arg) -> System.out.println(seed + ": " + arg));
- fee_estimator = new FeeEstimator((confirmation_target -> 253));
- tx_broadcaster = new BroadcasterInterface(tx -> {
+ logger = Logger.new_impl((String arg) -> System.out.println(seed + ": " + arg));
+ fee_estimator = FeeEstimator.new_impl((confirmation_target -> 253));
+ tx_broadcaster = BroadcasterInterface.new_impl(tx -> {
broadcast_set.add(tx);
});
this.monitors = new HashMap<>();
- Watch chain_monitor = new Watch(new Watch.WatchInterface() {
+ Watch chain_monitor = Watch.new_impl(new Watch.WatchInterface() {
public Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor) {
synchronized (monitors) {
assert monitors.put(Arrays.toString(funding_txo.get_txid()), monitor) == null;
for (byte i = 0; i < 32; i++) {
key_seed[i] = (byte) (i ^ seed);
}
- this.keys = KeysManager.constructor_new(key_seed, LDKNetwork.LDKNetwork_Bitcoin, System.currentTimeMillis() / 1000, (int) (System.currentTimeMillis() * 1000) & 0xffffffff);
+ KeysManager keys = KeysManager.constructor_new(key_seed, LDKNetwork.LDKNetwork_Bitcoin, System.currentTimeMillis() / 1000, (int) (System.currentTimeMillis() * 1000) & 0xffffffff);
this.keys_interface = keys.as_KeysInterface();
- this.chan_manager = ChannelManager.constructor_new(LDKNetwork.LDKNetwork_Bitcoin, new FeeEstimator(confirmation_target -> 0), chain_monitor, tx_broadcaster, logger, keys.as_KeysInterface(), UserConfig.constructor_default(), 1);
+ this.chan_manager = ChannelManager.constructor_new(LDKNetwork.LDKNetwork_Bitcoin, FeeEstimator.new_impl(confirmation_target -> 0), chain_monitor, tx_broadcaster, logger, this.keys_interface, UserConfig.constructor_default(), 1);
this.node_id = chan_manager.get_our_node_id();
this.chan_manager_events = chan_manager.as_EventsProvider();
this.router = NetGraphMsgHandler.constructor_new(null, logger);
System.gc();
}
- void connect_block(Block b, int height) {
+ TwoTuple<byte[], TxOut[]>[] connect_block(Block b, int height) {
byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80);
- TwoTuple<Long, org.ldk.structs.Transaction>[] txn;
+ TwoTuple<Long, byte[]>[] txn;
if (b.hasTransactions()) {
assert b.getTransactions().size() == 1;
- TwoTuple<Long, org.ldk.structs.Transaction> txp = new TwoTuple<>((long) 1, new org.ldk.structs.Transaction(b.getTransactions().get(0).bitcoinSerialize()));
+ TwoTuple<Long, byte[]> txp = new TwoTuple<>((long) 1, b.getTransactions().get(0).bitcoinSerialize());
txn = new TwoTuple[]{txp};
} else
txn = new TwoTuple[0];
chan_manager.block_connected(header, txn, height);
synchronized (monitors) {
+ assert monitors.size() == 1;
for (ChannelMonitor mon : monitors.values()) {
- TwoTuple<byte[], TxOut[]>[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
- assert ret.length == 0;
+ return mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
}
}
+ return null;
}
Route get_route(byte[] dest_node, ChannelDetails[] our_chans) {
assert ((Event.FundingBroadcastSafe) events[0]).user_channel_id == 42;
Block b = new Block(bitcoinj_net, 2, Sha256Hash.ZERO_HASH, Sha256Hash.ZERO_HASH, 42, 0, 0, Arrays.asList(new Transaction[]{funding}));
- peer1.connect_block(b, 1);
- peer2.connect_block(b, 1);
+ assert peer1.connect_block(b, 1).length == 0;
+ assert peer2.connect_block(b, 1).length == 0;
for (int height = 2; height < 10; height++) {
b = new Block(bitcoinj_net, 2, b.getHash(), Sha256Hash.ZERO_HASH, 42, 0, 0, Arrays.asList(new Transaction[0]));
- peer1.connect_block(b, height);
- peer2.connect_block(b, height);
+ assert peer1.connect_block(b, height).length == 0;
+ assert peer2.connect_block(b, height).length == 0;
}
peer1.peer_manager.process_events();
assert peer1.broadcast_set.size() == 1;
assert peer2.broadcast_set.size() == 0;
- //b = new Block(bitcoinj_net, 2, b.getHash(), Sha256Hash.ZERO_HASH, 42, 0, 0, Arrays.asList(new Transaction[]{new Transaction(bitcoinj_net, peer1.broadcast_set.getFirst())}));
- //peer2.connect_block(b, 1);
+ Transaction tx = new Transaction(bitcoinj_net, peer1.broadcast_set.getFirst());
+ b = new Block(bitcoinj_net, 2, b.getHash(), Sha256Hash.ZERO_HASH, 42, 0, 0,
+ Arrays.asList(new Transaction[]{tx}));
+ TwoTuple<byte[], TxOut[]>[] watch_outputs = peer2.connect_block(b, 1);
+ assert watch_outputs.length == 1;
+ assert Arrays.equals(watch_outputs[0].a, tx.getTxId().getReversedBytes());
+ assert watch_outputs[0].b.length == 1;
}
bindings.SocketDescriptor_free(descriptor2);