Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Nov 30, 2022
2 parents a59e845 + 66e26ff commit 6fd3360
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ pub trait DataNftMint:
description: ManagedBuffer,
) -> DataNftAttributes<Self::Api> {
self.require_minting_is_ready();
self.require_url_is_valid(&data_marshal);
self.require_url_is_valid(&data_stream);
self.require_url_is_valid(&data_preview);
self.require_url_is_valid(&media);
self.require_sft_is_valid(&royalties, &supply);
let caller = self.blockchain().get_caller();
let current_time = self.blockchain().get_block_timestamp();
Expand Down
18 changes: 18 additions & 0 deletions src/requirements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,22 @@ pub trait RequirementsModule: crate::storage::StorageModule {
"Address is not privileged"
);
}

// Checks wheter the uris are valid
fn require_url_is_valid(&self, url: &ManagedBuffer) {
let url_length = url.len();
let starts_with: &[u8] = b"https://";
require!(!url.is_empty(), "URL is empty");
require!(url_length <= 300, "URL length is too big");
require!(url_length >= 20, "URL length is too small");
let url_vec = url.to_boxed_bytes().into_vec();
for i in 0..starts_with.len() {
require!(url_vec[i] == starts_with[i], "URL must start with https://");
}
for i in 0..url_length {
if url_vec[i] == 32 || url_vec[i] == 10 || url_vec[i] == 13 {
sc_panic!("URL contains invalid characters");
}
}
}
}

0 comments on commit 6fd3360

Please sign in to comment.