Skip to content

Commit

Permalink
Fix resolver docs, improve resolver URL argument handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed May 5, 2024
1 parent b6b6c5a commit aaf3a88
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions rpc/wrpc/client/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ impl Default for Resolver {

impl Resolver {
pub fn new(urls: Vec<Arc<String>>) -> Self {
if urls.is_empty() {
panic!("Resolver: Empty URL list supplied to the constructor.");
}

Self { inner: Arc::new(Inner::new(urls)) }
}

Expand Down
16 changes: 9 additions & 7 deletions rpc/wrpc/wasm/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extern "C" {
///
/// // specifying custom resolver URLs
/// let rpc = RpcClient({
/// resolver: new Resolver(["<resolver-url>",...]),
/// resolver: new Resolver({urls: ["<resolver-url>",...]}),
/// networkId : "mainnet"
/// });
/// ```
Expand Down Expand Up @@ -163,12 +163,14 @@ impl Resolver {
impl TryFrom<IResolverConfig> for NativeResolver {
type Error = Error;
fn try_from(config: IResolverConfig) -> Result<Self> {
if let Ok(urls) = config.get_vec("urls") {
let urls = urls.into_iter().map(|v| v.as_string()).collect::<Option<Vec<_>>>().ok_or(Error::custom("Invalid URL"))?;
Ok(NativeResolver::new(urls.into_iter().map(Arc::new).collect()))
} else {
Ok(NativeResolver::default())
}
let resolver = config
.get_vec("urls")
.map(|urls| urls.into_iter().map(|v| v.as_string()).collect::<Option<Vec<_>>>())
.or_else(|_| config.dyn_into::<Array>().map(|urls| urls.into_iter().map(|v| v.as_string()).collect::<Option<Vec<_>>>()))
.map_err(|_| Error::custom("Invalid or missing resolver URL"))?
.map(|urls| NativeResolver::new(urls.into_iter().map(Arc::new).collect()));

Ok(resolver.unwrap_or_default())
}
}

Expand Down
4 changes: 4 additions & 0 deletions wallet/core/src/utxo/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ impl UtxoProcessor {
self.sync_proc().is_synced()
}

pub fn is_running(&self) -> bool {
self.inner.task_is_running.load(Ordering::SeqCst)
}

pub async fn init_state_from_server(&self) -> Result<bool> {
let GetServerInfoResponse {
server_version,
Expand Down
9 changes: 9 additions & 0 deletions wallet/core/src/wasm/utxo/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ impl UtxoContext {
pub fn context(&self) -> MutexGuard<native::context::Context> {
self.inner.context()
}

pub fn processor(&self) -> &native::UtxoProcessor {
self.inner.processor()
}
}

#[wasm_bindgen]
Expand Down Expand Up @@ -143,6 +147,11 @@ impl UtxoContext {
self.inner().clear().await
}

pub fn active(&self) -> bool {
let processor = self.inner().processor();
processor.try_rpc_ctl().map(|ctl| ctl.is_connected()).unwrap_or(false) && processor.is_connected() && processor.is_running()
}

// Returns all mature UTXO entries that are currently managed by the UtxoContext and are available for spending.
// This function is for informational purposes only.
// pub fn mature(&self) -> Result<IUtxoEntryReferenceArray> {
Expand Down

0 comments on commit aaf3a88

Please sign in to comment.