cargo_tangle/command/service/
accept.rs1use crate::wait_for_in_block_success;
2use blueprint_chain_setup::tangle::transactions::get_security_commitment;
3use blueprint_clients::tangle::client::OnlineClient;
4use blueprint_crypto::sp_core::SpSr25519;
5use blueprint_crypto::tangle_pair_signer::TanglePairSigner;
6use blueprint_keystore::backends::Backend;
7use blueprint_keystore::{Keystore, KeystoreConfig};
8use color_eyre::Result;
9use dialoguer::console::style;
10use tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_primitives::services::types::Asset;
11
12pub async fn accept_request(
36 ws_rpc_url: impl AsRef<str>,
37 _min_exposure_percent: u8,
38 _max_exposure_percent: u8,
39 restaking_percent: u8,
40 keystore_uri: String,
41 request_id: u64,
43) -> Result<()> {
44 let client = OnlineClient::from_url(ws_rpc_url.as_ref()).await?;
45
46 let config = KeystoreConfig::new().fs_root(keystore_uri.clone());
47 let keystore = Keystore::new(config).expect("Failed to create keystore");
48 let public = keystore.first_local::<SpSr25519>().unwrap();
49 let pair = keystore.get_secret::<SpSr25519>(&public).unwrap();
50 let signer = TanglePairSigner::new(pair.0);
51
52 let native_security_commitments =
53 vec![get_security_commitment(Asset::Custom(0), restaking_percent)];
54
55 println!(
56 "{}",
57 style(format!("Preparing to accept request ID: {}", request_id)).cyan()
58 );
59 let call = tangle_subxt::tangle_testnet_runtime::api::tx()
60 .services()
61 .approve(request_id, native_security_commitments);
62
63 println!(
64 "{}",
65 style(format!(
66 "Submitting Service Approval for request ID: {}",
67 request_id
68 ))
69 .cyan()
70 );
71 let res = client
72 .tx()
73 .sign_and_submit_then_watch_default(&call, &signer)
74 .await?;
75 wait_for_in_block_success(res).await;
76
77 println!(
78 "{}",
79 style(format!(
80 "Service Approval for request ID: {} submitted successfully",
81 request_id
82 ))
83 .green()
84 );
85 Ok(())
86}