// look for our own inputs
for (i, input) in tx.input.iter().enumerate() {
+ // skip coinbase inputs
+ if input.previous_output.is_null() {
+ continue;
+ }
+
// the fact that we visit addresses in a BFS fashion starting from the external addresses
// should ensure that this query is always consistent (i.e. when we get to call this all
// the transactions at a lower depth have already been indexed, so if an outpoint is ours
sent: outgoing,
height,
timestamp: 0,
- fees: inputs_sum - outputs_sum,
+ fees: inputs_sum.saturating_sub(outputs_sum), // if the tx is a coinbase, fees would be negative
};
info!("Saving tx {}", txid);
updates.set_tx(&tx)?;
assert_eq!(wallet.get_balance().unwrap(), 0);
assert_eq!(new_details.received, 0);
}
+
+ #[test]
+ #[serial]
+ fn test_sync_receive_coinbase() {
+ let (wallet, descriptors, mut test_client) = init_single_sig();
+ let wallet_addr = wallet.get_new_address().unwrap();
+
+ wallet.sync(noop_progress(), None).unwrap();
+ assert_eq!(wallet.get_balance().unwrap(), 0);
+
+ test_client.generate(1, Some(wallet_addr));
+
+ wallet.sync(noop_progress(), None).unwrap();
+ assert!(wallet.get_balance().unwrap() > 0);
+ }
}
};
.unwrap();
if let Some(num) = meta_tx.min_confirmations {
- self.generate(num);
+ self.generate(num, None);
}
let monitor_script = Address::from_str(&meta_tx.output[0].to_address)
block.header.block_hash().to_hex()
}
- pub fn generate(&mut self, num_blocks: u64) {
- let our_addr = self.get_new_address(None, None).unwrap();
- let hashes = self.generate_to_address(num_blocks, &our_addr).unwrap();
+ pub fn generate(&mut self, num_blocks: u64, address: Option<Address>) {
+ let address = address.unwrap_or_else(|| self.get_new_address(None, None).unwrap());
+ let hashes = self.generate_to_address(num_blocks, &address).unwrap();
let best_hash = hashes.last().unwrap();
let height = self.get_block_info(best_hash).unwrap().height;
pub fn reorg(&mut self, num_blocks: u64) {
self.invalidate(num_blocks);
- self.generate(num_blocks);
+ self.generate(num_blocks, None);
}
pub fn get_node_address(&self, address_type: Option<AddressType>) -> Address {