Skip to content

Commit

Permalink
Split query parameters into multiple structs (#1428)
Browse files Browse the repository at this point in the history
* Split query parameters into multiple enums

* Fix wasm

* Query parameter structs

* Update test and examples

* wasm

* Fix imports

* Default impl for to_query_string()

* Fix wasm

* QueryParameterBuilder or revert this commit?

* Shorter path

* Add Builder to all QueryParameter types, remove with_ prefix, make tests compile

* Setter instead of builder

* Fix only_address_unlock_condition()

* Add and use new() method for default

* ORDER

* Remove s

* Fix example, don't request outputs where the address is in the SDRUC anymore

* Address review comments

* Address review comments

* Nits

* Indexer v2

* Clippy nits

* nit

---------

Co-authored-by: DaughterOfMars <[email protected]>
Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
3 people committed Oct 26, 2023
1 parent 04e9ea8 commit 50f686c
Show file tree
Hide file tree
Showing 26 changed files with 408 additions and 424 deletions.
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ use derivative::Derivative;
#[cfg(feature = "mqtt")]
use iota_sdk::client::mqtt::Topic;
use iota_sdk::{
client::{node_api::indexer::query_parameters::QueryParameter, node_manager::node::NodeAuth},
client::{
node_api::indexer::query_parameters::{
AccountOutputQueryParameters, BasicOutputQueryParameters, FoundryOutputQueryParameters,
NftOutputQueryParameters, OutputQueryParameters,
},
node_manager::node::NodeAuth,
},
types::block::{
address::{Bech32Address, Hrp},
output::{
Expand Down Expand Up @@ -209,19 +215,19 @@ pub enum ClientMethod {
#[serde(rename_all = "camelCase")]
OutputIds {
/// Query parameters for output requests
query_parameters: Vec<QueryParameter>,
query_parameters: OutputQueryParameters,
},
/// Fetch basic output IDs
#[serde(rename_all = "camelCase")]
BasicOutputIds {
/// Query parameters for output requests
query_parameters: Vec<QueryParameter>,
query_parameters: BasicOutputQueryParameters,
},
/// Fetch account output IDs
#[serde(rename_all = "camelCase")]
AccountOutputIds {
/// Query parameters for output requests
query_parameters: Vec<QueryParameter>,
query_parameters: AccountOutputQueryParameters,
},
/// Fetch account output ID
#[serde(rename_all = "camelCase")]
Expand All @@ -233,7 +239,7 @@ pub enum ClientMethod {
#[serde(rename_all = "camelCase")]
NftOutputIds {
/// Query parameters for output requests
query_parameters: Vec<QueryParameter>,
query_parameters: NftOutputQueryParameters,
},
/// Fetch NFT output ID
#[serde(rename_all = "camelCase")]
Expand All @@ -245,7 +251,7 @@ pub enum ClientMethod {
#[serde(rename_all = "camelCase")]
FoundryOutputIds {
/// Query parameters for output requests
query_parameters: Vec<QueryParameter>,
query_parameters: FoundryOutputQueryParameters,
},
/// Fetch foundry Output ID
#[serde(rename_all = "camelCase")]
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/client/16-custom-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function run() {

// Call our "custom" indexer plugin
const outputId = await client.callPluginRoute(
'api/indexer/v1/',
'api/indexer/v2/',
'GET',
route,
undefined,
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ export class Client {
/**
* Extension method which provides request methods for plugins.
*
* @param basePluginPath The base path for the plugin eg indexer/v1/ .
* @param basePluginPath The base path for the plugin eg indexer/v2/ .
* @param method The http method.
* @param endpoint The path for the plugin request.
* @param queryParams Additional query params for the request.
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/client/custom_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@

# Call our "custom" indexer plugin
output_id = client.call_plugin_route(
"api/indexer/v1/", "GET", route, None, None)
"api/indexer/v2/", "GET", route, None, None)
print(json.dumps(output_id, indent=4))
9 changes: 8 additions & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ derive_more = { version = "0.99.17", default-features = false, features = [
"add",
"add_assign",
] }
derive_setters = { version = "0.1.6", default-features = false }
getset = { version = "0.1.2", default-features = false }
hashbrown = { version = "0.14.1", default-features = false, features = [
"ahash",
Expand Down Expand Up @@ -130,6 +131,7 @@ pretty_assertions = { version = "1.4.0", default-features = false, features = [
dotenvy = { version = "0.15.7", default-features = false }
fern-logger = { version = "0.5.0", default-features = false }
num_cpus = { version = "1.16.0", default-features = false }
once_cell = { version = "1.18.0", default-features = false }
tokio = { version = "1.33.0", default-features = false, features = [
"macros",
"rt",
Expand Down Expand Up @@ -563,6 +565,11 @@ name = "client_logger"
path = "examples/client/logger.rs"
required-features = ["client"]

[[example]]
name = "quorum"
path = "examples/client/quorum.rs"
required-features = ["client"]

[[example]]
name = "stronghold"
path = "examples/client/stronghold.rs"
Expand Down Expand Up @@ -658,7 +665,7 @@ required-features = ["wallet", "participation"]
[[example]]
name = "logger"
path = "examples/wallet/logger.rs"
required-features = ["wallet"]
required-features = ["wallet", "storage"]

[[example]]
name = "recover_accounts"
Expand Down
13 changes: 5 additions & 8 deletions sdk/examples/client/02_address_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

use iota_sdk::{
client::{
api::GetAddressesOptions, node_api::indexer::query_parameters::QueryParameter, secret::SecretManager, Client,
Result,
api::GetAddressesOptions, node_api::indexer::query_parameters::BasicOutputQueryParameters,
secret::SecretManager, Client, Result,
},
types::block::output::NativeTokensBuilder,
};
Expand Down Expand Up @@ -43,12 +43,9 @@ async fn main() -> Result<()> {

// Get output ids of outputs that can be controlled by this address without further unlock constraints
let output_ids_response = client
.basic_output_ids([
QueryParameter::Address(first_address.clone()),
QueryParameter::HasExpiration(false),
QueryParameter::HasTimelock(false),
QueryParameter::HasStorageDepositReturn(false),
])
.basic_output_ids(BasicOutputQueryParameters::only_address_unlock_condition(
first_address.clone(),
))
.await?;

// Get the outputs by their id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! ```

use iota_sdk::{
client::{node_api::indexer::query_parameters::QueryParameter, Client, Result},
client::{node_api::indexer::query_parameters::AccountOutputQueryParameters, Client, Result},
types::block::address::Bech32Address,
};

Expand Down Expand Up @@ -41,10 +41,7 @@ async fn main() -> Result<()> {

// Get output IDs of account outputs that can be controlled by this address.
let output_ids_response = client
.account_output_ids([
QueryParameter::Governor(address.clone()),
QueryParameter::StateController(address),
])
.account_output_ids(AccountOutputQueryParameters::new().unlockable_by_address(address))
.await?;

println!("Account output IDs: {output_ids_response:#?}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! ```

use iota_sdk::{
client::{node_api::indexer::query_parameters::QueryParameter, Client, Result},
client::{node_api::indexer::query_parameters::FoundryOutputQueryParameters, Client, Result},
types::block::address::Bech32Address,
};

Expand Down Expand Up @@ -41,7 +41,7 @@ async fn main() -> Result<()> {

// Get output IDs of foundry outputs that can be controlled by this address.
let output_ids_response = client
.foundry_output_ids([QueryParameter::AccountAddress(address)])
.foundry_output_ids(FoundryOutputQueryParameters::new().account_address(address))
.await?;

println!("Foundry output IDs: {output_ids_response:#?}");
Expand Down
9 changes: 2 additions & 7 deletions sdk/examples/client/node_api_indexer/06_get_nft_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! ```

use iota_sdk::{
client::{node_api::indexer::query_parameters::QueryParameter, Client, Result},
client::{node_api::indexer::query_parameters::NftOutputQueryParameters, Client, Result},
types::block::address::Bech32Address,
};

Expand Down Expand Up @@ -41,12 +41,7 @@ async fn main() -> Result<()> {

// Get output IDs of NFT outputs that can be controlled by this address without further unlock constraints.
let output_ids_response = client
.nft_output_ids([
QueryParameter::Address(address),
QueryParameter::HasExpiration(false),
QueryParameter::HasTimelock(false),
QueryParameter::HasStorageDepositReturn(false),
])
.nft_output_ids(NftOutputQueryParameters::only_address_unlock_condition(address))
.await?;

println!("NFT output IDs {output_ids_response:#?}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! cargo run --release --example node_api_indexer_get_random_basic_outputs [NODE_URL]
//! ```

use iota_sdk::client::{node_api::indexer::query_parameters::QueryParameter, Client, Result};
use iota_sdk::client::{node_api::indexer::query_parameters::BasicOutputQueryParameters, Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -26,8 +26,10 @@ async fn main() -> Result<()> {
// Create a node client.
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Get a single page with random output IDs by providing only `QueryParameter::Cursor(_)`.
let output_ids_response = client.basic_output_ids([QueryParameter::Cursor(String::new())]).await?;
// Get a single page with random output IDs by providing only an empty string as cursor.
let output_ids_response = client
.basic_output_ids(BasicOutputQueryParameters::new().cursor(String::new()))
.await?;

println!("Basic output IDs from first page {output_ids_response:#?}");

Expand Down
13 changes: 5 additions & 8 deletions sdk/examples/client/quorum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
//! ```

use iota_sdk::client::{
api::GetAddressesOptions, node_api::indexer::query_parameters::QueryParameter, secret::SecretManager, Client,
Result,
api::GetAddressesOptions, node_api::indexer::query_parameters::BasicOutputQueryParameters, secret::SecretManager,
Client, Result,
};

#[tokio::main]
Expand Down Expand Up @@ -52,12 +52,9 @@ async fn main() -> Result<()> {

// Get output ids of outputs that can be controlled by this address without further unlock constraints
let output_ids_response = client
.basic_output_ids([
QueryParameter::Address(addresses[0]),
QueryParameter::HasExpiration(false),
QueryParameter::HasTimelock(false),
QueryParameter::HasStorageDepositReturn(false),
])
.basic_output_ids(BasicOutputQueryParameters::only_address_unlock_condition(
addresses[0].clone(),
))
.await?;
println!("Address outputs: {output_ids_response:?}");

Expand Down
7 changes: 1 addition & 6 deletions sdk/examples/client/send_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ async fn main() -> Result<()> {

// Get output ids of outputs that can be controlled by this address without further unlock constraints
let output_ids_response = client
.basic_output_ids([
QueryParameter::Address(address),
QueryParameter::HasExpiration(false),
QueryParameter::HasTimelock(false),
QueryParameter::HasStorageDepositReturn(false),
])
.basic_output_ids(BasicOutputQueryParameters::only_address_unlock_condition(address))
.await?;

// Get the outputs by their id
Expand Down
6 changes: 4 additions & 2 deletions sdk/examples/how_tos/account_wallet/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! `cargo run --release --all-features --example account_wallet_transaction`

use iota_sdk::{
client::node_api::indexer::query_parameters::QueryParameter,
client::node_api::indexer::query_parameters::BasicOutputQueryParameters,
types::block::address::{AccountAddress, ToBech32Ext},
wallet::{
account::{AliasSyncOptions, SyncOptions, TransactionOptions},
Expand Down Expand Up @@ -54,7 +54,9 @@ async fn main() -> Result<()> {
// Find first output unlockable by the account address
let input = *account
.client()
.basic_output_ids([QueryParameter::Address(account_address)])
.basic_output_ids(BasicOutputQueryParameters::only_address_unlock_condition(
account_address,
))
.await?
.items
.first()
Expand Down
9 changes: 2 additions & 7 deletions sdk/examples/how_tos/client/get_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! ```

use iota_sdk::{
client::{node_api::indexer::query_parameters::QueryParameter, Client, Result},
client::{node_api::indexer::query_parameters::BasicOutputQueryParameters, Client, Result},
types::block::address::Bech32Address,
};

Expand All @@ -40,12 +40,7 @@ async fn main() -> Result<()> {

// Get output IDs of basic outputs that can be controlled by this address without further unlock constraints.
let output_ids_response = client
.basic_output_ids([
QueryParameter::Address(address),
QueryParameter::HasExpiration(false),
QueryParameter::HasTimelock(false),
QueryParameter::HasStorageDepositReturn(false),
])
.basic_output_ids(BasicOutputQueryParameters::only_address_unlock_condition(address))
.await?;

println!("First output of query:");
Expand Down
Loading

0 comments on commit 50f686c

Please sign in to comment.