diff --git a/nft-contract/src/enumeration.rs b/nft-contract/src/enumeration.rs index 1dc1083..5d1e0de 100644 --- a/nft-contract/src/enumeration.rs +++ b/nft-contract/src/enumeration.rs @@ -10,18 +10,15 @@ impl Contract { //Query for nft tokens on the contract regardless of the owner using pagination pub fn nft_tokens(&self, from_index: Option, limit: Option) -> Vec { - //get a vector of the keys in the token_metadata_by_id collection. - let keys = self.token_metadata_by_id.keys_as_vector(); - //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index let start = u128::from(from_index.unwrap_or(U128(0))); - //iterate through the keys vector - keys.iter() + //iterate through each token using an iterator + self.token_metadata_by_id.keys() //skip to the index we specified in the start variable .skip(start as usize) - //take the first "limit" elements in the vector. If we didn't specify a limit, use 0 - .take(limit.unwrap_or(0) as usize) + //take the first "limit" elements in the vector. If we didn't specify a limit, use 50 + .take(limit.unwrap_or(50) as usize) //we'll map the token IDs which are strings into Json Tokens .map(|token_id| self.nft_token(token_id.clone()).unwrap()) //since we turned the keys into an iterator, we need to turn it back into a vector to return @@ -61,21 +58,19 @@ impl Contract { //if there is no set of tokens, we'll simply return an empty vector. return vec![]; }; - //we'll convert the UnorderedSet into a vector of strings - let keys = tokens.as_vector(); //where to start pagination - if we have a from_index, we'll use that - otherwise start from 0 index let start = u128::from(from_index.unwrap_or(U128(0))); //iterate through the keys vector - keys.iter() + tokens.iter() //skip to the index we specified in the start variable .skip(start as usize) - //take the first "limit" elements in the vector. If we didn't specify a limit, use 0 - .take(limit.unwrap_or(0) as usize) + //take the first "limit" elements in the vector. If we didn't specify a limit, use 50 + .take(limit.unwrap_or(50) as usize) //we'll map the token IDs which are strings into Json Tokens .map(|token_id| self.nft_token(token_id.clone()).unwrap()) //since we turned the keys into an iterator, we need to turn it back into a vector to return .collect() } -} \ No newline at end of file +} diff --git a/out/main.wasm b/out/main.wasm index 86f569d..622cb0d 100755 Binary files a/out/main.wasm and b/out/main.wasm differ