Skip to content

Commit

Permalink
fix: storage migration on bnusd
Browse files Browse the repository at this point in the history
  • Loading branch information
Itshyphen authored Nov 13, 2024
1 parent a07bcd7 commit 2b430d1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/balanced_doller/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct BalancedDollar;

#[contractimpl]
impl BalancedDollar {
pub fn initialize(e: Env, admin: Address, config: ConfigData) {
pub fn initialize(e: Env, admin: Address, xcall: Address, xcall_manager: Address, nid: String, icon_bnusd: String, upgrade_auth: Address) {
if has_administrator(&e) {
panic_with_error!(e, ContractError::ContractAlreadyInitialized)
}
Expand Down
66 changes: 65 additions & 1 deletion contracts/balanced_doller/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,75 @@ pub struct AllowanceValue {
pub expiration_ledger: u32,
}

#[derive(Clone)]
#[contracttype]
pub struct ConfigData {
pub xcall: Address,
pub xcall_manager: Address,
pub nid: String,
pub icon_bn_usd: String,
pub upgrade_authority: Address,
}

#[derive(Clone)]
#[contracttype]
pub enum DataKey {
Allowance(AllowanceDataKey),
Balance(Address),
Admin,
Config,
XcallManager,
XCall,
Nid,
IconBnusd,
UpgradeAuthority
}

pub fn set_xcall_manager(e: &Env, value: XcallManager) {
e.storage().instance().set(&DataKey::XcallManager, &value);
}

pub fn set_xcall(e: &Env, value: Xcall) {
e.storage().instance().set(&DataKey::Xcall, &value);
}

pub fn set_nid(e: &Env, value: Nid) {
e.storage().instance().set(&DataKey::Nid, &value);
}

pub fn set_icon_bnusd(e: &Env, value: IconBnusd) {
e.storage().instance().set(&DataKey::IconBnusd, &value);
}

pub fn set_upgrade_authority(e: &Env, value: UpgradeAuthority) {
e.storage().instance().set(&DataKey::UpgradeAuthority, &value);
}


pub fn get_xcall_manager(e: &Env) -> XcallManager {
let key = DataKey::XcallManager;
e.storage().instance().get(&key).unwrap_optimized()
}

pub fn get_xcall(e: &Env) -> Xcall {
let key = DataKey::Xcall;
e.storage().instance().get(&key).unwrap_optimized()
}

pub fn get_nid(e: &Env) -> Nid {
let key = DataKey::Nid;
e.storage().instance().get(&key).unwrap_optimized()
}

pub fn get_icon_bnusd(e: &Env) -> IconBnusd {
let key = DataKey::IconBnusd;
e.storage().instance().get(&key).unwrap_optimized()
}

pub fn get_upgrade_authority(e: &Env) -> UpgradeAuthority {
let key = DataKey::UpgradeAuthority;
e.storage().instance().get(&key).unwrap_optimized()
}




0 comments on commit 2b430d1

Please sign in to comment.