iota_rpc_loadgen/payload/
get_object.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use anyhow::Result;
6use async_trait::async_trait;
7use futures::future::join_all;
8use iota_json_rpc_types::{IotaObjectDataOptions, IotaObjectResponse};
9use iota_sdk::IotaClient;
10use iota_types::base_types::ObjectID;
11
12use super::validation::chunk_entities;
13use crate::payload::{GetObject, ProcessPayload, RpcCommandProcessor, SignerInfo};
14
15#[async_trait]
16impl<'a> ProcessPayload<'a, &'a GetObject> for RpcCommandProcessor {
17    async fn process(&'a self, op: &'a GetObject, _signer_info: &Option<SignerInfo>) -> Result<()> {
18        if op.object_ids.is_empty() {
19            panic!("No object ids provided, skipping query");
20        };
21        let clients = self.get_clients().await?;
22        let chunked = chunk_entities(&op.object_ids, Some(op.chunk_size));
23
24        for chunk in chunked {
25            let mut tasks = Vec::new();
26            for object_id in chunk {
27                for client in clients.iter() {
28                    let task = async move {
29                        get_object(client, object_id).await.unwrap();
30                    };
31                    tasks.push(task);
32                }
33            }
34            join_all(tasks).await;
35        }
36        Ok(())
37    }
38}
39
40// TODO: should organize these into an api_calls.rs
41pub(crate) async fn get_object(
42    client: &IotaClient,
43    object_id: ObjectID,
44) -> Result<IotaObjectResponse> {
45    let result = client
46        .read_api()
47        .get_object_with_options(object_id, IotaObjectDataOptions::full_content())
48        .await
49        .unwrap();
50    Ok(result)
51}