Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow QueryParameter::UnlockableByAddress for more routes #1397

Conversation

Thoralf-M
Copy link
Member

@Thoralf-M Thoralf-M commented Oct 5, 2023

Description of change

Added QueryParameter::UnlockableByAddress to allowed query paramaters for Client::{alias_output_ids(), basic_output_ids(), nft_output_ids()} since this is now allowed by the indexer iotaledger/tips@0dd6217

Also changed the syncing in the wallet to make use of it

Links to any relevant issues

Fixes #1269

Type of change

  • Enhancement (a non-breaking change which adds functionality)

How the change has been tested

Running an example with

    let output_ids_response = client
        .alias_output_ids([QueryParameter::UnlockableByAddress(address)])
        .await?;

and also synced a wallet with

SyncOptions {
            nft: NftSyncOptions {
                basic_outputs: true,
                ..Default::default()
            },
            ..Default::default()
        }

…rs for `Client::{alias_output_ids(), basic_output_ids(), nft_output_ids()}`
sdk/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@thibault-martinez thibault-martinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there nowhere we can actually use it already?

Thoralf-M and others added 2 commits October 5, 2023 11:28
@Thoralf-M
Copy link
Member Author

Is there nowhere we can actually use it already?

There is, should I include it in this PR? It's for example merging all this

{
let mut output_ids = Vec::new();
output_ids.extend(
self.client()
.nft_output_ids([QueryParameter::Address(bech32_address)])
.await?
.items,
);
output_ids.extend(
self.client()
.nft_output_ids([QueryParameter::StorageDepositReturnAddress(bech32_address)])
.await?
.items,
);
output_ids.extend(
self.client()
.nft_output_ids([QueryParameter::ExpirationReturnAddress(bech32_address)])
.await?
.items,
);
Ok(output_ids)
}
#[cfg(not(target_family = "wasm"))]
{
let client = self.client();
let tasks = [
async move {
let client = client.clone();
tokio::spawn(async move {
// Get nft outputs where the address is in the address unlock condition
client
.nft_output_ids([QueryParameter::Address(bech32_address)])
.await
.map_err(From::from)
})
.await
}
.boxed(),
async move {
let client = client.clone();
tokio::spawn(async move {
// Get outputs where the address is in the storage deposit return unlock condition
client
.nft_output_ids([QueryParameter::StorageDepositReturnAddress(bech32_address)])
.await
.map_err(From::from)
})
.await
}
.boxed(),
async move {
let client = client.clone();
tokio::spawn(async move {
// Get outputs where the address is in the expiration unlock condition
client
.nft_output_ids([QueryParameter::ExpirationReturnAddress(bech32_address)])
.await
.map_err(From::from)
})
.await
}
.boxed(),
];
// Get all results
let mut output_ids = HashSet::new();
let results: Vec<crate::wallet::Result<OutputIdsResponse>> = futures::future::try_join_all(tasks).await?;
for res in results {
let found_output_ids = res?;
output_ids.extend(found_output_ids.items);
}

@thibault-martinez
Copy link
Member

Is there nowhere we can actually use it already?

There is, should I include it in this PR? It's for example merging all this

{
let mut output_ids = Vec::new();
output_ids.extend(
self.client()
.nft_output_ids([QueryParameter::Address(bech32_address)])
.await?
.items,
);
output_ids.extend(
self.client()
.nft_output_ids([QueryParameter::StorageDepositReturnAddress(bech32_address)])
.await?
.items,
);
output_ids.extend(
self.client()
.nft_output_ids([QueryParameter::ExpirationReturnAddress(bech32_address)])
.await?
.items,
);
Ok(output_ids)
}
#[cfg(not(target_family = "wasm"))]
{
let client = self.client();
let tasks = [
async move {
let client = client.clone();
tokio::spawn(async move {
// Get nft outputs where the address is in the address unlock condition
client
.nft_output_ids([QueryParameter::Address(bech32_address)])
.await
.map_err(From::from)
})
.await
}
.boxed(),
async move {
let client = client.clone();
tokio::spawn(async move {
// Get outputs where the address is in the storage deposit return unlock condition
client
.nft_output_ids([QueryParameter::StorageDepositReturnAddress(bech32_address)])
.await
.map_err(From::from)
})
.await
}
.boxed(),
async move {
let client = client.clone();
tokio::spawn(async move {
// Get outputs where the address is in the expiration unlock condition
client
.nft_output_ids([QueryParameter::ExpirationReturnAddress(bech32_address)])
.await
.map_err(From::from)
})
.await
}
.boxed(),
];
// Get all results
let mut output_ids = HashSet::new();
let results: Vec<crate::wallet::Result<OutputIdsResponse>> = futures::future::try_join_all(tasks).await?;
for res in results {
let found_output_ids = res?;
output_ids.extend(found_output_ids.items);
}

As you want, either in this PR or open an issue for later

@Thoralf-M Thoralf-M marked this pull request as draft October 5, 2023 09:44
@Thoralf-M Thoralf-M marked this pull request as ready for review October 5, 2023 10:12
Copy link
Contributor

@kwek20 kwek20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely code cleanup 👌

Copy link

@DaughterOfMars DaughterOfMars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

Copy link
Member

@thibault-martinez thibault-martinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice

@thibault-martinez thibault-martinez merged commit 16bc460 into iotaledger:develop Oct 5, 2023
@Thoralf-M Thoralf-M deleted the unlockableByAddress-queryparmeter branch October 5, 2023 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unlockableByAddress QueryParameter to alias/basic/nft endpoints
4 participants