difftreelog
CORE-302 Refactor collection for eth
in: master
20 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5467,9 +5467,9 @@
[[package]]
name = "once_cell"
-version = "1.11.0"
+version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b10983b38c53aebdf33f542c6275b0f58a238129d00c4ae0e6fb59738d783ca"
+checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]]
name = "opal-runtime"
@@ -6830,7 +6830,6 @@
"parity-scale-codec 3.1.2",
"scale-info",
"serde",
- "serde-json-core",
"sp-core",
"sp-io",
"sp-runtime",
@@ -10735,16 +10734,6 @@
]
[[package]]
-name = "serde-json-core"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8014aeea272bca0f0779778d43253f2f3375b414185b30e6ecc4d3e4a9994781"
-dependencies = [
- "ryu",
- "serde",
-]
-
-[[package]]
name = "serde_derive"
version = "1.0.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -12025,9 +12014,9 @@
[[package]]
name = "target-lexicon"
-version = "0.12.3"
+version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7fa7e55043acb85fca6b3c01485a2eeb6b69c5d21002e273c79e465f43b7ac1"
+checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1"
[[package]]
name = "tempfile"
Makefilediffbeforeafterboth--- a/Makefile
+++ b/Makefile
@@ -15,16 +15,13 @@
CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/
CONTRACT_HELPERS_ABI=./tests/src/eth/util/contractHelpersAbi.json
-COLLECTION_STUBS=./pallets/unique/src/eth/stubs/
-COLLECTION_ABI=./tests/src/eth/collectionAbi.json
-
COLLECTION_HELPER_STUBS=$(COLLECTION_STUBS)
COLLECTION_HELPER_ABI=./tests/src/eth/collectionHelperAbi.json
TESTS_API=./tests/src/eth/api/
.PHONY: regenerate_solidity
-regenerate_solidity: UniqueFungible.sol UniqueNFT.sol ContractHelpers.sol Collection.sol CollectionHelper.sol
+regenerate_solidity: UniqueFungible.sol UniqueNFT.sol ContractHelpers.sol CollectionHelper.sol
UniqueFungible.sol:
PACKAGE=pallet-fungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
@@ -38,10 +35,6 @@
PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_impl OUTPUT=$(CONTRACT_HELPERS_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
-Collection.sol:
- PACKAGE=pallet-unique NAME=eth::evm_collection::collection_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
- PACKAGE=pallet-unique NAME=eth::evm_collection::collection_impl OUTPUT=$(COLLECTION_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
-
CollectionHelper.sol:
PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_impl OUTPUT=$(COLLECTION_HELPER_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
@@ -58,15 +51,11 @@
INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw ./.maintain/scripts/compile_stub.sh
INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_ABI) ./.maintain/scripts/generate_abi.sh
-Collection: Collection.sol
- INPUT=$(COLLECTION_STUBS)/$< OUTPUT=$(COLLECTION_STUBS)/Collection.raw ./.maintain/scripts/compile_stub.sh
- INPUT=$(COLLECTION_STUBS)/$< OUTPUT=$(COLLECTION_ABI) ./.maintain/scripts/generate_abi.sh
-
CollectionHelper: CollectionHelper.sol
INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_STUBS)/CollectionHelper.raw ./.maintain/scripts/compile_stub.sh
INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_ABI) ./.maintain/scripts/generate_abi.sh
-evm_stubs: UniqueFungible UniqueNFT ContractHelpers Collection CollectionHelper
+evm_stubs: UniqueFungible UniqueNFT ContractHelpers CollectionHelper
.PHONY: _bench
_bench:
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use evm_coder::{solidity_interface, types::*, execution::Result};
+use evm_coder::{solidity_interface, types::*, execution::{Result, Error}};
pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};
-use pallet_evm_coder_substrate::dispatch_to_evm;
+use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder};
use sp_core::{H160, U256};
use sp_std::vec::Vec;
use up_data_structs::Property;
@@ -31,7 +31,7 @@
fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult>;
}
-#[solidity_interface(name = "CollectionProperties")]
+#[solidity_interface(name = "Collection")]
impl<T: Config> CollectionHandle<T> {
fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -64,4 +64,70 @@
Ok(prop.to_vec())
}
+
+ fn eth_set_sponsor(
+ &mut self,
+ caller: caller,
+ sponsor: address,
+ ) -> Result<void> {
+ check_is_owner(caller, self)?;
+
+ let sponsor = T::CrossAccountId::from_eth(sponsor);
+ self.set_sponsor(sponsor.as_sub().clone());
+ save(self);
+ Ok(())
+ }
+
+ fn eth_confirm_sponsorship(&mut self, caller: caller) -> Result<void> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ if !self.confirm_sponsorship(caller.as_sub()) {
+ return Err(Error::Revert("Caller is not set as sponsor".into()));
+ }
+ save(self);
+ Ok(())
+ }
+
+ fn set_limits(
+ &self,
+ caller: caller,
+ limits_json: string,
+ ) -> Result<void> {
+ // let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
+ // check_is_owner(caller, &collection)?;
+
+ // let limits = serde_json_core::from_str(limits_json.as_ref())
+ // .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
+ // collection.limits = limits.0;
+ // collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+ Ok(())
+ }
+
+ fn contract_address(&self, _caller: caller) -> Result<address> {
+ Ok(crate::eth::collection_id_to_address(self.id))
+ }
+}
+
+fn collection_from_address<T: Config>(
+ collection_address: address,
+ gas_limit: u64
+) -> Result<CollectionHandle<T>> {
+ let collection_id = crate::eth::map_eth_to_id(&collection_address)
+ .ok_or(Error::Revert("Contract is not an unique collection".into()))?;
+ let recorder = <SubstrateRecorder<T>>::new(gas_limit);
+ let collection =
+ CollectionHandle::new_with_recorder(collection_id, recorder)
+ .ok_or(Error::Revert("Create collection handle error".into()))?;
+ Ok(collection)
+}
+
+fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ collection
+ .check_is_owner(&caller)
+ .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+ Ok(())
}
+
+fn save<T: Config>(collection: &CollectionHandle<T>) {
+ <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
+}
\ No newline at end of file
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -20,7 +20,7 @@
use core::ops::{Deref, DerefMut};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_std::{vec::Vec, rc::Rc};
+use sp_std::vec::Vec;
use pallet_evm::account::CrossAccountId;
use frame_support::{
dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -24,7 +24,7 @@
use pallet_evm::account::CrossAccountId;
use pallet_evm_coder_substrate::{call, dispatch_to_evm};
use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use pallet_common::{CollectionHandle, erc::CollectionPropertiesCall};
+use pallet_common::{CollectionHandle, erc::CollectionCall};
use crate::{
Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,
@@ -150,7 +150,7 @@
is(
ERC20,
ERC20UniqueExtensions,
- via("CollectionHandle<T>", common_mut, CollectionProperties)
+ via("CollectionHandle<T>", common_mut, Collection)
)
)]
impl<T: Config> FungibleHandle<T> {}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -26,7 +26,7 @@
use sp_core::{H160, U256};
use sp_std::vec::Vec;
use pallet_common::{
- erc::{CommonEvmHandler, PrecompileResult, CollectionPropertiesCall},
+ erc::{CommonEvmHandler, PrecompileResult, CollectionCall},
CollectionHandle,
};
use pallet_evm::account::CrossAccountId;
@@ -513,7 +513,7 @@
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
- via("CollectionHandle<T>", common_mut, CollectionProperties),
+ via("CollectionHandle<T>", common_mut, Collection),
TokenProperties,
)
)]
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8 uint256 field_0;9 string field_1;10}1112// Common stubs holder13contract Dummy {14 uint8 dummy;15 string stub_error = "this contract is implemented in native";16}1718contract ERC165 is Dummy {19 function supportsInterface(bytes4 interfaceID)20 external21 view22 returns (bool)23 {24 require(false, stub_error);25 interfaceID;26 return true;27 }28}2930// Inline31contract ERC721Events {32 event Transfer(33 address indexed from,34 address indexed to,35 uint256 indexed tokenId36 );37 event Approval(38 address indexed owner,39 address indexed approved,40 uint256 indexed tokenId41 );42 event ApprovalForAll(43 address indexed owner,44 address indexed operator,45 bool approved46 );47}4849// Inline50contract ERC721MintableEvents {51 event MintingFinished();52}5354// Selector: 4136937755contract TokenProperties is Dummy, ERC165 {56 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa57 function setTokenPropertyPermission(58 string memory key,59 bool isMutable,60 bool collectionAdmin,61 bool tokenOwner62 ) public {63 require(false, stub_error);64 key;65 isMutable;66 collectionAdmin;67 tokenOwner;68 dummy = 0;69 }7071 // Selector: setProperty(uint256,string,bytes) 1752d67b72 function setProperty(73 uint256 tokenId,74 string memory key,75 bytes memory value76 ) public {77 require(false, stub_error);78 tokenId;79 key;80 value;81 dummy = 0;82 }8384 // Selector: deleteProperty(uint256,string) 066111d185 function deleteProperty(uint256 tokenId, string memory key) public {86 require(false, stub_error);87 tokenId;88 key;89 dummy = 0;90 }9192 // Throws error if key not found93 //94 // Selector: property(uint256,string) 7228c32795 function property(uint256 tokenId, string memory key)96 public97 view98 returns (bytes memory)99 {100 require(false, stub_error);101 tokenId;102 key;103 dummy;104 return hex"";105 }106}107108// Selector: 42966c68109contract ERC721Burnable is Dummy, ERC165 {110 // Selector: burn(uint256) 42966c68111 function burn(uint256 tokenId) public {112 require(false, stub_error);113 tokenId;114 dummy = 0;115 }116}117118// Selector: 58800161119contract ERC721 is Dummy, ERC165, ERC721Events {120 // Selector: balanceOf(address) 70a08231121 function balanceOf(address owner) public view returns (uint256) {122 require(false, stub_error);123 owner;124 dummy;125 return 0;126 }127128 // Selector: ownerOf(uint256) 6352211e129 function ownerOf(uint256 tokenId) public view returns (address) {130 require(false, stub_error);131 tokenId;132 dummy;133 return 0x0000000000000000000000000000000000000000;134 }135136 // Not implemented137 //138 // Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672139 function safeTransferFromWithData(140 address from,141 address to,142 uint256 tokenId,143 bytes memory data144 ) public {145 require(false, stub_error);146 from;147 to;148 tokenId;149 data;150 dummy = 0;151 }152153 // Not implemented154 //155 // Selector: safeTransferFrom(address,address,uint256) 42842e0e156 function safeTransferFrom(157 address from,158 address to,159 uint256 tokenId160 ) public {161 require(false, stub_error);162 from;163 to;164 tokenId;165 dummy = 0;166 }167168 // Selector: transferFrom(address,address,uint256) 23b872dd169 function transferFrom(170 address from,171 address to,172 uint256 tokenId173 ) public {174 require(false, stub_error);175 from;176 to;177 tokenId;178 dummy = 0;179 }180181 // Selector: approve(address,uint256) 095ea7b3182 function approve(address approved, uint256 tokenId) public {183 require(false, stub_error);184 approved;185 tokenId;186 dummy = 0;187 }188189 // Not implemented190 //191 // Selector: setApprovalForAll(address,bool) a22cb465192 function setApprovalForAll(address operator, bool approved) public {193 require(false, stub_error);194 operator;195 approved;196 dummy = 0;197 }198199 // Not implemented200 //201 // Selector: getApproved(uint256) 081812fc202 function getApproved(uint256 tokenId) public view returns (address) {203 require(false, stub_error);204 tokenId;205 dummy;206 return 0x0000000000000000000000000000000000000000;207 }208209 // Not implemented210 //211 // Selector: isApprovedForAll(address,address) e985e9c5212 function isApprovedForAll(address owner, address operator)213 public214 view215 returns (address)216 {217 require(false, stub_error);218 owner;219 operator;220 dummy;221 return 0x0000000000000000000000000000000000000000;222 }223}224225// Selector: 5b5e139f226contract ERC721Metadata is Dummy, ERC165 {227 // Selector: name() 06fdde03228 function name() public view returns (string memory) {229 require(false, stub_error);230 dummy;231 return "";232 }233234 // Selector: symbol() 95d89b41235 function symbol() public view returns (string memory) {236 require(false, stub_error);237 dummy;238 return "";239 }240241 // Returns token's const_metadata242 //243 // Selector: tokenURI(uint256) c87b56dd244 function tokenURI(uint256 tokenId) public view returns (string memory) {245 require(false, stub_error);246 tokenId;247 dummy;248 return "";249 }250}251252// Selector: 68ccfe89253contract ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {254 // Selector: mintingFinished() 05d2035b255 function mintingFinished() public view returns (bool) {256 require(false, stub_error);257 dummy;258 return false;259 }260261 // `token_id` should be obtained with `next_token_id` method,262 // unlike standard, you can't specify it manually263 //264 // Selector: mint(address,uint256) 40c10f19265 function mint(address to, uint256 tokenId) public returns (bool) {266 require(false, stub_error);267 to;268 tokenId;269 dummy = 0;270 return false;271 }272273 // `token_id` should be obtained with `next_token_id` method,274 // unlike standard, you can't specify it manually275 //276 // Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f277 function mintWithTokenURI(278 address to,279 uint256 tokenId,280 string memory tokenUri281 ) public returns (bool) {282 require(false, stub_error);283 to;284 tokenId;285 tokenUri;286 dummy = 0;287 return false;288 }289290 // Not implemented291 //292 // Selector: finishMinting() 7d64bcb4293 function finishMinting() public returns (bool) {294 require(false, stub_error);295 dummy = 0;296 return false;297 }298}299300// Selector: 780e9d63301contract ERC721Enumerable is Dummy, ERC165 {302 // Selector: tokenByIndex(uint256) 4f6ccce7303 function tokenByIndex(uint256 index) public view returns (uint256) {304 require(false, stub_error);305 index;306 dummy;307 return 0;308 }309310 // Not implemented311 //312 // Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59313 function tokenOfOwnerByIndex(address owner, uint256 index)314 public315 view316 returns (uint256)317 {318 require(false, stub_error);319 owner;320 index;321 dummy;322 return 0;323 }324325 // Selector: totalSupply() 18160ddd326 function totalSupply() public view returns (uint256) {327 require(false, stub_error);328 dummy;329 return 0;330 }331}332333// Selector: 9b5e29c5334contract CollectionProperties is Dummy, ERC165 {335 // Selector: setCollectionProperty(string,bytes) 2f073f66336 function setCollectionProperty(string memory key, bytes memory value)337 public338 {339 require(false, stub_error);340 key;341 value;342 dummy = 0;343 }344345 // Selector: deleteCollectionProperty(string) 7b7debce346 function deleteCollectionProperty(string memory key) public {347 require(false, stub_error);348 key;349 dummy = 0;350 }351352 // Throws error if key not found353 //354 // Selector: collectionProperty(string) cf24fd6d355 function collectionProperty(string memory key)356 public357 view358 returns (bytes memory)359 {360 require(false, stub_error);361 key;362 dummy;363 return hex"";364 }365}366367// Selector: d74d154f368contract ERC721UniqueExtensions is Dummy, ERC165 {369 // Selector: transfer(address,uint256) a9059cbb370 function transfer(address to, uint256 tokenId) public {371 require(false, stub_error);372 to;373 tokenId;374 dummy = 0;375 }376377 // Selector: burnFrom(address,uint256) 79cc6790378 function burnFrom(address from, uint256 tokenId) public {379 require(false, stub_error);380 from;381 tokenId;382 dummy = 0;383 }384385 // Selector: nextTokenId() 75794a3c386 function nextTokenId() public view returns (uint256) {387 require(false, stub_error);388 dummy;389 return 0;390 }391392 // Selector: mintBulk(address,uint256[]) 44a9945e393 function mintBulk(address to, uint256[] memory tokenIds)394 public395 returns (bool)396 {397 require(false, stub_error);398 to;399 tokenIds;400 dummy = 0;401 return false;402 }403404 // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006405 function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)406 public407 returns (bool)408 {409 require(false, stub_error);410 to;411 tokens;412 dummy = 0;413 return false;414 }415}416417contract UniqueNFT is418 Dummy,419 ERC165,420 ERC721,421 ERC721Metadata,422 ERC721Enumerable,423 ERC721UniqueExtensions,424 ERC721Mintable,425 ERC721Burnable,426 CollectionProperties,427 TokenProperties428{}1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56// Anonymous struct7struct Tuple0 {8 uint256 field_0;9 string field_1;10}1112// Common stubs holder13contract Dummy {14 uint8 dummy;15 string stub_error = "this contract is implemented in native";16}1718contract ERC165 is Dummy {19 function supportsInterface(bytes4 interfaceID)20 external21 view22 returns (bool)23 {24 require(false, stub_error);25 interfaceID;26 return true;27 }28}2930// Inline31contract ERC721Events {32 event Transfer(33 address indexed from,34 address indexed to,35 uint256 indexed tokenId36 );37 event Approval(38 address indexed owner,39 address indexed approved,40 uint256 indexed tokenId41 );42 event ApprovalForAll(43 address indexed owner,44 address indexed operator,45 bool approved46 );47}4849// Inline50contract ERC721MintableEvents {51 event MintingFinished();52}5354// Selector: 38e33c6055contract Collection is Dummy, ERC165 {56 // Selector: setCollectionProperty(string,bytes) 2f073f6657 function setCollectionProperty(string memory key, bytes memory value)58 public59 {60 require(false, stub_error);61 key;62 value;63 dummy = 0;64 }6566 // Selector: deleteCollectionProperty(string) 7b7debce67 function deleteCollectionProperty(string memory key) public {68 require(false, stub_error);69 key;70 dummy = 0;71 }7273 // Throws error if key not found74 //75 // Selector: collectionProperty(string) cf24fd6d76 function collectionProperty(string memory key)77 public78 view79 returns (bytes memory)80 {81 require(false, stub_error);82 key;83 dummy;84 return hex"";85 }8687 // Selector: ethSetSponsor(address) 8f9af35688 function ethSetSponsor(address sponsor) public {89 require(false, stub_error);90 sponsor;91 dummy = 0;92 }9394 // Selector: ethConfirmSponsorship() a8580d1a95 function ethConfirmSponsorship() public {96 require(false, stub_error);97 dummy = 0;98 }99100 // Selector: setLimits(string) 72cb345d101 function setLimits(string memory limitsJson) public view {102 require(false, stub_error);103 limitsJson;104 dummy;105 }106107 // Selector: contractAddress() f6b4dfb4108 function contractAddress() public view returns (address) {109 require(false, stub_error);110 dummy;111 return 0x0000000000000000000000000000000000000000;112 }113}114115// Selector: 41369377116contract TokenProperties is Dummy, ERC165 {117 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa118 function setTokenPropertyPermission(119 string memory key,120 bool isMutable,121 bool collectionAdmin,122 bool tokenOwner123 ) public {124 require(false, stub_error);125 key;126 isMutable;127 collectionAdmin;128 tokenOwner;129 dummy = 0;130 }131132 // Selector: setProperty(uint256,string,bytes) 1752d67b133 function setProperty(134 uint256 tokenId,135 string memory key,136 bytes memory value137 ) public {138 require(false, stub_error);139 tokenId;140 key;141 value;142 dummy = 0;143 }144145 // Selector: deleteProperty(uint256,string) 066111d1146 function deleteProperty(uint256 tokenId, string memory key) public {147 require(false, stub_error);148 tokenId;149 key;150 dummy = 0;151 }152153 // Throws error if key not found154 //155 // Selector: property(uint256,string) 7228c327156 function property(uint256 tokenId, string memory key)157 public158 view159 returns (bytes memory)160 {161 require(false, stub_error);162 tokenId;163 key;164 dummy;165 return hex"";166 }167}168169// Selector: 42966c68170contract ERC721Burnable is Dummy, ERC165 {171 // Selector: burn(uint256) 42966c68172 function burn(uint256 tokenId) public {173 require(false, stub_error);174 tokenId;175 dummy = 0;176 }177}178179// Selector: 58800161180contract ERC721 is Dummy, ERC165, ERC721Events {181 // Selector: balanceOf(address) 70a08231182 function balanceOf(address owner) public view returns (uint256) {183 require(false, stub_error);184 owner;185 dummy;186 return 0;187 }188189 // Selector: ownerOf(uint256) 6352211e190 function ownerOf(uint256 tokenId) public view returns (address) {191 require(false, stub_error);192 tokenId;193 dummy;194 return 0x0000000000000000000000000000000000000000;195 }196197 // Not implemented198 //199 // Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672200 function safeTransferFromWithData(201 address from,202 address to,203 uint256 tokenId,204 bytes memory data205 ) public {206 require(false, stub_error);207 from;208 to;209 tokenId;210 data;211 dummy = 0;212 }213214 // Not implemented215 //216 // Selector: safeTransferFrom(address,address,uint256) 42842e0e217 function safeTransferFrom(218 address from,219 address to,220 uint256 tokenId221 ) public {222 require(false, stub_error);223 from;224 to;225 tokenId;226 dummy = 0;227 }228229 // Selector: transferFrom(address,address,uint256) 23b872dd230 function transferFrom(231 address from,232 address to,233 uint256 tokenId234 ) public {235 require(false, stub_error);236 from;237 to;238 tokenId;239 dummy = 0;240 }241242 // Selector: approve(address,uint256) 095ea7b3243 function approve(address approved, uint256 tokenId) public {244 require(false, stub_error);245 approved;246 tokenId;247 dummy = 0;248 }249250 // Not implemented251 //252 // Selector: setApprovalForAll(address,bool) a22cb465253 function setApprovalForAll(address operator, bool approved) public {254 require(false, stub_error);255 operator;256 approved;257 dummy = 0;258 }259260 // Not implemented261 //262 // Selector: getApproved(uint256) 081812fc263 function getApproved(uint256 tokenId) public view returns (address) {264 require(false, stub_error);265 tokenId;266 dummy;267 return 0x0000000000000000000000000000000000000000;268 }269270 // Not implemented271 //272 // Selector: isApprovedForAll(address,address) e985e9c5273 function isApprovedForAll(address owner, address operator)274 public275 view276 returns (address)277 {278 require(false, stub_error);279 owner;280 operator;281 dummy;282 return 0x0000000000000000000000000000000000000000;283 }284}285286// Selector: 5b5e139f287contract ERC721Metadata is Dummy, ERC165 {288 // Selector: name() 06fdde03289 function name() public view returns (string memory) {290 require(false, stub_error);291 dummy;292 return "";293 }294295 // Selector: symbol() 95d89b41296 function symbol() public view returns (string memory) {297 require(false, stub_error);298 dummy;299 return "";300 }301302 // Returns token's const_metadata303 //304 // Selector: tokenURI(uint256) c87b56dd305 function tokenURI(uint256 tokenId) public view returns (string memory) {306 require(false, stub_error);307 tokenId;308 dummy;309 return "";310 }311}312313// Selector: 68ccfe89314contract ERC721Mintable is Dummy, ERC165, ERC721MintableEvents {315 // Selector: mintingFinished() 05d2035b316 function mintingFinished() public view returns (bool) {317 require(false, stub_error);318 dummy;319 return false;320 }321322 // `token_id` should be obtained with `next_token_id` method,323 // unlike standard, you can't specify it manually324 //325 // Selector: mint(address,uint256) 40c10f19326 function mint(address to, uint256 tokenId) public returns (bool) {327 require(false, stub_error);328 to;329 tokenId;330 dummy = 0;331 return false;332 }333334 // `token_id` should be obtained with `next_token_id` method,335 // unlike standard, you can't specify it manually336 //337 // Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f338 function mintWithTokenURI(339 address to,340 uint256 tokenId,341 string memory tokenUri342 ) public returns (bool) {343 require(false, stub_error);344 to;345 tokenId;346 tokenUri;347 dummy = 0;348 return false;349 }350351 // Not implemented352 //353 // Selector: finishMinting() 7d64bcb4354 function finishMinting() public returns (bool) {355 require(false, stub_error);356 dummy = 0;357 return false;358 }359}360361// Selector: 780e9d63362contract ERC721Enumerable is Dummy, ERC165 {363 // Selector: tokenByIndex(uint256) 4f6ccce7364 function tokenByIndex(uint256 index) public view returns (uint256) {365 require(false, stub_error);366 index;367 dummy;368 return 0;369 }370371 // Not implemented372 //373 // Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59374 function tokenOfOwnerByIndex(address owner, uint256 index)375 public376 view377 returns (uint256)378 {379 require(false, stub_error);380 owner;381 index;382 dummy;383 return 0;384 }385386 // Selector: totalSupply() 18160ddd387 function totalSupply() public view returns (uint256) {388 require(false, stub_error);389 dummy;390 return 0;391 }392}393394// Selector: d74d154f395contract ERC721UniqueExtensions is Dummy, ERC165 {396 // Selector: transfer(address,uint256) a9059cbb397 function transfer(address to, uint256 tokenId) public {398 require(false, stub_error);399 to;400 tokenId;401 dummy = 0;402 }403404 // Selector: burnFrom(address,uint256) 79cc6790405 function burnFrom(address from, uint256 tokenId) public {406 require(false, stub_error);407 from;408 tokenId;409 dummy = 0;410 }411412 // Selector: nextTokenId() 75794a3c413 function nextTokenId() public view returns (uint256) {414 require(false, stub_error);415 dummy;416 return 0;417 }418419 // Selector: mintBulk(address,uint256[]) 44a9945e420 function mintBulk(address to, uint256[] memory tokenIds)421 public422 returns (bool)423 {424 require(false, stub_error);425 to;426 tokenIds;427 dummy = 0;428 return false;429 }430431 // Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006432 function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)433 public434 returns (bool)435 {436 require(false, stub_error);437 to;438 tokens;439 dummy = 0;440 return false;441 }442}443444contract UniqueNFT is445 Dummy,446 ERC165,447 ERC721,448 ERC721Metadata,449 ERC721Enumerable,450 ERC721UniqueExtensions,451 ERC721Mintable,452 ERC721Burnable,453 Collection,454 TokenProperties455{}pallets/unique/Cargo.tomldiffbeforeafterboth--- a/pallets/unique/Cargo.toml
+++ b/pallets/unique/Cargo.toml
@@ -20,7 +20,6 @@
std = [
'codec/std',
'serde/std',
- 'serde-json-core/std',
'frame-support/std',
'frame-system/std',
'pallet-evm/std',
@@ -42,10 +41,6 @@
default-features = false
features = ['derive']
version = '1.0.130'
-
-[dependencies.serde-json-core]
-default-features = false
-version = "0.4"
[dependencies.ethereum]
version = "0.12.0"
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -110,17 +110,6 @@
}
}
- struct EvmCollection<T: Config>(H160, SubstrateRecorder<T>);
- impl<T: Config> WithRecorder<T> for EvmCollection<T> {
- fn recorder(&self) -> &SubstrateRecorder<T> {
- &self.1
- }
-
- fn into_recorder(self) -> SubstrateRecorder<T> {
- self.1
- }
- }
-
#[derive(ToLog)]
pub enum EthCollectionEvent {
CollectionCreated {
@@ -129,78 +118,7 @@
#[indexed]
collection_id: address,
},
- }
-
- #[solidity_interface(name = "Collection")]
- impl<T: Config> EvmCollection<T> {
- fn set_sponsor(
- &self,
- caller: caller,
- sponsor: address,
- ) -> Result<void> {
- let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
- check_is_owner(caller, &collection)?;
-
- let sponsor = T::CrossAccountId::from_eth(sponsor);
- collection.set_sponsor(sponsor.as_sub().clone());
- collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
- Ok(())
- }
-
- fn confirm_sponsorship(&self, caller: caller) -> Result<void> {
- let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
- let caller = T::CrossAccountId::from_eth(caller);
- if !collection.confirm_sponsorship(caller.as_sub()) {
- return Err(Error::Revert("Caller is not set as sponsor".into()));
- }
- collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
- Ok(())
- }
-
- fn set_limits(
- &self,
- caller: caller,
- limits_json: string,
- ) -> Result<void> {
- let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
- check_is_owner(caller, &collection)?;
-
- let limits = serde_json_core::from_str(limits_json.as_ref())
- .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
- collection.limits = limits.0;
- collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
- Ok(())
- }
-
- fn contract_address(&self, _caller: caller) -> Result<address> {
- Ok(self.0)
- }
- }
-
- fn error_feild_too_long(feild: &str, bound: u32) -> Error {
- Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))
}
-
- fn collection_from_address<T: Config>(
- collection_address: address,
- gas_limit: u64
- ) -> Result<CollectionHandle<T>> {
- let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)
- .ok_or(Error::Revert("Contract is not an unique collection".into()))?;
- let recorder = <SubstrateRecorder<T>>::new(gas_limit);
- let collection =
- pallet_common::CollectionHandle::new_with_recorder(collection_id, recorder)
- .ok_or(Error::Revert("Create collection handle error".into()))?;
- Ok(collection)
- }
-
- fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {
- let caller = T::CrossAccountId::from_eth(caller);
- collection
- .check_is_owner(&caller)
- .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
- Ok(())
- }
pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);
impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {
@@ -235,38 +153,8 @@
generate_stubgen!(collection_helper_impl, CollectionHelperCall<()>, true);
generate_stubgen!(collection_helper_iface, CollectionHelperCall<()>, false);
-
- pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);
- impl<T: Config> OnMethodCall<T> for CollectionOnMethodCall<T> {
- fn is_reserved(contract: &sp_core::H160) -> bool {
- contract == &T::ContractAddress::get()
- }
-
- fn is_used(contract: &sp_core::H160) -> bool {
- contract == &T::ContractAddress::get()
- }
-
- fn call(
- source: &sp_core::H160,
- target: &sp_core::H160,
- gas_left: u64,
- input: &[u8],
- value: sp_core::U256,
- ) -> Option<PrecompileResult> {
- if !pallet_common::eth::is_collection(target) {
- return None;
- }
- let helpers = EvmCollection::<T>(*target, SubstrateRecorder::<T>::new(gas_left));
- pallet_evm_coder_substrate::call(*source, helpers, value, input)
- }
-
- fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
- (contract == &T::ContractAddress::get())
- .then(|| include_bytes!("./stubs/Collection.raw").to_vec())
- }
+ fn error_feild_too_long(feild: &str, bound: u32) -> Error {
+ Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))
}
-
- generate_stubgen!(collection_impl, CollectionCall<()>, true);
- generate_stubgen!(collection_iface, CollectionCall<()>, false);
}
pallets/unique/src/eth/stubs/Collection.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/Collection.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/Collection.sol
+++ /dev/null
@@ -1,52 +0,0 @@
-// SPDX-License-Identifier: OTHER
-// This code is automatically generated
-
-pragma solidity >=0.8.0 <0.9.0;
-
-// Common stubs holder
-contract Dummy {
- uint8 dummy;
- string stub_error = "this contract is implemented in native";
-}
-
-contract ERC165 is Dummy {
- function supportsInterface(bytes4 interfaceID)
- external
- view
- returns (bool)
- {
- require(false, stub_error);
- interfaceID;
- return true;
- }
-}
-
-// Selector: 15cc740e
-contract Collection is Dummy, ERC165 {
- // Selector: setSponsor(address) 59753fb1
- function setSponsor(address sponsor) public view {
- require(false, stub_error);
- sponsor;
- dummy;
- }
-
- // Selector: confirmSponsorship() c8c6a056
- function confirmSponsorship() public view {
- require(false, stub_error);
- dummy;
- }
-
- // Selector: setLimits(string) 72cb345d
- function setLimits(string memory limitsJson) public view {
- require(false, stub_error);
- limitsJson;
- dummy;
- }
-
- // Selector: contractAddress() f6b4dfb4
- function contractAddress() public view returns (address) {
- require(false, stub_error);
- dummy;
- return 0x0000000000000000000000000000000000000000;
- }
-}
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -307,7 +307,6 @@
pallet_evm_migration::OnMethodCall<Self>,
pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
CollectionDispatchT<Self>,
- evm_collection::CollectionOnMethodCall<Self>,
evm_collection::CollectionHelperOnMethodCall<Self>,
);
type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -286,7 +286,6 @@
pallet_evm_migration::OnMethodCall<Self>,
pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
CollectionDispatchT<Self>,
- evm_collection::CollectionOnMethodCall<Self>,
evm_collection::CollectionHelperOnMethodCall<Self>,
);
type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
runtime/unique/src/lib.rsdiffbeforeafterboth--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -291,7 +291,6 @@
pallet_evm_migration::OnMethodCall<Self>,
pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
CollectionDispatchT<Self>,
- evm_collection::CollectionOnMethodCall<Self>,
evm_collection::CollectionHelperOnMethodCall<Self>,
);
type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -42,6 +42,36 @@
event MintingFinished();
}
+// Selector: 38e33c60
+interface Collection is Dummy, ERC165 {
+ // Selector: setCollectionProperty(string,bytes) 2f073f66
+ function setCollectionProperty(string memory key, bytes memory value)
+ external;
+
+ // Selector: deleteCollectionProperty(string) 7b7debce
+ function deleteCollectionProperty(string memory key) external;
+
+ // Throws error if key not found
+ //
+ // Selector: collectionProperty(string) cf24fd6d
+ function collectionProperty(string memory key)
+ external
+ view
+ returns (bytes memory);
+
+ // Selector: ethSetSponsor(address) 8f9af356
+ function ethSetSponsor(address sponsor) external;
+
+ // Selector: ethConfirmSponsorship() a8580d1a
+ function ethConfirmSponsorship() external;
+
+ // Selector: setLimits(string) 72cb345d
+ function setLimits(string memory limitsJson) external view;
+
+ // Selector: contractAddress() f6b4dfb4
+ function contractAddress() external view returns (address);
+}
+
// Selector: 41369377
interface TokenProperties is Dummy, ERC165 {
// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
@@ -191,24 +221,6 @@
function totalSupply() external view returns (uint256);
}
-// Selector: 9b5e29c5
-interface CollectionProperties is Dummy, ERC165 {
- // Selector: setCollectionProperty(string,bytes) 2f073f66
- function setCollectionProperty(string memory key, bytes memory value)
- external;
-
- // Selector: deleteCollectionProperty(string) 7b7debce
- function deleteCollectionProperty(string memory key) external;
-
- // Throws error if key not found
- //
- // Selector: collectionProperty(string) cf24fd6d
- function collectionProperty(string memory key)
- external
- view
- returns (bytes memory);
-}
-
// Selector: d74d154f
interface ERC721UniqueExtensions is Dummy, ERC165 {
// Selector: transfer(address,uint256) a9059cbb
@@ -240,6 +252,6 @@
ERC721UniqueExtensions,
ERC721Mintable,
ERC721Burnable,
- CollectionProperties,
+ Collection,
TokenProperties
{}
tests/src/eth/collectionAbi.jsondiffbeforeafterboth--- a/tests/src/eth/collectionAbi.json
+++ /dev/null
@@ -1,43 +0,0 @@
-[
- {
- "inputs": [],
- "name": "confirmSponsorship",
- "outputs": [],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "contractAddress",
- "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [
- { "internalType": "string", "name": "limitsJson", "type": "string" }
- ],
- "name": "setLimits",
- "outputs": [],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [
- { "internalType": "address", "name": "sponsor", "type": "address" }
- ],
- "name": "setSponsor",
- "outputs": [],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [
- { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }
- ],
- "name": "supportsInterface",
- "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
- "stateMutability": "view",
- "type": "function"
- }
-]
tests/src/eth/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -88,13 +88,13 @@
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- result = await collectionEvm.methods.setSponsor(sponsor).send();
+ result = await collectionEvm.methods.ethSetSponsor(sponsor).send();
let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
- await expect(collectionEvm.methods.confirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
+ await expect(collectionEvm.methods.ethConfirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
- await sponsorCollection.methods.confirmSponsorship().send();
+ await sponsorCollection.methods.ethConfirmSponsorship().send();
collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isConfirmed).to.be.true;
expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -126,6 +126,13 @@
"type": "function"
},
{
+ "inputs": [],
+ "name": "contractAddress",
+ "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
"inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
"name": "deleteCollectionProperty",
"outputs": [],
@@ -144,6 +151,22 @@
},
{
"inputs": [],
+ "name": "ethConfirmSponsorship",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ { "internalType": "address", "name": "sponsor", "type": "address" }
+ ],
+ "name": "ethSetSponsor",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [],
"name": "finishMinting",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
@@ -302,6 +325,15 @@
},
{
"inputs": [
+ { "internalType": "string", "name": "limitsJson", "type": "string" }
+ ],
+ "name": "setLimits",
+ "outputs": [],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" },
{ "internalType": "string", "name": "key", "type": "string" },
{ "internalType": "bytes", "name": "value", "type": "bytes" }
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -28,7 +28,7 @@
import config from '../../config';
import privateKey from '../../substrate/privateKey';
import contractHelpersAbi from './contractHelpersAbi.json';
-import collectionAbi from '../collectionAbi.json';
+import collectionAbi from '../nonFungibleAbi.json';
import collectionHelperAbi from '../collectionHelperAbi.json';
import getBalance from '../../substrate/get-balance';
import waitNewBlocks from '../../substrate/wait-new-blocks';