difftreelog
refac: rename string -> String
in: master
16 files changed
crates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth--- a/crates/evm-coder/procedural/src/solidity_interface.rs
+++ b/crates/evm-coder/procedural/src/solidity_interface.rs
@@ -999,7 +999,7 @@
)*),
};
- let mut out = ::evm_coder::types::string::new();
+ let mut out = ::evm_coder::types::String::new();
if #solidity_name.starts_with("Inline") {
out.push_str("/// @dev inlined interface\n");
}
crates/evm-coder/procedural/src/to_log.rsdiffbeforeafterboth--- a/crates/evm-coder/procedural/src/to_log.rs
+++ b/crates/evm-coder/procedural/src/to_log.rs
@@ -222,7 +222,7 @@
#solidity_functions,
)*),
};
- let mut out = string::new();
+ let mut out = ::evm_coder::types::String::new();
out.push_str("/// @dev inlined interface\n");
let _ = interface.format(is_impl, &mut out, tc);
tc.collect(out);
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -63,7 +63,7 @@
impl_abi!(u128, uint128, false);
impl_abi!(U256, uint256, false);
impl_abi!(H160, address, false);
-impl_abi!(string, string, true);
+impl_abi!(String, string, true);
impl_abi_writeable!(&str, string);
crates/evm-coder/src/abi/mod.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/mod.rs
+++ b/crates/evm-coder/src/abi/mod.rs
@@ -148,8 +148,8 @@
}
/// Read [`string`] at current position, then advance
- pub fn string(&mut self) -> Result<string> {
- string::from_utf8(self.bytes()?).map_err(|_| Error::Error(ExitError::InvalidRange))
+ pub fn string(&mut self) -> Result<String> {
+ String::from_utf8(self.bytes()?).map_err(|_| Error::Error(ExitError::InvalidRange))
}
/// Read [`u8`] at current position, then advance
crates/evm-coder/src/abi/test.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/test.rs
+++ b/crates/evm-coder/src/abi/test.rs
@@ -138,7 +138,7 @@
#[test]
fn encode_decode_vec_tuple_uint256_string() {
- test_impl::<Vec<(U256, string)>>(
+ test_impl::<Vec<(U256, String)>>(
0xdeadbeef,
vec![
(1.into(), "Test URI 0".to_string()),
@@ -261,7 +261,7 @@
let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();
assert_eq!(call, u32::to_be_bytes(decoded_data.0));
let address = decoder.address().unwrap();
- let data = <Vec<(U256, string)>>::abi_read(&mut decoder).unwrap();
+ let data = <Vec<(U256, String)>>::abi_read(&mut decoder).unwrap();
assert_eq!(data, decoded_data.1);
let mut writer = AbiWriter::new_call(decoded_data.0);
@@ -273,7 +273,7 @@
#[test]
fn encode_decode_vec_tuple_string_bytes() {
- test_impl::<Vec<(string, bytes)>>(
+ test_impl::<Vec<(String, bytes)>>(
0xdeadbeef,
vec![
(
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -136,9 +136,9 @@
pub type Topic = H256;
#[cfg(not(feature = "std"))]
- pub type string = ::alloc::string::String;
+ pub type String = ::alloc::string::String;
#[cfg(feature = "std")]
- pub type string = ::std::string::String;
+ pub type String = ::std::string::String;
#[derive(Default, Debug, PartialEq, Eq, Clone)]
pub struct bytes(pub Vec<u8>);
crates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth--- a/crates/evm-coder/src/solidity/impls.rs
+++ b/crates/evm-coder/src/solidity/impls.rs
@@ -29,7 +29,7 @@
U256 => "uint256" true = "0",
Bytes4 => "bytes4" true = "bytes4(0)",
H160 => "address" true = "0x0000000000000000000000000000000000000000",
- string => "string" false = "\"\"",
+ String => "string" false = "\"\"",
bytes => "bytes" false = "hex\"\"",
bool => "bool" true = "false",
}
@@ -72,10 +72,10 @@
macro_rules! impl_tuples {
($($ident:ident)+) => {
impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleTy for ($($ident,)+) {
- fn fields(tc: &TypeCollector) -> Vec<string> {
+ fn fields(tc: &TypeCollector) -> Vec<String> {
let mut collected = Vec::with_capacity(Self::len());
$({
- let mut out = string::new();
+ let mut out = String::new();
$ident::solidity_name(&mut out, tc).expect("no fmt error");
collected.push(out);
})*;
crates/evm-coder/src/solidity/mod.rsdiffbeforeafterboth--- a/crates/evm-coder/src/solidity/mod.rs
+++ b/crates/evm-coder/src/solidity/mod.rs
@@ -26,7 +26,7 @@
mod impls;
#[cfg(not(feature = "std"))]
-use alloc::{string::String, vec::Vec, collections::BTreeMap, format};
+use alloc::{vec::Vec, collections::BTreeMap, format};
#[cfg(feature = "std")]
use std::collections::BTreeMap;
use core::{
@@ -42,16 +42,16 @@
pub struct TypeCollector {
/// Code => id
/// id ordering is required to perform topo-sort on the resulting data
- structs: RefCell<BTreeMap<string, usize>>,
- anonymous: RefCell<BTreeMap<Vec<string>, usize>>,
- // generic: RefCell<BTreeMap<string, usize>>,
+ structs: RefCell<BTreeMap<String, usize>>,
+ anonymous: RefCell<BTreeMap<Vec<String>, usize>>,
+ // generic: RefCell<BTreeMap<String, usize>>,
id: Cell<usize>,
}
impl TypeCollector {
pub fn new() -> Self {
Self::default()
}
- pub fn collect(&self, item: string) {
+ pub fn collect(&self, item: String) {
let id = self.next_id();
self.structs.borrow_mut().insert(item, id);
}
@@ -84,7 +84,7 @@
pub fn collect_enum<T: SolidityEnumTy>(&self) -> String {
T::generate_solidity_interface(self)
}
- pub fn finish(self) -> Vec<string> {
+ pub fn finish(self) -> Vec<String> {
let mut data = self.structs.into_inner().into_iter().collect::<Vec<_>>();
data.sort_by_key(|(_, id)| Reverse(*id));
data.into_iter().map(|(code, _)| code).collect()
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -94,7 +94,7 @@
/// @param value Propery value.
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
- fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {
+ fn set_collection_property(&mut self, caller: caller, key: String, value: bytes) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let key = <Vec<u8>>::from(key)
.try_into()
@@ -130,7 +130,7 @@
/// @param key Property key.
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]
- fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {
+ fn delete_collection_property(&mut self, caller: caller, key: String) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let key = <Vec<u8>>::from(key)
.try_into()
@@ -143,7 +143,7 @@
///
/// @param keys Properties keys.
#[weight(<SelfWeightOf<T>>::delete_collection_properties(keys.len() as u32))]
- fn delete_collection_properties(&mut self, caller: caller, keys: Vec<string>) -> Result<()> {
+ fn delete_collection_properties(&mut self, caller: caller, keys: Vec<String>) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let keys = keys
.into_iter()
@@ -164,7 +164,7 @@
///
/// @param key Property key.
/// @return bytes The property corresponding to the key.
- fn collection_property(&self, key: string) -> Result<bytes> {
+ fn collection_property(&self, key: String) -> Result<bytes> {
let key = <Vec<u8>>::from(key)
.try_into()
.map_err(|_| "key too large")?;
@@ -179,7 +179,7 @@
///
/// @param keys Properties keys. Empty keys for all propertyes.
/// @return Vector of properties key/value pairs.
- fn collection_properties(&self, keys: Vec<string>) -> Result<Vec<eth::Property>> {
+ fn collection_properties(&self, keys: Vec<String>) -> Result<Vec<eth::Property>> {
let keys = keys
.into_iter()
.map(|key| {
@@ -616,7 +616,7 @@
/// Returns collection type
///
/// @return `Fungible` or `NFT` or `ReFungible`
- fn unique_collection_type(&self) -> Result<string> {
+ fn unique_collection_type(&self) -> Result<String> {
let mode = match self.collection.mode {
CollectionMode::Fungible(_) => "Fungible",
CollectionMode::NFT => "NFT",
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -118,7 +118,7 @@
/// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
#[derive(Debug, Default, AbiCoder)]
pub struct Property {
- key: evm_coder::types::string,
+ key: evm_coder::types::String,
value: evm_coder::types::bytes,
}
@@ -126,7 +126,7 @@
type Error = evm_coder::execution::Error;
fn try_from(from: up_data_structs::Property) -> Result<Self, Self::Error> {
- let key = evm_coder::types::string::from_utf8(from.key.into())
+ let key = evm_coder::types::String::from_utf8(from.key.into())
.map_err(|e| Self::Error::Revert(format!("utf8 conversion error: {}", e)))?;
let value = evm_coder::types::bytes(from.value.to_vec());
Ok(Property { key, value })
@@ -342,7 +342,7 @@
#[derive(Debug, Default, AbiCoder)]
pub struct TokenPropertyPermission {
/// Token property key.
- key: evm_coder::types::string,
+ key: evm_coder::types::String,
/// Token property permissions.
permissions: Vec<PropertyPermission>,
}
@@ -360,7 +360,7 @@
),
) -> Self {
let (key, permission) = value;
- let key = evm_coder::types::string::from_utf8(key.into_inner())
+ let key = evm_coder::types::String::from_utf8(key.into_inner())
.expect("Stored key must be valid");
let permissions = PropertyPermission::into_vec(permission);
Self { key, permissions }
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -59,13 +59,13 @@
#[solidity_interface(name = ERC20, events(ERC20Events))]
impl<T: Config> FungibleHandle<T> {
- fn name(&self) -> Result<string> {
+ fn name(&self) -> Result<String> {
Ok(decode_utf16(self.name.iter().copied())
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
- .collect::<string>())
+ .collect::<String>())
}
- fn symbol(&self) -> Result<string> {
- Ok(string::from_utf8_lossy(&self.token_prefix).into())
+ fn symbol(&self) -> Result<String> {
+ Ok(String::from_utf8_lossy(&self.token_prefix).into())
}
fn total_supply(&self) -> Result<U256> {
self.consume_store_reads(1)?;
@@ -167,10 +167,10 @@
T::AccountId: From<[u8; 32]>,
{
/// @notice A description for the collection.
- fn description(&self) -> Result<string> {
+ fn description(&self) -> Result<String> {
Ok(decode_utf16(self.description.iter().copied())
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
- .collect::<string>())
+ .collect::<String>())
}
#[weight(<SelfWeightOf<T>>::create_item())]
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -64,7 +64,7 @@
fn set_token_property_permission(
&mut self,
caller: caller,
- key: string,
+ key: String,
is_mutable: bool,
collection_admin: bool,
token_owner: bool,
@@ -123,7 +123,7 @@
&mut self,
caller: caller,
token_id: U256,
- key: string,
+ key: String,
value: bytes,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -187,7 +187,7 @@
/// @param key Property key.
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::delete_token_properties(1))]
- fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {
+ fn delete_property(&mut self, token_id: U256, caller: caller, key: String) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
let key = <Vec<u8>>::from(key)
@@ -211,7 +211,7 @@
&mut self,
token_id: U256,
caller: caller,
- keys: Vec<string>,
+ keys: Vec<String>,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -239,7 +239,7 @@
/// @param tokenId ID of the token.
/// @param key Property key.
/// @return Property value bytes
- fn property(&self, token_id: U256, key: string) -> Result<bytes> {
+ fn property(&self, token_id: U256, key: String) -> Result<bytes> {
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
let key = <Vec<u8>>::from(key)
.try_into()
@@ -301,14 +301,14 @@
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev real implementation of this function lies in `ERC721UniqueExtensions`
#[solidity(hide, rename_selector = "name")]
- fn name_proxy(&self) -> Result<string> {
+ fn name_proxy(&self) -> Result<String> {
self.name()
}
/// @notice An abbreviated name for NFTs in this contract
/// @dev real implementation of this function lies in `ERC721UniqueExtensions`
#[solidity(hide, rename_selector = "symbol")]
- fn symbol_proxy(&self) -> Result<string> {
+ fn symbol_proxy(&self) -> Result<String> {
self.symbol()
}
@@ -322,7 +322,7 @@
///
/// @return token's const_metadata
#[solidity(rename_selector = "tokenURI")]
- fn token_uri(&self, token_id: U256) -> Result<string> {
+ fn token_uri(&self, token_id: U256) -> Result<String> {
let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
match get_token_property(self, token_id_u32, &key::url()).as_deref() {
@@ -335,7 +335,7 @@
let base_uri =
pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
.map(BoundedVec::into_inner)
- .map(string::from_utf8)
+ .map(String::from_utf8)
.transpose()
.map_err(|e| {
Error::Revert(alloc::format!(
@@ -595,7 +595,7 @@
&mut self,
caller: caller,
to: Address,
- token_uri: string,
+ token_uri: String,
) -> Result<U256> {
let token_id: U256 = <TokensMinted<T>>::get(self.id)
.checked_add(1)
@@ -618,7 +618,7 @@
caller: caller,
to: Address,
token_id: U256,
- token_uri: string,
+ token_uri: String,
) -> Result<bool> {
let key = key::url();
let permission = get_token_permission::<T>(self.id, &key)?;
@@ -670,12 +670,12 @@
collection: &CollectionHandle<T>,
token_id: u32,
key: &up_data_structs::PropertyKey,
-) -> Result<string> {
+) -> Result<String> {
collection.consume_store_reads(1)?;
let properties = <TokenProperties<T>>::try_get((collection.id, token_id))
.map_err(|_| Error::Revert("Token properties not found".into()))?;
if let Some(property) = properties.get(key) {
- return Ok(string::from_utf8_lossy(property).into());
+ return Ok(String::from_utf8_lossy(property).into());
}
Err("Property tokenURI not found".into())
@@ -691,7 +691,7 @@
.get(key)
.map(Clone::clone)
.ok_or_else(|| {
- let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();
+ let key = String::from_utf8(key.clone().into_inner()).unwrap_or_default();
Error::Revert(alloc::format!("No permission for key {}", key))
})?;
Ok(a)
@@ -704,22 +704,22 @@
T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,
{
/// @notice A descriptive name for a collection of NFTs in this contract
- fn name(&self) -> Result<string> {
+ fn name(&self) -> Result<String> {
Ok(decode_utf16(self.name.iter().copied())
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
- .collect::<string>())
+ .collect::<String>())
}
/// @notice An abbreviated name for NFTs in this contract
- fn symbol(&self) -> Result<string> {
- Ok(string::from_utf8_lossy(&self.token_prefix).into())
+ fn symbol(&self) -> Result<String> {
+ Ok(String::from_utf8_lossy(&self.token_prefix).into())
}
/// @notice A description for the collection.
- fn description(&self) -> Result<string> {
+ fn description(&self) -> Result<String> {
Ok(decode_utf16(self.description.iter().copied())
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
- .collect::<string>())
+ .collect::<String>())
}
/// Returns the owner (in cross format) of the token.
@@ -736,7 +736,7 @@
/// @param tokenId Id for the token.
/// @param keys Properties keys. Empty keys for all propertyes.
/// @return Vector of properties key/value pairs.
- fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
+ fn properties(&self, token_id: U256, keys: Vec<String>) -> Result<Vec<eth::Property>> {
let keys = keys
.into_iter()
.map(|key| {
@@ -948,7 +948,7 @@
&mut self,
caller: caller,
to: Address,
- tokens: Vec<(U256, string)>,
+ tokens: Vec<(U256, String)>,
) -> Result<bool> {
let key = key::url();
let caller = T::CrossAccountId::from_eth(caller);
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -67,7 +67,7 @@
fn set_token_property_permission(
&mut self,
caller: caller,
- key: string,
+ key: String,
is_mutable: bool,
collection_admin: bool,
token_owner: bool,
@@ -126,7 +126,7 @@
&mut self,
caller: caller,
token_id: U256,
- key: string,
+ key: String,
value: bytes,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -190,7 +190,7 @@
/// @param key Property key.
#[solidity(hide)]
#[weight(<SelfWeightOf<T>>::delete_token_properties(1))]
- fn delete_property(&mut self, token_id: U256, caller: caller, key: string) -> Result<()> {
+ fn delete_property(&mut self, token_id: U256, caller: caller, key: String) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
let key = <Vec<u8>>::from(key)
@@ -214,7 +214,7 @@
&mut self,
token_id: U256,
caller: caller,
- keys: Vec<string>,
+ keys: Vec<String>,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -242,7 +242,7 @@
/// @param tokenId ID of the token.
/// @param key Property key.
/// @return Property value bytes
- fn property(&self, token_id: U256, key: string) -> Result<bytes> {
+ fn property(&self, token_id: U256, key: String) -> Result<bytes> {
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
let key = <Vec<u8>>::from(key)
.try_into()
@@ -298,14 +298,14 @@
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev real implementation of this function lies in `ERC721UniqueExtensions`
#[solidity(hide, rename_selector = "name")]
- fn name_proxy(&self) -> Result<string> {
+ fn name_proxy(&self) -> Result<String> {
self.name()
}
/// @notice An abbreviated name for NFTs in this contract
/// @dev real implementation of this function lies in `ERC721UniqueExtensions`
#[solidity(hide, rename_selector = "symbol")]
- fn symbol_proxy(&self) -> Result<string> {
+ fn symbol_proxy(&self) -> Result<String> {
self.symbol()
}
@@ -319,7 +319,7 @@
///
/// @return token's const_metadata
#[solidity(rename_selector = "tokenURI")]
- fn token_uri(&self, token_id: U256) -> Result<string> {
+ fn token_uri(&self, token_id: U256) -> Result<String> {
let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
match get_token_property(self, token_id_u32, &key::url()).as_deref() {
@@ -332,7 +332,7 @@
let base_uri =
pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
.map(BoundedVec::into_inner)
- .map(string::from_utf8)
+ .map(String::from_utf8)
.transpose()
.map_err(|e| {
Error::Revert(alloc::format!(
@@ -631,7 +631,7 @@
&mut self,
caller: caller,
to: Address,
- token_uri: string,
+ token_uri: String,
) -> Result<U256> {
let token_id: U256 = <TokensMinted<T>>::get(self.id)
.checked_add(1)
@@ -654,7 +654,7 @@
caller: caller,
to: Address,
token_id: U256,
- token_uri: string,
+ token_uri: String,
) -> Result<bool> {
let key = key::url();
let permission = get_token_permission::<T>(self.id, &key)?;
@@ -708,12 +708,12 @@
collection: &CollectionHandle<T>,
token_id: u32,
key: &up_data_structs::PropertyKey,
-) -> Result<string> {
+) -> Result<String> {
collection.consume_store_reads(1)?;
let properties = <TokenProperties<T>>::try_get((collection.id, token_id))
.map_err(|_| Error::Revert("Token properties not found".into()))?;
if let Some(property) = properties.get(key) {
- return Ok(string::from_utf8_lossy(property).into());
+ return Ok(String::from_utf8_lossy(property).into());
}
Err("Property tokenURI not found".into())
@@ -729,7 +729,7 @@
.get(key)
.map(Clone::clone)
.ok_or_else(|| {
- let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();
+ let key = String::from_utf8(key.clone().into_inner()).unwrap_or_default();
Error::Revert(alloc::format!("No permission for key {}", key))
})?;
Ok(a)
@@ -742,22 +742,22 @@
T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,
{
/// @notice A descriptive name for a collection of NFTs in this contract
- fn name(&self) -> Result<string> {
+ fn name(&self) -> Result<String> {
Ok(decode_utf16(self.name.iter().copied())
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
- .collect::<string>())
+ .collect::<String>())
}
/// @notice An abbreviated name for NFTs in this contract
- fn symbol(&self) -> Result<string> {
- Ok(string::from_utf8_lossy(&self.token_prefix).into())
+ fn symbol(&self) -> Result<String> {
+ Ok(String::from_utf8_lossy(&self.token_prefix).into())
}
/// @notice A description for the collection.
- fn description(&self) -> Result<string> {
+ fn description(&self) -> Result<String> {
Ok(decode_utf16(self.description.iter().copied())
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
- .collect::<string>())
+ .collect::<String>())
}
/// Returns the owner (in cross format) of the token.
@@ -774,7 +774,7 @@
/// @param tokenId Id for the token.
/// @param keys Properties keys. Empty keys for all propertyes.
/// @return Vector of properties key/value pairs.
- fn properties(&self, token_id: U256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
+ fn properties(&self, token_id: U256, keys: Vec<String>) -> Result<Vec<eth::Property>> {
let keys = keys
.into_iter()
.map(|key| {
@@ -991,7 +991,7 @@
&mut self,
caller: caller,
to: Address,
- tokens: Vec<(U256, string)>,
+ tokens: Vec<(U256, String)>,
) -> Result<bool> {
let key = key::url();
let caller = T::CrossAccountId::from_eth(caller);
pallets/refungible/src/erc_token.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Refungible Pallet EVM API for token pieces18//!19//! Provides ERC-20 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122use core::{23 char::{REPLACEMENT_CHARACTER, decode_utf16},24 convert::TryInto,25 ops::Deref,26};27use evm_coder::{28 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity_interface, solidity, types::*,29 weight,30};31use pallet_common::{32 CommonWeightInfo,33 erc::{CommonEvmHandler, PrecompileResult},34 eth::collection_id_to_address,35};36use pallet_evm::{account::CrossAccountId, PrecompileHandle};37use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};38use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};39use sp_std::vec::Vec;40use sp_core::U256;41use up_data_structs::TokenId;4243use crate::{44 Allowance, Balance, common::CommonWeights, Config, Pallet, RefungibleHandle, SelfWeightOf,45 TotalSupply, weights::WeightInfo,46};4748/// Refungible token handle contains information about token's collection and id49///50/// RefungibleTokenHandle doesn't check token's existance upon creation51pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);5253#[solidity_interface(name = ERC1633)]54impl<T: Config> RefungibleTokenHandle<T> {55 fn parent_token(&self) -> Result<Address> {56 Ok(collection_id_to_address(self.id))57 }5859 fn parent_token_id(&self) -> Result<U256> {60 Ok(self.1.into())61 }62}6364#[derive(ToLog)]65pub enum ERC20Events {66 /// @dev This event is emitted when the amount of tokens (value) is sent67 /// from the from address to the to address. In the case of minting new68 /// tokens, the transfer is usually from the 0 address while in the case69 /// of burning tokens the transfer is to 0.70 Transfer {71 #[indexed]72 from: Address,73 #[indexed]74 to: Address,75 value: U256,76 },77 /// @dev This event is emitted when the amount of tokens (value) is approved78 /// by the owner to be used by the spender.79 Approval {80 #[indexed]81 owner: Address,82 #[indexed]83 spender: Address,84 value: U256,85 },86}8788/// @title Standard ERC20 token89///90/// @dev Implementation of the basic standard token.91/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md92#[solidity_interface(name = ERC20, events(ERC20Events))]93impl<T: Config> RefungibleTokenHandle<T> {94 /// @return the name of the token.95 fn name(&self) -> Result<string> {96 Ok(decode_utf16(self.name.iter().copied())97 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))98 .collect::<string>())99 }100101 /// @return the symbol of the token.102 fn symbol(&self) -> Result<string> {103 Ok(string::from_utf8_lossy(&self.token_prefix).into())104 }105106 /// @dev Total number of tokens in existence107 fn total_supply(&self) -> Result<U256> {108 self.consume_store_reads(1)?;109 Ok(<TotalSupply<T>>::get((self.id, self.1)).into())110 }111112 /// @dev Not supported113 fn decimals(&self) -> Result<u8> {114 // Decimals aren't supported for refungible tokens115 Ok(0)116 }117118 /// @dev Gets the balance of the specified address.119 /// @param owner The address to query the balance of.120 /// @return An uint256 representing the amount owned by the passed address.121 fn balance_of(&self, owner: Address) -> Result<U256> {122 self.consume_store_reads(1)?;123 let owner = T::CrossAccountId::from_eth(owner);124 let balance = <Balance<T>>::get((self.id, self.1, owner));125 Ok(balance.into())126 }127128 /// @dev Transfer token for a specified address129 /// @param to The address to transfer to.130 /// @param amount The amount to be transferred.131 #[weight(<CommonWeights<T>>::transfer())]132 fn transfer(&mut self, caller: caller, to: Address, amount: U256) -> Result<bool> {133 let caller = T::CrossAccountId::from_eth(caller);134 let to = T::CrossAccountId::from_eth(to);135 let amount = amount.try_into().map_err(|_| "amount overflow")?;136 let budget = self137 .recorder138 .weight_calls_budget(<StructureWeight<T>>::find_parent());139140 <Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)141 .map_err(dispatch_to_evm::<T>)?;142 Ok(true)143 }144145 /// @dev Transfer tokens from one address to another146 /// @param from address The address which you want to send tokens from147 /// @param to address The address which you want to transfer to148 /// @param amount uint256 the amount of tokens to be transferred149 #[weight(<CommonWeights<T>>::transfer_from())]150 fn transfer_from(151 &mut self,152 caller: caller,153 from: Address,154 to: Address,155 amount: U256,156 ) -> Result<bool> {157 let caller = T::CrossAccountId::from_eth(caller);158 let from = T::CrossAccountId::from_eth(from);159 let to = T::CrossAccountId::from_eth(to);160 let amount = amount.try_into().map_err(|_| "amount overflow")?;161 let budget = self162 .recorder163 .weight_calls_budget(<StructureWeight<T>>::find_parent());164165 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)166 .map_err(dispatch_to_evm::<T>)?;167 Ok(true)168 }169170 /// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.171 /// Beware that changing an allowance with this method brings the risk that someone may use both the old172 /// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this173 /// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:174 /// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729175 /// @param spender The address which will spend the funds.176 /// @param amount The amount of tokens to be spent.177 #[weight(<SelfWeightOf<T>>::approve())]178 fn approve(&mut self, caller: caller, spender: Address, amount: U256) -> Result<bool> {179 let caller = T::CrossAccountId::from_eth(caller);180 let spender = T::CrossAccountId::from_eth(spender);181 let amount = amount.try_into().map_err(|_| "amount overflow")?;182183 <Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)184 .map_err(dispatch_to_evm::<T>)?;185 Ok(true)186 }187188 /// @dev Function to check the amount of tokens that an owner allowed to a spender.189 /// @param owner address The address which owns the funds.190 /// @param spender address The address which will spend the funds.191 /// @return A uint256 specifying the amount of tokens still available for the spender.192 fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {193 self.consume_store_reads(1)?;194 let owner = T::CrossAccountId::from_eth(owner);195 let spender = T::CrossAccountId::from_eth(spender);196197 Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())198 }199}200201#[solidity_interface(name = ERC20UniqueExtensions)]202impl<T: Config> RefungibleTokenHandle<T>203where204 T::AccountId: From<[u8; 32]>,205{206 /// @dev Function that burns an amount of the token of a given account,207 /// deducting from the sender's allowance for said account.208 /// @param from The account whose tokens will be burnt.209 /// @param amount The amount that will be burnt.210 #[weight(<SelfWeightOf<T>>::burn_from())]211 #[solidity(hide)]212 fn burn_from(&mut self, caller: caller, from: Address, amount: U256) -> Result<bool> {213 let caller = T::CrossAccountId::from_eth(caller);214 let from = T::CrossAccountId::from_eth(from);215 let amount = amount.try_into().map_err(|_| "amount overflow")?;216 let budget = self217 .recorder218 .weight_calls_budget(<StructureWeight<T>>::find_parent());219220 <Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)221 .map_err(dispatch_to_evm::<T>)?;222 Ok(true)223 }224225 /// @dev Function that burns an amount of the token of a given account,226 /// deducting from the sender's allowance for said account.227 /// @param from The account whose tokens will be burnt.228 /// @param amount The amount that will be burnt.229 #[weight(<SelfWeightOf<T>>::burn_from())]230 fn burn_from_cross(231 &mut self,232 caller: caller,233 from: pallet_common::eth::CrossAddress,234 amount: U256,235 ) -> Result<bool> {236 let caller = T::CrossAccountId::from_eth(caller);237 let from = from.into_sub_cross_account::<T>()?;238 let amount = amount.try_into().map_err(|_| "amount overflow")?;239 let budget = self240 .recorder241 .weight_calls_budget(<StructureWeight<T>>::find_parent());242243 <Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)244 .map_err(dispatch_to_evm::<T>)?;245 Ok(true)246 }247248 /// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.249 /// Beware that changing an allowance with this method brings the risk that someone may use both the old250 /// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this251 /// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:252 /// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729253 /// @param spender The crossaccount which will spend the funds.254 /// @param amount The amount of tokens to be spent.255 #[weight(<SelfWeightOf<T>>::approve())]256 fn approve_cross(257 &mut self,258 caller: caller,259 spender: pallet_common::eth::CrossAddress,260 amount: U256,261 ) -> Result<bool> {262 let caller = T::CrossAccountId::from_eth(caller);263 let spender = spender.into_sub_cross_account::<T>()?;264 let amount = amount.try_into().map_err(|_| "amount overflow")?;265266 <Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)267 .map_err(dispatch_to_evm::<T>)?;268 Ok(true)269 }270 /// @dev Function that changes total amount of the tokens.271 /// Throws if `msg.sender` doesn't owns all of the tokens.272 /// @param amount New total amount of the tokens.273 #[weight(<SelfWeightOf<T>>::repartition_item())]274 fn repartition(&mut self, caller: caller, amount: U256) -> Result<bool> {275 let caller = T::CrossAccountId::from_eth(caller);276 let amount = amount.try_into().map_err(|_| "amount overflow")?;277278 <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;279 Ok(true)280 }281282 /// @dev Transfer token for a specified address283 /// @param to The crossaccount to transfer to.284 /// @param amount The amount to be transferred.285 #[weight(<CommonWeights<T>>::transfer())]286 fn transfer_cross(287 &mut self,288 caller: caller,289 to: pallet_common::eth::CrossAddress,290 amount: U256,291 ) -> Result<bool> {292 let caller = T::CrossAccountId::from_eth(caller);293 let to = to.into_sub_cross_account::<T>()?;294 let amount = amount.try_into().map_err(|_| "amount overflow")?;295 let budget = self296 .recorder297 .weight_calls_budget(<StructureWeight<T>>::find_parent());298299 <Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)300 .map_err(dispatch_to_evm::<T>)?;301 Ok(true)302 }303304 /// @dev Transfer tokens from one address to another305 /// @param from The address which you want to send tokens from306 /// @param to The address which you want to transfer to307 /// @param amount the amount of tokens to be transferred308 #[weight(<CommonWeights<T>>::transfer_from())]309 fn transfer_from_cross(310 &mut self,311 caller: caller,312 from: pallet_common::eth::CrossAddress,313 to: pallet_common::eth::CrossAddress,314 amount: U256,315 ) -> Result<bool> {316 let caller = T::CrossAccountId::from_eth(caller);317 let from = from.into_sub_cross_account::<T>()?;318 let to = to.into_sub_cross_account::<T>()?;319 let amount = amount.try_into().map_err(|_| "amount overflow")?;320 let budget = self321 .recorder322 .weight_calls_budget(<StructureWeight<T>>::find_parent());323324 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)325 .map_err(dispatch_to_evm::<T>)?;326 Ok(true)327 }328}329330impl<T: Config> RefungibleTokenHandle<T> {331 pub fn into_inner(self) -> RefungibleHandle<T> {332 self.0333 }334 pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {335 &mut self.0336 }337}338339impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {340 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {341 self.0.recorder()342 }343 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {344 self.0.into_recorder()345 }346}347348impl<T: Config> Deref for RefungibleTokenHandle<T> {349 type Target = RefungibleHandle<T>;350351 fn deref(&self) -> &Self::Target {352 &self.0353 }354}355356#[solidity_interface(357 name = UniqueRefungibleToken,358 is(ERC20, ERC20UniqueExtensions, ERC1633)359)]360impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}361362generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);363generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);364365impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>366where367 T::AccountId: From<[u8; 32]>,368{369 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");370371 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {372 call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)373 }374}pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -57,9 +57,9 @@
fn convert_data<T: Config>(
caller: caller,
- name: string,
- description: string,
- token_prefix: string,
+ name: String,
+ description: String,
+ token_prefix: String,
) -> Result<(
T::CrossAccountId,
CollectionName,
@@ -89,10 +89,10 @@
fn create_collection_internal<T: Config>(
caller: caller,
value: value,
- name: string,
+ name: String,
collection_mode: CollectionMode,
- description: string,
- token_prefix: string,
+ description: String,
+ token_prefix: String,
) -> Result<Address> {
let (caller, name, description, token_prefix) =
convert_data::<T>(caller, name, description, token_prefix)?;
@@ -151,9 +151,9 @@
&mut self,
caller: caller,
value: value,
- name: string,
- description: string,
- token_prefix: string,
+ name: String,
+ description: String,
+ token_prefix: String,
) -> Result<Address> {
let (caller, name, description, token_prefix) =
convert_data::<T>(caller, name, description, token_prefix)?;
@@ -190,9 +190,9 @@
&mut self,
caller: caller,
value: value,
- name: string,
- description: string,
- token_prefix: string,
+ name: String,
+ description: String,
+ token_prefix: String,
) -> Result<Address> {
create_collection_internal::<T>(
caller,
@@ -210,9 +210,9 @@
&mut self,
caller: caller,
value: value,
- name: string,
- description: string,
- token_prefix: string,
+ name: String,
+ description: String,
+ token_prefix: String,
) -> Result<Address> {
create_collection_internal::<T>(
caller,
@@ -230,10 +230,10 @@
&mut self,
caller: caller,
value: value,
- name: string,
+ name: String,
decimals: u8,
- description: string,
- token_prefix: string,
+ description: String,
+ token_prefix: String,
) -> Result<Address> {
create_collection_internal::<T>(
caller,
@@ -250,7 +250,7 @@
&mut self,
caller: caller,
collection: Address,
- base_uri: string,
+ base_uri: String,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let collection =
runtime/tests/src/tests.rsdiffbeforeafterboth--- a/runtime/tests/src/tests.rs
+++ b/runtime/tests/src/tests.rs
@@ -323,7 +323,7 @@
.map(|d| { d.into() })
.collect()
));
- for (index, data) in items_data.into_iter().enumerate() {
+ for (index, _data) in items_data.into_iter().enumerate() {
let balance = <pallet_refungible::Balance<Test>>::get((
CollectionId(1),
TokenId((index + 1) as u32),