Skip to content

Commit 56df000

Browse files
committed
proxy call
1 parent ed1dc53 commit 56df000

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

cli/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
SEED="your_mnemonic_phrase"
2-
FAUCET_ADDRESS="Address_of_your_chain"
2+
FAUCET_ADDRESS="Faucet_address_of_your_chain"
33
ROCOCO_URI="ws://127.0.0.1:9944" # or wss://rococo-rpc.polkadot.io:443
4+
SUDO_ACCOUNT="network's public sudo account"

cli/src/calls.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use subxt::{utils::AccountId32};
22
use subxt::{OnlineClient, PolkadotConfig};
3-
use crate::utils::get_signer;
3+
use crate::utils::{get_signer, get_sudo_account};
44

55
// #[subxt::subxt(runtime_metadata_path = "metadata/rococo_metadata.scale")]
66
// pub mod rococo {}
@@ -17,6 +17,7 @@ type AssignSlotsCall = rococo::runtime_types::polkadot_runtime_common::assigned_
1717
type SchedulerCall = rococo::runtime_types::pallet_scheduler::pallet::Call;
1818
type BalancesCall = rococo::runtime_types::pallet_balances::pallet::Call;
1919
type UtilityCall = rococo::runtime_types::pallet_utility::pallet::Call;
20+
type SudoCall = rococo::runtime_types::pallet_sudo::pallet::Call;
2021

2122
const BLOCKS_SCHEDULED: u32 = 1205; // 2 epochs (600*2) + 5 blocks of margin
2223
const REGISTER_DEPOSIT: u128 = 10_000;
@@ -124,13 +125,33 @@ pub fn create_scheduled_remove_lock_call(
124125
Ok(scheduled_call)
125126
}
126127

128+
//
129+
// Creates a sudo call wrapping the given call
130+
//
131+
pub fn create_sudo_call(
132+
call: Call,
133+
) -> Result<Call, Box<dyn std::error::Error>> {
134+
135+
let sudo_call = Call::Sudo(SudoCall::sudo {
136+
call: Box::new(call),
137+
});
138+
139+
Ok(sudo_call)
140+
}
141+
142+
//
127143
// Sign and send the passed call and waits for
128-
pub async fn sign_and_send_call(
144+
//
145+
pub async fn sign_and_send_proxy_call(
129146
api: OnlineClient<PolkadotConfig>,
130147
call: Call,
131148
) -> Result<(), Box<dyn std::error::Error>> {
132149

133-
let utx = rococo::tx().sudo().sudo(call);
150+
let utx = rococo::tx().proxy().proxy(
151+
subxt::utils::MultiAddress::Id(get_sudo_account()),
152+
None,
153+
call
154+
);
134155

135156
api.tx()
136157
.sign_and_submit_then_watch_default(&utx, &get_signer())

cli/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use para_onboarding::{
55
utils::{has_slot_in_rococo, is_registered, needs_perm_slot, calculate_sovereign_account, parse_validation_code},
66
calls::{Call, create_batch_all_call, create_force_transfer_call,
77
create_force_register_call, create_scheduled_assign_slots_call,
8-
create_scheduled_remove_lock_call, sign_and_send_call
8+
create_scheduled_remove_lock_call, create_sudo_call, sign_and_send_proxy_call
99
},
1010
};
1111
use std::{fs, path::PathBuf};
@@ -101,7 +101,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
101101
// Get the batched call based on the calls present in buffer
102102
let batch_call = create_batch_all_call(call_buffer).unwrap();
103103

104+
// Create a SUDO call
105+
let sudo_call = create_sudo_call(batch_call).unwrap();
106+
104107
// Sign and send batch_call to the network
105-
sign_and_send_call(rococo_api, batch_call).await
108+
sign_and_send_proxy_call(rococo_api, sudo_call).await
106109

107110
}

cli/src/utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use sp_core::{
55
};
66
use sp_runtime::MultiSigner;
77
use subxt::{tx::PairSigner, utils::AccountId32, OnlineClient, PolkadotConfig};
8+
use std::str::FromStr;
89

910
use crate::query::{maybe_leases, paras_registered};
1011

@@ -26,6 +27,11 @@ pub fn get_signer() -> PairSigner<PolkadotConfig, sp_core::sr25519::Pair> {
2627
PairSigner::new(pair)
2728
}
2829

30+
pub fn get_sudo_account() -> AccountId32 {
31+
let sudo_account = std::env::var("SUDO_ACCOUNT").expect("Error: No SEED provided");
32+
AccountId32::from_str(&sudo_account).unwrap()
33+
}
34+
2935
pub fn parse_validation_code(validation_code: String) -> Vec<u8> {
3036
// Remove "0x" from validation_code
3137
let parsed_validation_code = &validation_code[2..];

0 commit comments

Comments
 (0)