+ 8 => {
+ for payment in payments_received.drain(..) {
+ let mut payment_preimage = [0; 32];
+ payment_preimage[0] = payment[0];
+ let mut sha = Sha256::new();
+ sha.input(&payment_preimage);
+ let mut payment_hash_check = [0; 32];
+ sha.result(&mut payment_hash_check);
+ assert!(payment_hash_check == payment);
+ channelmanager.claim_funds(payment_preimage);
+ }
+ },
+ 9 => {
+ for payment in payments_received.drain(..) {
+ channelmanager.fail_htlc_backwards(&payment);
+ }
+ },
+ 10 => {
+ for funding_generation in pending_funding_generation.drain(..) {
+ let mut tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: vec![TxOut {
+ value: funding_generation.1, script_pubkey: funding_generation.2,
+ }] };
+ let funding_output = OutPoint::new(Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
+ let mut found_duplicate_txo = false;
+ for chan in channelmanager.list_channels() {
+ if chan.channel_id == funding_output.to_channel_id() {
+ found_duplicate_txo = true;
+ }
+ }
+ if !found_duplicate_txo {
+ channelmanager.funding_transaction_generated(&funding_generation.0, funding_output.clone());
+ pending_funding_signatures.insert(funding_output, tx);
+ }
+ }
+ },
+ 11 => {
+ if !pending_funding_relay.is_empty() {
+ let mut txn = Vec::with_capacity(pending_funding_relay.len());
+ let mut txn_idxs = Vec::with_capacity(pending_funding_relay.len());
+ for (idx, tx) in pending_funding_relay.iter().enumerate() {
+ txn.push(tx);
+ txn_idxs.push(idx as u32 + 1);
+ }
+
+ let mut header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+ channelmanager.block_connected(&header, 1, &txn[..], &txn_idxs[..]);
+ txn.clear();
+ txn_idxs.clear();
+ for i in 2..100 {
+ header = BlockHeader { version: 0x20000000, prev_blockhash: header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+ channelmanager.block_connected(&header, i, &txn[..], &txn_idxs[..]);
+ }
+ }
+ pending_funding_relay.clear();
+ },