iota_rpc_loadgen/payload/
get_reference_gas_price.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::try_join_all;
8use iota_sdk::IotaClient;
9
10use crate::payload::{GetReferenceGasPrice, ProcessPayload, RpcCommandProcessor, SignerInfo};
11
12#[async_trait]
13impl<'a> ProcessPayload<'a, &'a GetReferenceGasPrice> for RpcCommandProcessor {
14    async fn process(
15        &'a self,
16        op: &'a GetReferenceGasPrice,
17        _signer_info: &Option<SignerInfo>,
18    ) -> Result<()> {
19        let clients = self.get_clients().await?;
20
21        let futures = (0..op.num_repeats).map(|_| {
22            let clients = clients.clone();
23            async move {
24                let futures = clients.iter().map(get_reference_gas_price);
25                try_join_all(futures).await
26            }
27        });
28
29        try_join_all(futures).await.unwrap();
30        Ok(())
31    }
32}
33
34async fn get_reference_gas_price(client: &IotaClient) -> Result<u64> {
35    let results = client
36        .governance_api()
37        .get_reference_gas_price()
38        .await
39        .unwrap();
40    Ok(results)
41}