+
+struct InputData {
+ data: Vec<u8>,
+ read_pos: AtomicUsize,
+}
+impl InputData {
+ fn get_slice(&self, len: usize) -> Option<&[u8]> {
+ let old_pos = self.read_pos.fetch_add(len, Ordering::AcqRel);
+ if self.data.len() < old_pos + len {
+ return None;
+ }
+ Some(&self.data[old_pos..old_pos + len])
+ }
+ fn get_slice_nonadvancing(&self, len: usize) -> Option<&[u8]> {
+ let old_pos = self.read_pos.load(Ordering::Acquire);
+ if self.data.len() < old_pos + len {
+ return None;
+ }
+ Some(&self.data[old_pos..old_pos + len])
+ }
+}
+
+struct DummyChainWatcher {
+ input: Arc<InputData>,
+}
+
+impl ChainWatchInterface for DummyChainWatcher {
+ fn install_watch_script(&self, _script_pub_key: &Script) { }
+ fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { }
+ fn watch_all_txn(&self) { }
+ fn register_listener(&self, _listener: Weak<ChainListener>) { }
+
+ fn get_chain_utxo(&self, _genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
+ match self.input.get_slice(2) {
+ Some(&[0, _]) => Err(ChainError::NotSupported),
+ Some(&[1, _]) => Err(ChainError::NotWatched),
+ Some(&[2, _]) => Err(ChainError::UnknownTx),
+ Some(&[_, x]) => Ok((Builder::new().push_int(x as i64).into_script().to_v0_p2wsh(), 0)),
+ None => Err(ChainError::UnknownTx),
+ _ => unreachable!(),
+ }
+ }
+}
+