git.delta.rocks / unique-network / refs/commits / 7d542e4157ec

difftreelog

refac: rename string -> String

Trubnikov Sergey2023-01-18parent: #a4ecd38.patch.diff
in: master

16 files changed

modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
999 )*),999 )*),
1000 };1000 };
10011001
1002 let mut out = ::evm_coder::types::string::new();1002 let mut out = ::evm_coder::types::String::new();
1003 if #solidity_name.starts_with("Inline") {1003 if #solidity_name.starts_with("Inline") {
1004 out.push_str("/// @dev inlined interface\n");1004 out.push_str("/// @dev inlined interface\n");
1005 }1005 }
modifiedcrates/evm-coder/procedural/src/to_log.rsdiffbeforeafterboth
222 #solidity_functions,222 #solidity_functions,
223 )*),223 )*),
224 };224 };
225 let mut out = string::new();225 let mut out = ::evm_coder::types::String::new();
226 out.push_str("/// @dev inlined interface\n");226 out.push_str("/// @dev inlined interface\n");
227 let _ = interface.format(is_impl, &mut out, tc);227 let _ = interface.format(is_impl, &mut out, tc);
228 tc.collect(out);228 tc.collect(out);
modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
63impl_abi!(u128, uint128, false);63impl_abi!(u128, uint128, false);
64impl_abi!(U256, uint256, false);64impl_abi!(U256, uint256, false);
65impl_abi!(H160, address, false);65impl_abi!(H160, address, false);
66impl_abi!(string, string, true);66impl_abi!(String, string, true);
6767
68impl_abi_writeable!(&str, string);68impl_abi_writeable!(&str, string);
6969
modifiedcrates/evm-coder/src/abi/mod.rsdiffbeforeafterboth
148 }148 }
149149
150 /// Read [`string`] at current position, then advance150 /// Read [`string`] at current position, then advance
151 pub fn string(&mut self) -> Result<string> {151 pub fn string(&mut self) -> Result<String> {
152 string::from_utf8(self.bytes()?).map_err(|_| Error::Error(ExitError::InvalidRange))152 String::from_utf8(self.bytes()?).map_err(|_| Error::Error(ExitError::InvalidRange))
153 }153 }
154154
155 /// Read [`u8`] at current position, then advance155 /// Read [`u8`] at current position, then advance
modifiedcrates/evm-coder/src/abi/test.rsdiffbeforeafterboth
138138
139#[test]139#[test]
140fn encode_decode_vec_tuple_uint256_string() {140fn encode_decode_vec_tuple_uint256_string() {
141 test_impl::<Vec<(U256, string)>>(141 test_impl::<Vec<(U256, String)>>(
142 0xdeadbeef,142 0xdeadbeef,
143 vec![143 vec![
144 (1.into(), "Test URI 0".to_string()),144 (1.into(), "Test URI 0".to_string()),
261 let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();261 let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();
262 assert_eq!(call, u32::to_be_bytes(decoded_data.0));262 assert_eq!(call, u32::to_be_bytes(decoded_data.0));
263 let address = decoder.address().unwrap();263 let address = decoder.address().unwrap();
264 let data = <Vec<(U256, string)>>::abi_read(&mut decoder).unwrap();264 let data = <Vec<(U256, String)>>::abi_read(&mut decoder).unwrap();
265 assert_eq!(data, decoded_data.1);265 assert_eq!(data, decoded_data.1);
266266
267 let mut writer = AbiWriter::new_call(decoded_data.0);267 let mut writer = AbiWriter::new_call(decoded_data.0);
273273
274#[test]274#[test]
275fn encode_decode_vec_tuple_string_bytes() {275fn encode_decode_vec_tuple_string_bytes() {
276 test_impl::<Vec<(string, bytes)>>(276 test_impl::<Vec<(String, bytes)>>(
277 0xdeadbeef,277 0xdeadbeef,
278 vec![278 vec![
279 (279 (
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
136 pub type Topic = H256;136 pub type Topic = H256;
137137
138 #[cfg(not(feature = "std"))]138 #[cfg(not(feature = "std"))]
139 pub type string = ::alloc::string::String;139 pub type String = ::alloc::string::String;
140 #[cfg(feature = "std")]140 #[cfg(feature = "std")]
141 pub type string = ::std::string::String;141 pub type String = ::std::string::String;
142142
143 #[derive(Default, Debug, PartialEq, Eq, Clone)]143 #[derive(Default, Debug, PartialEq, Eq, Clone)]
144 pub struct bytes(pub Vec<u8>);144 pub struct bytes(pub Vec<u8>);
modifiedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth
29 U256 => "uint256" true = "0",29 U256 => "uint256" true = "0",
30 Bytes4 => "bytes4" true = "bytes4(0)",30 Bytes4 => "bytes4" true = "bytes4(0)",
31 H160 => "address" true = "0x0000000000000000000000000000000000000000",31 H160 => "address" true = "0x0000000000000000000000000000000000000000",
32 string => "string" false = "\"\"",32 String => "string" false = "\"\"",
33 bytes => "bytes" false = "hex\"\"",33 bytes => "bytes" false = "hex\"\"",
34 bool => "bool" true = "false",34 bool => "bool" true = "false",
35}35}
72macro_rules! impl_tuples {72macro_rules! impl_tuples {
73 ($($ident:ident)+) => {73 ($($ident:ident)+) => {
74 impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleTy for ($($ident,)+) {74 impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleTy for ($($ident,)+) {
75 fn fields(tc: &TypeCollector) -> Vec<string> {75 fn fields(tc: &TypeCollector) -> Vec<String> {
76 let mut collected = Vec::with_capacity(Self::len());76 let mut collected = Vec::with_capacity(Self::len());
77 $({77 $({
78 let mut out = string::new();78 let mut out = String::new();
79 $ident::solidity_name(&mut out, tc).expect("no fmt error");79 $ident::solidity_name(&mut out, tc).expect("no fmt error");
80 collected.push(out);80 collected.push(out);
81 })*;81 })*;
modifiedcrates/evm-coder/src/solidity/mod.rsdiffbeforeafterboth
26mod impls;26mod impls;
2727
28#[cfg(not(feature = "std"))]28#[cfg(not(feature = "std"))]
29use alloc::{string::String, vec::Vec, collections::BTreeMap, format};29use alloc::{vec::Vec, collections::BTreeMap, format};
30#[cfg(feature = "std")]30#[cfg(feature = "std")]
31use std::collections::BTreeMap;31use std::collections::BTreeMap;
32use core::{32use core::{
42pub struct TypeCollector {42pub struct TypeCollector {
43 /// Code => id43 /// Code => id
44 /// id ordering is required to perform topo-sort on the resulting data44 /// id ordering is required to perform topo-sort on the resulting data
45 structs: RefCell<BTreeMap<string, usize>>,45 structs: RefCell<BTreeMap<String, usize>>,
46 anonymous: RefCell<BTreeMap<Vec<string>, usize>>,46 anonymous: RefCell<BTreeMap<Vec<String>, usize>>,
47 // generic: RefCell<BTreeMap<string, usize>>,47 // generic: RefCell<BTreeMap<String, usize>>,
48 id: Cell<usize>,48 id: Cell<usize>,
49}49}
50impl TypeCollector {50impl TypeCollector {
51 pub fn new() -> Self {51 pub fn new() -> Self {
52 Self::default()52 Self::default()
53 }53 }
54 pub fn collect(&self, item: string) {54 pub fn collect(&self, item: String) {
55 let id = self.next_id();55 let id = self.next_id();
56 self.structs.borrow_mut().insert(item, id);56 self.structs.borrow_mut().insert(item, id);
57 }57 }
84 pub fn collect_enum<T: SolidityEnumTy>(&self) -> String {84 pub fn collect_enum<T: SolidityEnumTy>(&self) -> String {
85 T::generate_solidity_interface(self)85 T::generate_solidity_interface(self)
86 }86 }
87 pub fn finish(self) -> Vec<string> {87 pub fn finish(self) -> Vec<String> {
88 let mut data = self.structs.into_inner().into_iter().collect::<Vec<_>>();88 let mut data = self.structs.into_inner().into_iter().collect::<Vec<_>>();
89 data.sort_by_key(|(_, id)| Reverse(*id));89 data.sort_by_key(|(_, id)| Reverse(*id));
90 data.into_iter().map(|(code, _)| code).collect()90 data.into_iter().map(|(code, _)| code).collect()
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
94 /// @param value Propery value.94 /// @param value Propery value.
95 #[solidity(hide)]95 #[solidity(hide)]
96 #[weight(<SelfWeightOf<T>>::set_collection_properties(1))]96 #[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
97 fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {97 fn set_collection_property(&mut self, caller: caller, key: String, value: bytes) -> Result<()> {
98 let caller = T::CrossAccountId::from_eth(caller);98 let caller = T::CrossAccountId::from_eth(caller);
99 let key = <Vec<u8>>::from(key)99 let key = <Vec<u8>>::from(key)
100 .try_into()100 .try_into()
130 /// @param key Property key.130 /// @param key Property key.
131 #[solidity(hide)]131 #[solidity(hide)]
132 #[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]132 #[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]
133 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {133 fn delete_collection_property(&mut self, caller: caller, key: String) -> Result<()> {
134 let caller = T::CrossAccountId::from_eth(caller);134 let caller = T::CrossAccountId::from_eth(caller);
135 let key = <Vec<u8>>::from(key)135 let key = <Vec<u8>>::from(key)
136 .try_into()136 .try_into()
143 ///143 ///
144 /// @param keys Properties keys.144 /// @param keys Properties keys.
145 #[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]145 #[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]
146 fn delete_collection_properties(&mut self, caller: caller, keys: Vec<string>) -> Result<()> {146 fn delete_collection_properties(&mut self, caller: caller, keys: Vec<String>) -> Result<()> {
147 let caller = T::CrossAccountId::from_eth(caller);147 let caller = T::CrossAccountId::from_eth(caller);
148 let keys = keys148 let keys = keys
149 .into_iter()149 .into_iter()
164 ///164 ///
165 /// @param key Property key.165 /// @param key Property key.
166 /// @return bytes The property corresponding to the key.166 /// @return bytes The property corresponding to the key.
167 fn collection_property(&self, key: string) -> Result<bytes> {167 fn collection_property(&self, key: String) -> Result<bytes> {
168 let key = <Vec<u8>>::from(key)168 let key = <Vec<u8>>::from(key)
169 .try_into()169 .try_into()
170 .map_err(|_| "key too large")?;170 .map_err(|_| "key too large")?;
179 ///179 ///
180 /// @param keys Properties keys. Empty keys for all propertyes.180 /// @param keys Properties keys. Empty keys for all propertyes.
181 /// @return Vector of properties key/value pairs.181 /// @return Vector of properties key/value pairs.
182 fn collection_properties(&self, keys: Vec<string>) -> Result<Vec<eth::Property>> {182 fn collection_properties(&self, keys: Vec<String>) -> Result<Vec<eth::Property>> {
183 let keys = keys183 let keys = keys
184 .into_iter()184 .into_iter()
185 .map(|key| {185 .map(|key| {
616 /// Returns collection type616 /// Returns collection type
617 ///617 ///
618 /// @return `Fungible` or `NFT` or `ReFungible`618 /// @return `Fungible` or `NFT` or `ReFungible`
619 fn unique_collection_type(&self) -> Result<string> {619 fn unique_collection_type(&self) -> Result<String> {
620 let mode = match self.collection.mode {620 let mode = match self.collection.mode {
621 CollectionMode::Fungible(_) => "Fungible",621 CollectionMode::Fungible(_) => "Fungible",
622 CollectionMode::NFT => "NFT",622 CollectionMode::NFT => "NFT",
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
118/// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).118/// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
119#[derive(Debug, Default, AbiCoder)]119#[derive(Debug, Default, AbiCoder)]
120pub struct Property {120pub struct Property {
121 key: evm_coder::types::string,121 key: evm_coder::types::String,
122 value: evm_coder::types::bytes,122 value: evm_coder::types::bytes,
123}123}
124124
125impl TryFrom<up_data_structs::Property> for Property {125impl TryFrom<up_data_structs::Property> for Property {
126 type Error = evm_coder::execution::Error;126 type Error = evm_coder::execution::Error;
127127
128 fn try_from(from: up_data_structs::Property) -> Result<Self, Self::Error> {128 fn try_from(from: up_data_structs::Property) -> Result<Self, Self::Error> {
129 let key = evm_coder::types::string::from_utf8(from.key.into())129 let key = evm_coder::types::String::from_utf8(from.key.into())
130 .map_err(|e| Self::Error::Revert(format!("utf8 conversion error: {}", e)))?;130 .map_err(|e| Self::Error::Revert(format!("utf8 conversion error: {}", e)))?;
131 let value = evm_coder::types::bytes(from.value.to_vec());131 let value = evm_coder::types::bytes(from.value.to_vec());
132 Ok(Property { key, value })132 Ok(Property { key, value })
342#[derive(Debug, Default, AbiCoder)]342#[derive(Debug, Default, AbiCoder)]
343pub struct TokenPropertyPermission {343pub struct TokenPropertyPermission {
344 /// Token property key.344 /// Token property key.
345 key: evm_coder::types::string,345 key: evm_coder::types::String,
346 /// Token property permissions.346 /// Token property permissions.
347 permissions: Vec<PropertyPermission>,347 permissions: Vec<PropertyPermission>,
348}348}
360 ),360 ),
361 ) -> Self {361 ) -> Self {
362 let (key, permission) = value;362 let (key, permission) = value;
363 let key = evm_coder::types::string::from_utf8(key.into_inner())363 let key = evm_coder::types::String::from_utf8(key.into_inner())
364 .expect("Stored key must be valid");364 .expect("Stored key must be valid");
365 let permissions = PropertyPermission::into_vec(permission);365 let permissions = PropertyPermission::into_vec(permission);
366 Self { key, permissions }366 Self { key, permissions }
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
5959
60#[solidity_interface(name = ERC20, events(ERC20Events))]60#[solidity_interface(name = ERC20, events(ERC20Events))]
61impl<T: Config> FungibleHandle<T> {61impl<T: Config> FungibleHandle<T> {
62 fn name(&self) -> Result<string> {62 fn name(&self) -> Result<String> {
63 Ok(decode_utf16(self.name.iter().copied())63 Ok(decode_utf16(self.name.iter().copied())
64 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))64 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
65 .collect::<string>())65 .collect::<String>())
66 }66 }
67 fn symbol(&self) -> Result<string> {67 fn symbol(&self) -> Result<String> {
68 Ok(string::from_utf8_lossy(&self.token_prefix).into())68 Ok(String::from_utf8_lossy(&self.token_prefix).into())
69 }69 }
70 fn total_supply(&self) -> Result<U256> {70 fn total_supply(&self) -> Result<U256> {
71 self.consume_store_reads(1)?;71 self.consume_store_reads(1)?;
167 T::AccountId: From<[u8; 32]>,167 T::AccountId: From<[u8; 32]>,
168{168{
169 /// @notice A description for the collection.169 /// @notice A description for the collection.
170 fn description(&self) -> Result<string> {170 fn description(&self) -> Result<String> {
171 Ok(decode_utf16(self.description.iter().copied())171 Ok(decode_utf16(self.description.iter().copied())
172 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))172 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
173 .collect::<string>())173 .collect::<String>())
174 }174 }
175175
176 #[weight(<SelfWeightOf<T>>::create_item())]176 #[weight(<SelfWeightOf<T>>::create_item())]
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
64 fn set_token_property_permission(64 fn set_token_property_permission(
65 &mut self,65 &mut self,
66 caller: caller,66 caller: caller,
67 key: string,67 key: String,
68 is_mutable: bool,68 is_mutable: bool,
69 collection_admin: bool,69 collection_admin: bool,
70 token_owner: bool,70 token_owner: bool,
123 &mut self,123 &mut self,
124 caller: caller,124 caller: caller,
125 token_id: U256,125 token_id: U256,
126 key: string,126 key: String,
127 value: bytes,127 value: bytes,
128 ) -> Result<()> {128 ) -> Result<()> {
129 let caller = T::CrossAccountId::from_eth(caller);129 let caller = T::CrossAccountId::from_eth(caller);
187 /// @param key Property key.187 /// @param key Property key.
188 #[solidity(hide)]188 #[solidity(hide)]
189 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]189 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]
190 fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {190 fn delete_property(&mut self, token_id: U256, caller: caller, key: String) -> Result<()> {
191 let caller = T::CrossAccountId::from_eth(caller);191 let caller = T::CrossAccountId::from_eth(caller);
192 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;192 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
193 let key = <Vec<u8>>::from(key)193 let key = <Vec<u8>>::from(key)
211 &mut self,211 &mut self,
212 token_id: U256,212 token_id: U256,
213 caller: caller,213 caller: caller,
214 keys: Vec<string>,214 keys: Vec<String>,
215 ) -> Result<()> {215 ) -> Result<()> {
216 let caller = T::CrossAccountId::from_eth(caller);216 let caller = T::CrossAccountId::from_eth(caller);
217 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;217 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
239 /// @param tokenId ID of the token.239 /// @param tokenId ID of the token.
240 /// @param key Property key.240 /// @param key Property key.
241 /// @return Property value bytes241 /// @return Property value bytes
242 fn property(&self, token_id: U256, key: string) -> Result<bytes> {242 fn property(&self, token_id: U256, key: String) -> Result<bytes> {
243 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;243 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
244 let key = <Vec<u8>>::from(key)244 let key = <Vec<u8>>::from(key)
245 .try_into()245 .try_into()
301 /// @notice A descriptive name for a collection of NFTs in this contract301 /// @notice A descriptive name for a collection of NFTs in this contract
302 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`302 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`
303 #[solidity(hide, rename_selector = "name")]303 #[solidity(hide, rename_selector = "name")]
304 fn name_proxy(&self) -> Result<string> {304 fn name_proxy(&self) -> Result<String> {
305 self.name()305 self.name()
306 }306 }
307307
308 /// @notice An abbreviated name for NFTs in this contract308 /// @notice An abbreviated name for NFTs in this contract
309 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`309 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`
310 #[solidity(hide, rename_selector = "symbol")]310 #[solidity(hide, rename_selector = "symbol")]
311 fn symbol_proxy(&self) -> Result<string> {311 fn symbol_proxy(&self) -> Result<String> {
312 self.symbol()312 self.symbol()
313 }313 }
314314
322 ///322 ///
323 /// @return token's const_metadata323 /// @return token's const_metadata
324 #[solidity(rename_selector = "tokenURI")]324 #[solidity(rename_selector = "tokenURI")]
325 fn token_uri(&self, token_id: U256) -> Result<string> {325 fn token_uri(&self, token_id: U256) -> Result<String> {
326 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;326 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
327327
328 match get_token_property(self, token_id_u32, &key::url()).as_deref() {328 match get_token_property(self, token_id_u32, &key::url()).as_deref() {
335 let base_uri =335 let base_uri =
336 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())336 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
337 .map(BoundedVec::into_inner)337 .map(BoundedVec::into_inner)
338 .map(string::from_utf8)338 .map(String::from_utf8)
339 .transpose()339 .transpose()
340 .map_err(|e| {340 .map_err(|e| {
341 Error::Revert(alloc::format!(341 Error::Revert(alloc::format!(
595 &mut self,595 &mut self,
596 caller: caller,596 caller: caller,
597 to: Address,597 to: Address,
598 token_uri: string,598 token_uri: String,
599 ) -> Result<U256> {599 ) -> Result<U256> {
600 let token_id: U256 = <TokensMinted<T>>::get(self.id)600 let token_id: U256 = <TokensMinted<T>>::get(self.id)
601 .checked_add(1)601 .checked_add(1)
618 caller: caller,618 caller: caller,
619 to: Address,619 to: Address,
620 token_id: U256,620 token_id: U256,
621 token_uri: string,621 token_uri: String,
622 ) -> Result<bool> {622 ) -> Result<bool> {
623 let key = key::url();623 let key = key::url();
624 let permission = get_token_permission::<T>(self.id, &key)?;624 let permission = get_token_permission::<T>(self.id, &key)?;
670 collection: &CollectionHandle<T>,670 collection: &CollectionHandle<T>,
671 token_id: u32,671 token_id: u32,
672 key: &up_data_structs::PropertyKey,672 key: &up_data_structs::PropertyKey,
673) -> Result<string> {673) -> Result<String> {
674 collection.consume_store_reads(1)?;674 collection.consume_store_reads(1)?;
675 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))675 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))
676 .map_err(|_| Error::Revert("Token properties not found".into()))?;676 .map_err(|_| Error::Revert("Token properties not found".into()))?;
677 if let Some(property) = properties.get(key) {677 if let Some(property) = properties.get(key) {
678 return Ok(string::from_utf8_lossy(property).into());678 return Ok(String::from_utf8_lossy(property).into());
679 }679 }
680680
681 Err("Property tokenURI not found".into())681 Err("Property tokenURI not found".into())
691 .get(key)691 .get(key)
692 .map(Clone::clone)692 .map(Clone::clone)
693 .ok_or_else(|| {693 .ok_or_else(|| {
694 let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();694 let key = String::from_utf8(key.clone().into_inner()).unwrap_or_default();
695 Error::Revert(alloc::format!("No permission for key {}", key))695 Error::Revert(alloc::format!("No permission for key {}", key))
696 })?;696 })?;
697 Ok(a)697 Ok(a)
704 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,704 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,
705{705{
706 /// @notice A descriptive name for a collection of NFTs in this contract706 /// @notice A descriptive name for a collection of NFTs in this contract
707 fn name(&self) -> Result<string> {707 fn name(&self) -> Result<String> {
708 Ok(decode_utf16(self.name.iter().copied())708 Ok(decode_utf16(self.name.iter().copied())
709 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))709 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
710 .collect::<string>())710 .collect::<String>())
711 }711 }
712712
713 /// @notice An abbreviated name for NFTs in this contract713 /// @notice An abbreviated name for NFTs in this contract
714 fn symbol(&self) -> Result<string> {714 fn symbol(&self) -> Result<String> {
715 Ok(string::from_utf8_lossy(&self.token_prefix).into())715 Ok(String::from_utf8_lossy(&self.token_prefix).into())
716 }716 }
717717
718 /// @notice A description for the collection.718 /// @notice A description for the collection.
719 fn description(&self) -> Result<string> {719 fn description(&self) -> Result<String> {
720 Ok(decode_utf16(self.description.iter().copied())720 Ok(decode_utf16(self.description.iter().copied())
721 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))721 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
722 .collect::<string>())722 .collect::<String>())
723 }723 }
724724
725 /// Returns the owner (in cross format) of the token.725 /// Returns the owner (in cross format) of the token.
736 /// @param tokenId Id for the token.736 /// @param tokenId Id for the token.
737 /// @param keys Properties keys. Empty keys for all propertyes.737 /// @param keys Properties keys. Empty keys for all propertyes.
738 /// @return Vector of properties key/value pairs.738 /// @return Vector of properties key/value pairs.
739 fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {739 fn properties(&self, token_id: U256, keys: Vec<String>) -> Result<Vec<eth::Property>> {
740 let keys = keys740 let keys = keys
741 .into_iter()741 .into_iter()
742 .map(|key| {742 .map(|key| {
948 &mut self,948 &mut self,
949 caller: caller,949 caller: caller,
950 to: Address,950 to: Address,
951 tokens: Vec<(U256, string)>,951 tokens: Vec<(U256, String)>,
952 ) -> Result<bool> {952 ) -> Result<bool> {
953 let key = key::url();953 let key = key::url();
954 let caller = T::CrossAccountId::from_eth(caller);954 let caller = T::CrossAccountId::from_eth(caller);
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
67 fn set_token_property_permission(67 fn set_token_property_permission(
68 &mut self,68 &mut self,
69 caller: caller,69 caller: caller,
70 key: string,70 key: String,
71 is_mutable: bool,71 is_mutable: bool,
72 collection_admin: bool,72 collection_admin: bool,
73 token_owner: bool,73 token_owner: bool,
126 &mut self,126 &mut self,
127 caller: caller,127 caller: caller,
128 token_id: U256,128 token_id: U256,
129 key: string,129 key: String,
130 value: bytes,130 value: bytes,
131 ) -> Result<()> {131 ) -> Result<()> {
132 let caller = T::CrossAccountId::from_eth(caller);132 let caller = T::CrossAccountId::from_eth(caller);
190 /// @param key Property key.190 /// @param key Property key.
191 #[solidity(hide)]191 #[solidity(hide)]
192 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]192 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]
193 fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {193 fn delete_property(&mut self, token_id: U256, caller: caller, key: String) -> Result<()> {
194 let caller = T::CrossAccountId::from_eth(caller);194 let caller = T::CrossAccountId::from_eth(caller);
195 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;195 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
196 let key = <Vec<u8>>::from(key)196 let key = <Vec<u8>>::from(key)
214 &mut self,214 &mut self,
215 token_id: U256,215 token_id: U256,
216 caller: caller,216 caller: caller,
217 keys: Vec<string>,217 keys: Vec<String>,
218 ) -> Result<()> {218 ) -> Result<()> {
219 let caller = T::CrossAccountId::from_eth(caller);219 let caller = T::CrossAccountId::from_eth(caller);
220 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;220 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
242 /// @param tokenId ID of the token.242 /// @param tokenId ID of the token.
243 /// @param key Property key.243 /// @param key Property key.
244 /// @return Property value bytes244 /// @return Property value bytes
245 fn property(&self, token_id: U256, key: string) -> Result<bytes> {245 fn property(&self, token_id: U256, key: String) -> Result<bytes> {
246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
247 let key = <Vec<u8>>::from(key)247 let key = <Vec<u8>>::from(key)
248 .try_into()248 .try_into()
298 /// @notice A descriptive name for a collection of NFTs in this contract298 /// @notice A descriptive name for a collection of NFTs in this contract
299 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`299 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`
300 #[solidity(hide, rename_selector = "name")]300 #[solidity(hide, rename_selector = "name")]
301 fn name_proxy(&self) -> Result<string> {301 fn name_proxy(&self) -> Result<String> {
302 self.name()302 self.name()
303 }303 }
304304
305 /// @notice An abbreviated name for NFTs in this contract305 /// @notice An abbreviated name for NFTs in this contract
306 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`306 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`
307 #[solidity(hide, rename_selector = "symbol")]307 #[solidity(hide, rename_selector = "symbol")]
308 fn symbol_proxy(&self) -> Result<string> {308 fn symbol_proxy(&self) -> Result<String> {
309 self.symbol()309 self.symbol()
310 }310 }
311311
319 ///319 ///
320 /// @return token's const_metadata320 /// @return token's const_metadata
321 #[solidity(rename_selector = "tokenURI")]321 #[solidity(rename_selector = "tokenURI")]
322 fn token_uri(&self, token_id: U256) -> Result<string> {322 fn token_uri(&self, token_id: U256) -> Result<String> {
323 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;323 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
324324
325 match get_token_property(self, token_id_u32, &key::url()).as_deref() {325 match get_token_property(self, token_id_u32, &key::url()).as_deref() {
332 let base_uri =332 let base_uri =
333 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())333 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
334 .map(BoundedVec::into_inner)334 .map(BoundedVec::into_inner)
335 .map(string::from_utf8)335 .map(String::from_utf8)
336 .transpose()336 .transpose()
337 .map_err(|e| {337 .map_err(|e| {
338 Error::Revert(alloc::format!(338 Error::Revert(alloc::format!(
631 &mut self,631 &mut self,
632 caller: caller,632 caller: caller,
633 to: Address,633 to: Address,
634 token_uri: string,634 token_uri: String,
635 ) -> Result<U256> {635 ) -> Result<U256> {
636 let token_id: U256 = <TokensMinted<T>>::get(self.id)636 let token_id: U256 = <TokensMinted<T>>::get(self.id)
637 .checked_add(1)637 .checked_add(1)
654 caller: caller,654 caller: caller,
655 to: Address,655 to: Address,
656 token_id: U256,656 token_id: U256,
657 token_uri: string,657 token_uri: String,
658 ) -> Result<bool> {658 ) -> Result<bool> {
659 let key = key::url();659 let key = key::url();
660 let permission = get_token_permission::<T>(self.id, &key)?;660 let permission = get_token_permission::<T>(self.id, &key)?;
708 collection: &CollectionHandle<T>,708 collection: &CollectionHandle<T>,
709 token_id: u32,709 token_id: u32,
710 key: &up_data_structs::PropertyKey,710 key: &up_data_structs::PropertyKey,
711) -> Result<string> {711) -> Result<String> {
712 collection.consume_store_reads(1)?;712 collection.consume_store_reads(1)?;
713 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))713 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))
714 .map_err(|_| Error::Revert("Token properties not found".into()))?;714 .map_err(|_| Error::Revert("Token properties not found".into()))?;
715 if let Some(property) = properties.get(key) {715 if let Some(property) = properties.get(key) {
716 return Ok(string::from_utf8_lossy(property).into());716 return Ok(String::from_utf8_lossy(property).into());
717 }717 }
718718
719 Err("Property tokenURI not found".into())719 Err("Property tokenURI not found".into())
729 .get(key)729 .get(key)
730 .map(Clone::clone)730 .map(Clone::clone)
731 .ok_or_else(|| {731 .ok_or_else(|| {
732 let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();732 let key = String::from_utf8(key.clone().into_inner()).unwrap_or_default();
733 Error::Revert(alloc::format!("No permission for key {}", key))733 Error::Revert(alloc::format!("No permission for key {}", key))
734 })?;734 })?;
735 Ok(a)735 Ok(a)
742 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,742 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,
743{743{
744 /// @notice A descriptive name for a collection of NFTs in this contract744 /// @notice A descriptive name for a collection of NFTs in this contract
745 fn name(&self) -> Result<string> {745 fn name(&self) -> Result<String> {
746 Ok(decode_utf16(self.name.iter().copied())746 Ok(decode_utf16(self.name.iter().copied())
747 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))747 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
748 .collect::<string>())748 .collect::<String>())
749 }749 }
750750
751 /// @notice An abbreviated name for NFTs in this contract751 /// @notice An abbreviated name for NFTs in this contract
752 fn symbol(&self) -> Result<string> {752 fn symbol(&self) -> Result<String> {
753 Ok(string::from_utf8_lossy(&self.token_prefix).into())753 Ok(String::from_utf8_lossy(&self.token_prefix).into())
754 }754 }
755755
756 /// @notice A description for the collection.756 /// @notice A description for the collection.
757 fn description(&self) -> Result<string> {757 fn description(&self) -> Result<String> {
758 Ok(decode_utf16(self.description.iter().copied())758 Ok(decode_utf16(self.description.iter().copied())
759 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))759 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
760 .collect::<string>())760 .collect::<String>())
761 }761 }
762762
763 /// Returns the owner (in cross format) of the token.763 /// Returns the owner (in cross format) of the token.
774 /// @param tokenId Id for the token.774 /// @param tokenId Id for the token.
775 /// @param keys Properties keys. Empty keys for all propertyes.775 /// @param keys Properties keys. Empty keys for all propertyes.
776 /// @return Vector of properties key/value pairs.776 /// @return Vector of properties key/value pairs.
777 fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {777 fn properties(&self, token_id: U256, keys: Vec<String>) -> Result<Vec<eth::Property>> {
778 let keys = keys778 let keys = keys
779 .into_iter()779 .into_iter()
780 .map(|key| {780 .map(|key| {
991 &mut self,991 &mut self,
992 caller: caller,992 caller: caller,
993 to: Address,993 to: Address,
994 tokens: Vec<(U256, string)>,994 tokens: Vec<(U256, String)>,
995 ) -> Result<bool> {995 ) -> Result<bool> {
996 let key = key::url();996 let key = key::url();
997 let caller = T::CrossAccountId::from_eth(caller);997 let caller = T::CrossAccountId::from_eth(caller);
modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
92#[solidity_interface(name = ERC20, events(ERC20Events))]92#[solidity_interface(name = ERC20, events(ERC20Events))]
93impl<T: Config> RefungibleTokenHandle<T> {93impl<T: Config> RefungibleTokenHandle<T> {
94 /// @return the name of the token.94 /// @return the name of the token.
95 fn name(&self) -> Result<string> {95 fn name(&self) -> Result<String> {
96 Ok(decode_utf16(self.name.iter().copied())96 Ok(decode_utf16(self.name.iter().copied())
97 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))97 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
98 .collect::<string>())98 .collect::<String>())
99 }99 }
100100
101 /// @return the symbol of the token.101 /// @return the symbol of the token.
102 fn symbol(&self) -> Result<string> {102 fn symbol(&self) -> Result<String> {
103 Ok(string::from_utf8_lossy(&self.token_prefix).into())103 Ok(String::from_utf8_lossy(&self.token_prefix).into())
104 }104 }
105105
106 /// @dev Total number of tokens in existence106 /// @dev Total number of tokens in existence
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
5757
58fn convert_data<T: Config>(58fn convert_data<T: Config>(
59 caller: caller,59 caller: caller,
60 name: string,60 name: String,
61 description: string,61 description: String,
62 token_prefix: string,62 token_prefix: String,
63) -> Result<(63) -> Result<(
64 T::CrossAccountId,64 T::CrossAccountId,
65 CollectionName,65 CollectionName,
89fn create_collection_internal<T: Config>(89fn create_collection_internal<T: Config>(
90 caller: caller,90 caller: caller,
91 value: value,91 value: value,
92 name: string,92 name: String,
93 collection_mode: CollectionMode,93 collection_mode: CollectionMode,
94 description: string,94 description: String,
95 token_prefix: string,95 token_prefix: String,
96) -> Result<Address> {96) -> Result<Address> {
97 let (caller, name, description, token_prefix) =97 let (caller, name, description, token_prefix) =
98 convert_data::<T>(caller, name, description, token_prefix)?;98 convert_data::<T>(caller, name, description, token_prefix)?;
151 &mut self,151 &mut self,
152 caller: caller,152 caller: caller,
153 value: value,153 value: value,
154 name: string,154 name: String,
155 description: string,155 description: String,
156 token_prefix: string,156 token_prefix: String,
157 ) -> Result<Address> {157 ) -> Result<Address> {
158 let (caller, name, description, token_prefix) =158 let (caller, name, description, token_prefix) =
159 convert_data::<T>(caller, name, description, token_prefix)?;159 convert_data::<T>(caller, name, description, token_prefix)?;
190 &mut self,190 &mut self,
191 caller: caller,191 caller: caller,
192 value: value,192 value: value,
193 name: string,193 name: String,
194 description: string,194 description: String,
195 token_prefix: string,195 token_prefix: String,
196 ) -> Result<Address> {196 ) -> Result<Address> {
197 create_collection_internal::<T>(197 create_collection_internal::<T>(
198 caller,198 caller,
210 &mut self,210 &mut self,
211 caller: caller,211 caller: caller,
212 value: value,212 value: value,
213 name: string,213 name: String,
214 description: string,214 description: String,
215 token_prefix: string,215 token_prefix: String,
216 ) -> Result<Address> {216 ) -> Result<Address> {
217 create_collection_internal::<T>(217 create_collection_internal::<T>(
218 caller,218 caller,
230 &mut self,230 &mut self,
231 caller: caller,231 caller: caller,
232 value: value,232 value: value,
233 name: string,233 name: String,
234 decimals: u8,234 decimals: u8,
235 description: string,235 description: String,
236 token_prefix: string,236 token_prefix: String,
237 ) -> Result<Address> {237 ) -> Result<Address> {
238 create_collection_internal::<T>(238 create_collection_internal::<T>(
239 caller,239 caller,
250 &mut self,250 &mut self,
251 caller: caller,251 caller: caller,
252 collection: Address,252 collection: Address,
253 base_uri: string,253 base_uri: String,
254 ) -> Result<()> {254 ) -> Result<()> {
255 let caller = T::CrossAccountId::from_eth(caller);255 let caller = T::CrossAccountId::from_eth(caller);
256 let collection =256 let collection =
modifiedruntime/tests/src/tests.rsdiffbeforeafterboth
323 .map(|d| { d.into() })323 .map(|d| { d.into() })
324 .collect()324 .collect()
325 ));325 ));
326 for (index, data) in items_data.into_iter().enumerate() {326 for (index, _data) in items_data.into_iter().enumerate() {
327 let balance = <pallet_refungible::Balance<Test>>::get((327 let balance = <pallet_refungible::Balance<Test>>::get((
328 CollectionId(1),328 CollectionId(1),
329 TokenId((index + 1) as u32),329 TokenId((index + 1) as u32),