use bingle_core::blockchain::algo_bingle::AlgoBingle;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AccountReadiness {
Registered,
NeedsMigration {
ancestor: u64,
},
Unregistered,
}
pub fn classify_account(holds_handle: bool, migratable_ancestor: Option<u64>) -> AccountReadiness {
if holds_handle {
AccountReadiness::Registered
} else if let Some(ancestor) = migratable_ancestor {
AccountReadiness::NeedsMigration { ancestor }
} else {
AccountReadiness::Unregistered
}
}
pub fn readiness_on_chain(
bingle: &AlgoBingle,
app_id: u64,
account: &str,
) -> Result<AccountReadiness, String> {
if bingle
.holds_handle(app_id, account)
.map_err(|e| e.to_string())?
{
return Ok(AccountReadiness::Registered);
}
let ancestor = bingle
.find_migratable_ancestor(app_id, account)
.map_err(|e| e.to_string())?;
Ok(classify_account(false, ancestor))
}
pub fn migration_needed_message(account: &str, app_id: u64, ancestor: u64) -> String {
format!(
"account {account} is not registered on app {app_id}: it is registered on ancestor app \
{ancestor} and has not been migrated. Migrate it once with \
`bingle_cli migrate --passphrase <mnemonic> --node-file <node_file>`, or re-run this \
command with --auto-migrate."
)
}
pub fn registration_needed_message(account: &str, app_id: u64) -> String {
format!(
"account {account} is not registered on app {app_id} or any of its ancestor apps. \
Register it first with \
`bingle_cli register --handle <handle> --passphrase <mnemonic> --node-file <node_file> --price-units <n>`."
)
}