pub fn refresh_outputs(config: &WalletConfig, keychain: &Keychain) -> Result<(), Error> {
	debug!(LOGGER, "Refreshing wallet outputs");
	let mut wallet_outputs: HashMap<pedersen::Commitment, Identifier> = HashMap::new();
	let mut commits: Vec<pedersen::Commitment> = vec![];

	// build a local map of wallet outputs by commits
	// and a list of outputs we want to query the node for
	let _ = WalletData::read_wallet(&config.data_file_dir, |wallet_data| {
		for out in wallet_data
			.outputs
			.values()
			.filter(|out| out.root_key_id == keychain.root_key_id())
			.filter(|out| out.status != OutputStatus::Spent)
		{
			let commit = keychain.commit_with_key_index(out.value, out.n_child).unwrap();
			commits.push(commit);
			wallet_outputs.insert(commit, out.key_id.clone());
		}
	});

	// build the necessary query params -
 // ?id=xxx&id=yyy&id=zzz
	let query_params: Vec<String> = commits
		.iter()
		.map(|commit| {
			let id = util::to_hex(commit.as_ref().to_vec());
			format!("id={}", id)
		})
		.collect();
	let query_string = query_params.join("&");

	let url = format!(
		"{}/v1/chain/utxos/byids?{}",
		config.check_node_api_http_addr,
		query_string,
	);

	// build a map of api outputs by commit so we can look them up efficiently
	let mut api_outputs: HashMap<pedersen::Commitment, api::Output> = HashMap::new();
	match api::client::get::<Vec<api::Output>>(url.as_str()) {
		Ok(outputs) => for out in outputs {
			api_outputs.insert(out.commit, out);
		},
		Err(e) => {
			// if we got anything other than 200 back from server, don't attempt to refresh the wallet
			// data after
			return Err(Error::Node(e));
		}
	};

	// now for each commit, find the output in the wallet and
 // the corresponding api output (if it exists)
 // and refresh it in-place in the wallet.
 // Note: minimizing the time we spend holding the wallet lock.
	WalletData::with_wallet(&config.data_file_dir, |wallet_data| for commit in commits {
		let id = wallet_outputs.get(&commit).unwrap();
		if let Entry::Occupied(mut output) = wallet_data.outputs.entry(id.to_hex()) {
			match api_outputs.get(&commit) {
				Some(api_output) => refresh_output(&mut output.get_mut(), api_output),
				None => mark_spent_output(&mut output.get_mut()),
			};
		}
	})
}
/// Builds a single api query to retrieve the latest output data from the node.
/// So we can refresh the local wallet outputs.
Builds a single api query to retrieve the latest output data from the node.
So we can refresh the local wallet outputs.
Builds a single api query to retrieve the latest output data from the node . So we can refresh the local wallet outputs .
pub fn refresh_outputs(config: &WalletConfig, keychain: &Keychain) -> Result<(), Error> {
	debug!(LOGGER, "Refreshing wallet outputs");
	let mut wallet_outputs: HashMap<pedersen::Commitment, Identifier> = HashMap::new();
	let mut commits: Vec<pedersen::Commitment> = vec![];
	// build a local map of wallet outputs by commits
	// and a list of outputs we want to query the node for
	let _ = WalletData::read_wallet(&config.data_file_dir, |wallet_data| {
		for out in wallet_data
			.outputs
			.values()
			.filter(|out| out.root_key_id == keychain.root_key_id())
			.filter(|out| out.status != OutputStatus::Spent)
		{
			let commit = keychain.commit_with_key_index(out.value, out.n_child).unwrap();
			commits.push(commit);
			wallet_outputs.insert(commit, out.key_id.clone());
		}
	});
	// build the necessary query params -
 // ?id=xxx&id=yyy&id=zzz
	let query_params: Vec<String> = commits
		.iter()
		.map(|commit| {
			let id = util::to_hex(commit.as_ref().to_vec());
			format!("id={}", id)
		})
		.collect();
	let query_string = query_params.join("&");
	let url = format!(
		"{}/v1/chain/utxos/byids?{}",
		config.check_node_api_http_addr,
		query_string,
	);
	// build a map of api outputs by commit so we can look them up efficiently
	let mut api_outputs: HashMap<pedersen::Commitment, api::Output> = HashMap::new();
	match api::client::get::<Vec<api::Output>>(url.as_str()) {
		Ok(outputs) => for out in outputs {
			api_outputs.insert(out.commit, out);
		},
		Err(e) => {
			// if we got anything other than 200 back from server, don't attempt to refresh the wallet
			// data after
			return Err(Error::Node(e));
		}
	};
	// now for each commit, find the output in the wallet and
 // the corresponding api output (if it exists)
 // and refresh it in-place in the wallet.
 // Note: minimizing the time we spend holding the wallet lock.
	WalletData::with_wallet(&config.data_file_dir, |wallet_data| for commit in commits {
		let id = wallet_outputs.get(&commit).unwrap();
		if let Entry::Occupied(mut output) = wallet_data.outputs.entry(id.to_hex()) {
			match api_outputs.get(&commit) {
				Some(api_output) => refresh_output(&mut output.get_mut(), api_output),
				None => mark_spent_output(&mut output.get_mut()),
			};
		}
	})
}
pub fn refresh_outputs ( config : & WalletConfig , keychain : & Keychain ) -> Result < ( ) , Error > { debug ! ( LOGGER " " ) ; let mut wallet_outputs : HashMap < pedersen :: Commitment , Identifier > = HashMap :: new ( ) ; let mut commits : Vec < pedersen :: Commitment > = vec ! [ ] ; // build a local map of wallet outputs by commits // and a list of outputs we want to query the node for let _ = WalletData :: read_wallet ( & config . data_file_dir , | wallet_data | { for out in wallet_data . outputs . values ( ) . filter ( | out | out . root_key_id == keychain . root_key_id ( ) ) . filter ( | out | out . status != OutputStatus :: Spent ) { let commit = keychain . commit_with_key_index ( out . value , out . n_child ) . unwrap ( ) ; commits . push ( commit ) ; wallet_outputs . insert ( commit , out . key_id . clone ( ) ) ; } } ) ; // build the necessary query params - // ?id=xxx&id=yyy&id=zzz let query_params : Vec < String > = commits . iter ( ) . map ( | commit | { let id = util :: to_hex ( commit . as_ref ( ) . to_vec ( ) ) ; format ! ( " " id ) } ) . collect ( ) ; let query_string = query_params . join ( " " ) ; let url = format ! ( " " config check_node_api_http_addr query_string ) ; // build a map of api outputs by commit so we can look them up efficiently let mut api_outputs : HashMap < pedersen :: Commitment , api :: Output > = HashMap :: new ( ) ; match api :: client :: get :: < Vec < api :: Output > > ( url . as_str ( ) ) { Ok ( outputs ) => for out in outputs { api_outputs . insert ( out . commit , out ) ; } , Err ( e ) => { // if we got anything other than 200 back from server, don't attempt to refresh the wallet // data after return Err ( Error :: Node ( e ) ) ; } } ; // now for each commit, find the output in the wallet and // the corresponding api output (if it exists) // and refresh it in-place in the wallet. // Note: minimizing the time we spend holding the wallet lock. WalletData :: with_wallet ( & config . data_file_dir , | wallet_data | for commit in commits { let id = wallet_outputs . get ( & commit ) . unwrap ( ) ; if let Entry :: Occupied ( mut output ) = wallet_data . outputs . entry ( id . to_hex ( ) ) { match api_outputs . get ( & commit ) { Some ( api_output ) => refresh_output ( & mut output . get_mut ( ) , api_output ) , None => mark_spent_output ( & mut output . get_mut ( ) ) , } ; } } ) }
Builds a single api query to retrieve the latest output data from the node.
Builds a single api query to retrieve the latest output data from the node .
config
&WalletConfig
keychain
&Keychain