sui_rpc_loadgen/payload/
pay_sui.rs1use crate::payload::rpc_command_processor::DEFAULT_GAS_BUDGET;
5use crate::payload::{PaySui, ProcessPayload, RpcCommandProcessor, SignerInfo};
6use async_trait::async_trait;
7use futures::future::join_all;
8use sui_types::base_types::SuiAddress;
9use sui_types::crypto::{EncodeDecodeBase64, SuiKeyPair};
10use sui_types::quorum_driver_types::ExecuteTransactionRequestType;
11use sui_types::transaction::TransactionData;
12use tracing::debug;
13
14#[async_trait]
15impl<'a> ProcessPayload<'a, &'a PaySui> for RpcCommandProcessor {
16 async fn process(
17 &'a self,
18 _op: &'a PaySui,
19 signer_info: &Option<SignerInfo>,
20 ) -> anyhow::Result<()> {
21 let clients = self.get_clients().await?;
22 let SignerInfo {
23 encoded_keypair,
24 gas_budget,
25 gas_payment,
26 } = signer_info.clone().unwrap();
27 let recipient = SuiAddress::random_for_testing_only();
28 let amount = 1;
29 let gas_budget = gas_budget.unwrap_or(DEFAULT_GAS_BUDGET);
30 let gas_payments = gas_payment.unwrap();
31
32 let keypair =
33 SuiKeyPair::decode_base64(&encoded_keypair).expect("Decoding keypair should not fail");
34
35 debug!(
36 "Transfer Sui {} time to {recipient} with {amount} MIST with {gas_payments:?}",
37 gas_payments.len()
38 );
39
40 let sender = SuiAddress::from(&keypair.public());
41 let client = clients.first().unwrap();
44 let gas_price = client
45 .governance_api()
46 .get_reference_gas_price()
47 .await
48 .expect("Unable to fetch gas price");
49 join_all(gas_payments.iter().map(|gas| async {
50 let tx = TransactionData::new_transfer_sui(
51 recipient,
52 sender,
53 Some(amount),
54 self.get_object_ref(client, gas).await,
55 gas_budget,
56 gas_price,
57 );
58 self.sign_and_execute(
59 client,
60 &keypair,
61 tx,
62 ExecuteTransactionRequestType::WaitForEffectsCert,
63 )
64 .await
65 }))
66 .await;
67
68 Ok(())
69 }
70}