git.delta.rocks / unique-network / refs/commits / c535db977251

difftreelog

fix token uri == const_data

Yaroslav Bolyukin2021-08-11parent: #cc62c5a.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/eth/erc.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/erc.rs
+++ b/pallets/nft/src/eth/erc.rs
@@ -2,7 +2,6 @@
 use evm_coder::{ToLog, execution::Result, solidity, solidity_interface, types::*};
 use nft_data_structs::{CreateItemData, CreateNftData};
 use core::convert::TryInto;
-use alloc::format;
 use crate::{
 	Allowances, Module, Balance, CollectionHandle, CollectionMode, Config, NftItemList,
 	ItemListIndex,
@@ -46,9 +45,15 @@
 
 #[solidity_interface(name = "ERC721Metadata", inline_is(InlineNameSymbol))]
 impl<T: Config> CollectionHandle<T> {
+	#[solidity(rename_selector = "tokenURI")]
 	fn token_uri(&self, token_id: uint256) -> Result<string> {
-		// TODO: We should standartize url prefix, maybe via offchain schema?
-		Ok(format!("unique.network/{}/{}", self.id, token_id))
+		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
+		Ok(string::from_utf8_lossy(
+			&<NftItemList<T>>::get(self.id, token_id)
+				.ok_or("token not found")?
+				.const_data,
+		)
+		.into())
 	}
 }
 
modifiedpallets/nft/src/eth/stubs/ERC721.soldiffbeforeafterboth
140}140}
141141
142contract ERC721Metadata is Dummy, InlineNameSymbol {142contract ERC721Metadata is Dummy, InlineNameSymbol {
143 function tokenUri(uint256 tokenId) public view returns (string memory) {143 function tokenURI(uint256 tokenId) public view returns (string memory) {
144 require(false, stub_error);144 require(false, stub_error);
145 tokenId;145 tokenId;
146 dummy;146 dummy;