near/upgradePhase1: fix some upgrade issues to make it easier to migrate in the future

This commit is contained in:
Josh Siegel 2022-08-30 08:07:48 -05:00 committed by jumpsiegel
parent ca7c018734
commit 1860a7fc27
2 changed files with 34 additions and 35 deletions

View File

@ -14,10 +14,7 @@ use {
BorshDeserialize, BorshDeserialize,
BorshSerialize, BorshSerialize,
}, },
collections::{ collections::LookupMap,
LookupMap,
UnorderedSet,
},
env, env,
ext_contract, ext_contract,
json_types::U128, json_types::U128,
@ -128,7 +125,8 @@ pub struct TokenData {
pub struct OldPortal { pub struct OldPortal {
booted: bool, booted: bool,
core: AccountId, core: AccountId,
dups: UnorderedSet<Vec<u8>>, gov_idx: u32,
dups: LookupMap<Vec<u8>, bool>,
owner_pk: PublicKey, owner_pk: PublicKey,
emitter_registration: LookupMap<u16, Vec<u8>>, emitter_registration: LookupMap<u16, Vec<u8>>,
last_asset: u32, last_asset: u32,
@ -589,11 +587,7 @@ impl TokenBridge {
)); ));
ext_ft_contract::ext(asset_token_account.clone()) ext_ft_contract::ext(asset_token_account.clone())
.with_static_gas(Gas(10_000_000_000_000)) .with_static_gas(Gas(10_000_000_000_000))
.update_ft( .update_ft(ft, data.to_vec(), vaa.sequence)
ft,
data.to_vec(),
vaa.sequence,
)
} else { } else {
env::log_str(&format!( env::log_str(&format!(
"token-bridge/{}#{}: vaa_asset_meta: fresh", "token-bridge/{}#{}: vaa_asset_meta: fresh",
@ -742,6 +736,7 @@ impl TokenBridge {
Promise::new(env::current_account_id()) Promise::new(env::current_account_id())
.deploy_contract(v.to_vec()) .deploy_contract(v.to_vec())
.then(Self::ext(env::current_account_id()).migrate())
.then(Self::ext(env::current_account_id()).update_contract_done( .then(Self::ext(env::current_account_id()).update_contract_done(
env::predecessor_account_id(), env::predecessor_account_id(),
env::storage_usage(), env::storage_usage(),
@ -1639,6 +1634,11 @@ impl TokenBridge {
storage_used: u64, storage_used: u64,
attached_deposit: u128, attached_deposit: u128,
) { ) {
env::log_str(&format!(
"token-bridge/{}#{}: update_contract_done",
file!(),
line!(),
));
let delta = (env::storage_usage() as i128 - storage_used as i128) let delta = (env::storage_usage() as i128 - storage_used as i128)
* env::storage_byte_cost() as i128; * env::storage_byte_cost() as i128;
let refund = attached_deposit as i128 - delta; let refund = attached_deposit as i128 - delta;
@ -1654,30 +1654,31 @@ impl TokenBridge {
} }
} }
// #[init(ignore_state)] #[init(ignore_state)]
// #[payable] pub fn migrate() -> Self {
// #[private] env::log_str(&format!("token-bridge/{}#{}: migrate", file!(), line!(),));
// pub fn migrate() -> Self {
// if env::attached_deposit() != 1 { let state: TokenBridge = env::state_read().expect("failed");
// env::panic_str("Need money"); state
// }
// let old_state: OldPortal = env::state_read().expect("failed"); // let old_state: OldPortal = env::state_read().expect("failed");
// env::log_str(&format!("token-bridge/{}#{}: migrate", file!(), line!(),));
// Self { // Self {
// booted: old_state.booted, // booted: old_state.booted,
// core: old_state.core, // core: old_state.core,
// gov_idx: 0, // gov_idx: old_state.gov_idx,
// dups: LookupMap::new(b"d".to_vec()), // dups: old_state.dups,
// owner_pk: old_state.owner_pk, // owner_pk: old_state.owner_pk,
// emitter_registration: old_state.emitter_registration, // emitter_registration: old_state.emitter_registration,
// last_asset: old_state.last_asset, // last_asset: old_state.last_asset,
// upgrade_hash: old_state.upgrade_hash, // upgrade_hash: old_state.upgrade_hash,
// tokens: old_state.tokens, //
// key_map: old_state.key_map, // tokens: old_state.tokens,
// hash_map: old_state.hash_map, // key_map: old_state.key_map,
// bank: old_state.bank, // hash_map: old_state.hash_map,
//
// bank: old_state.bank,
// } // }
// } }
} }
// let result = await userAccount.functionCall({ // let result = await userAccount.functionCall({

View File

@ -345,6 +345,7 @@ impl Wormhole {
Promise::new(env::current_account_id()) Promise::new(env::current_account_id())
.deploy_contract(v.to_vec()) .deploy_contract(v.to_vec())
.then(Self::ext(env::current_account_id()).migrate())
.then(Self::ext(env::current_account_id()).update_contract_done( .then(Self::ext(env::current_account_id()).update_contract_done(
env::predecessor_account_id(), env::predecessor_account_id(),
env::storage_usage(), env::storage_usage(),
@ -601,16 +602,13 @@ impl Wormhole {
true true
} }
// #[init(ignore_state)] #[init(ignore_state)]
// #[payable] pub fn migrate() -> Self {
// #[private] env::log_str(&format!("wormhole/{}#{}: migrate", file!(), line!(),));
// pub fn migrate() -> Self {
// // call migrate on self let state: Wormhole = env::state_read().expect("failed");
// if env::attached_deposit() != 1 { state
// env::panic_str("Need money");
// }
// let old_state: OldWormhole = env::state_read().expect("failed"); // let old_state: OldWormhole = env::state_read().expect("failed");
// env::log_str(&format!("wormhole/{}#{}: migrate", file!(), line!(),));
// Self { // Self {
// guardians: old_state.guardians, // guardians: old_state.guardians,
// dups: old_state.dups, // dups: old_state.dups,
@ -622,7 +620,7 @@ impl Wormhole {
// message_fee: old_state.message_fee, // message_fee: old_state.message_fee,
// bank: old_state.bank, // bank: old_state.bank,
// } // }
// } }
} }
// let result = await userAccount.functionCall({ // let result = await userAccount.functionCall({