Skip to content

Commit

Permalink
Prepare testnet reverse migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tifrel committed Jan 13, 2023
1 parent ad06e0c commit c84db2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
1 change: 0 additions & 1 deletion factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use mintbase_deps::constants::{
gas,
storage_bytes,
storage_stake,
NO_DEPOSIT,
YOCTO_PER_BYTE,
};
use mintbase_deps::interfaces::factory_self;
Expand Down
2 changes: 1 addition & 1 deletion simple-market-contract
48 changes: 15 additions & 33 deletions store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,37 +216,31 @@ impl MintbaseStore {
/// which should also be reversible
/// - Will require partial reindexing
#[private]
pub fn prepend_base_uri(
pub fn set_reference_media(
&mut self,
base_uri: String,
token_ids_with_media: Vec<(String, Option<String>)>,
specs: Vec<(String, Option<String>, Option<String>)>,
) {
for (token_id, media) in token_ids_with_media
.iter()
.map(|(id, media)| (id.parse::<u64>().unwrap(), media))
{
let metadata_id = self.tokens.get(&token_id).unwrap().metadata_id;
for (token_id, reference, media) in specs {
let metadata_id = self
.tokens
.get(&token_id.parse().unwrap())
.unwrap()
.metadata_id;
let (n, mut metadata) = self.token_metadata.get(&metadata_id).unwrap();
metadata.reference = concat_uri(&base_uri, &metadata.reference);
metadata.media = concat_uri(&base_uri, &media);
metadata.reference = reference;
metadata.media = media;
self.token_metadata.insert(&metadata_id, &(n, metadata));
}
}

/// Drops the base_uri after successfully migration all tokens with
/// `prepend_base_uri`
#[private]
pub fn drop_base_uri(&mut self) {
self.metadata.base_uri = None;
}

/// While prepending and dropping base_uri, I destroyed
/// nearcon2demo1.mintspace2.testnet, and one day I might wish to repair it
/// using this method.
#[private]
pub fn repair_reference(&mut self) {
// FIXME: repair nearcon2demo1.minstpace2.testnet -> remove `nan/` prefixes on reference
self.metadata.base_uri = None;
pub fn set_base_uri(
&mut self,
base_uri: Option<String>,
) {
self.metadata.base_uri = base_uri;
}

// -------------------------- internal methods -------------------------
Expand Down Expand Up @@ -339,15 +333,3 @@ pub trait NonFungibleResolveTransfer {
approved_account_ids: Option<Vec<String>>,
);
}

fn concat_uri(
base: &str,
uri: &Option<String>,
) -> Option<String> {
match uri {
None => None,
Some(uri) if uri.starts_with(base) => Some(uri.to_string()),
Some(uri) if base.ends_with('/') => Some(format!("{}{}", base, uri)),
Some(uri) => Some(format!("{}/{}", base, uri)),
}
}

0 comments on commit c84db2e

Please sign in to comment.