Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 29, 2024
1 parent e09336e commit ed481c3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 37 additions & 15 deletions ahm-controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@ pub enum Role {
}

#[derive(Encode, Decode, MaxEncodedLen, TypeInfo)]
pub enum Phase {
pub enum Phases {
MigrateBalancesEds { next_account: Option<BoundedVec<u8, ConstU32<128>>> },

AllDone,
}

/// WARNING EXTREMLY IMPORTANT THAT THESE INDICES ARE CORRECT
#[derive(Encode, Decode)]
enum AssetHubPalletConfig<T: Config> {
#[codec(index = 244)]
AhmController(AhmCall),
#[codec(index = 5)]
Indices(pallet_indices::Call<T>),
#[codec(index = 10)]
Balances(pallet_balances::Call<T>),
#[codec(index = 244)]
AhmController(AhmCall),
}

/// Call encoding for the calls needed from the Broker pallet.
Expand Down Expand Up @@ -100,7 +103,7 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::storage]
pub type Phase<T: Config> = StorageValue<_, super::Phase>;
pub type Phase<T: Config> = StorageValue<_, super::Phases>;

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
Expand Down Expand Up @@ -146,19 +149,19 @@ pub mod pallet {
fn relay_on_init() {
// Phase init
let phase = match Phase::<T>::get() {
None => Phase::MigrateBalancesEds { next_account: Vec::new() },
None => Phases::MigrateBalancesEds { next_account: None },
Some(phase) => phase,
};

// Phase handling and transistion
let phase = match phase {
Phase::MigrateBalancesEds { mut next_account } => {
Self::migrate_eds(&mut next_account, 100)?;
Phases::MigrateBalancesEds { mut next_account } => {
Self::migrate_eds(&mut next_account);

if next_account.is_some() {
Phase::MigrateBalancesEds { next_account }
Phases::MigrateBalancesEds { next_account }
} else {
Phase::AllDone
Phases::AllDone
}
},
other => other,
Expand All @@ -175,13 +178,32 @@ pub mod pallet {
}*/
}

fn migrate_eds(next_acc: &mut Option<Vec<u8>>) -> Result<(), ()> {
frame_support::storage::transactional::with_transaction_opaque_err::<(), (), _>(|| {
let Some((call, weight)) = pallet_balances::Pallet::<T>::migrate_ed(&mut next_acc, 100) else {
return TransactionOutcome::Commit(Ok(()));
// Just to make the BoundedVec compiler stuff work...
fn migrate_eds(next_acc: &mut Option<BoundedVec<u8, ConstU32<128>>>) {
let Ok(new) = Self::do_migrate_eds(next_acc.clone().map(|v| v.into_inner())) else {
// TODO what do?
return;
};
let Some(new) = new else {
*next_acc = None;
return;
};

let Ok(new_bounded) = BoundedVec::try_from(new) else {
defensive!("Very bad: could not store next cursor");
// TODO yikes
return;
};
*next_acc = Some(new_bounded);
}

fn do_migrate_eds(next_acc: Option<Vec<u8>>) -> Result<Option<Vec<u8>>, ()> {
frame_support::storage::transactional::with_transaction_opaque_err::<Option<Vec<u8>>, (), _>(|| {
let Some((next_key, call, weight)) = pallet_balances::Pallet::<T>::migrate_ed(next_acc, 100) else {
return TransactionOutcome::Commit(Ok(None));
};

let ah_call: xcm::DoubleEncoded<()> = AssetHubPalletConfig::<T>::Indices(
let ah_call: xcm::DoubleEncoded<()> = AssetHubPalletConfig::<T>::Balances(
call,
).encode().into();

Expand All @@ -203,7 +225,7 @@ pub mod pallet {
) {
Ok(_) => {
Self::deposit_event(Event::SentDownward);
TransactionOutcome::Commit(Ok(()))
TransactionOutcome::Commit(Ok(next_key))
},
Err(_) => {
Self::deposit_event(Event::ErrorSendingDownward);
Expand Down

0 comments on commit ed481c3

Please sign in to comment.