sui_rpc_loadgen/payload/
get_object.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use anyhow::Result;
5use futures::future::join_all;
6use sui_json_rpc_types::{SuiObjectDataOptions, SuiObjectResponse};
7use sui_sdk::SuiClient;
8use sui_types::base_types::ObjectID;
9
10use crate::payload::{GetObject, ProcessPayload, RpcCommandProcessor, SignerInfo};
11use async_trait::async_trait;
12
13use super::validation::chunk_entities;
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: &SuiClient,
43    object_id: ObjectID,
44) -> Result<SuiObjectResponse> {
45    let result = client
46        .read_api()
47        .get_object_with_options(object_id, SuiObjectDataOptions::full_content())
48        .await
49        .unwrap();
50    Ok(result)
51}