difftreelog
Merge pull request #871 from UniqueNetwork/feature/move_TokenChanged_event
in: master
21 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2445,8 +2445,8 @@
[[package]]
name = "evm-coder"
-version = "0.3.0"
-source = "git+https://github.com/uniquenetwork/evm-coder?tag=v0.3.0#c4bfdf39d84fbe74c6178417177f2a7f81d92bdd"
+version = "0.3.1"
+source = "git+https://github.com/uniquenetwork/evm-coder?tag=v0.3.1#21e61c627f71337d6b8a03899fe8de14bfbf67aa"
dependencies = [
"ethereum",
"evm-coder-procedural",
@@ -2457,8 +2457,8 @@
[[package]]
name = "evm-coder-procedural"
-version = "0.3.0"
-source = "git+https://github.com/uniquenetwork/evm-coder?tag=v0.3.0#c4bfdf39d84fbe74c6178417177f2a7f81d92bdd"
+version = "0.3.1"
+source = "git+https://github.com/uniquenetwork/evm-coder?tag=v0.3.1#21e61c627f71337d6b8a03899fe8de14bfbf67aa"
dependencies = [
"Inflector",
"hex",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,16 +19,9 @@
[workspace.dependencies]
# Unique
-evm-coder = { git = "https://github.com/uniquenetwork/evm-coder", tag = "v0.3.0", default-features = false }
-struct-versioning = { path = "crates/struct-versioning" }
-precompile-utils-macro = { path = "runtime/common/ethereum/precompiles/utils/macro" }
-up-common = { path = "primitives/common", default-features = false }
-up-data-structs = { path = "primitives/data-structs", default-features = false }
-up-pov-estimate-rpc = { path = "primitives/pov-estimate-rpc", default-features = false }
-up-rpc = { path = "primitives/rpc", default-features = false }
-up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.37" }
-uc-rpc = { path = "client/rpc" }
-unique-rpc = { path = "node/rpc" }
+app-promotion-rpc = { path = "primitives/app_promotion_rpc", default-features = false }
+evm-coder = { git = "https://github.com/uniquenetwork/evm-coder", tag = "v0.3.1", default-features = false }
+pallet-app-promotion = { path = "pallets/app-promotion", default-features = false }
pallet-charge-transaction = { package = "pallet-template-transaction-payment", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.37" }
pallet-collator-selection = { default-features = false, path = "pallets/collator-selection" }
pallet-common = { default-features = false, path = "pallets/common" }
@@ -45,56 +38,59 @@
pallet-nonfungible = { default-features = false, path = "pallets/nonfungible" }
pallet-refungible = { default-features = false, path = "pallets/refungible" }
pallet-structure = { default-features = false, path = "pallets/structure" }
+pallet-test-utils = { default-features = false, path = "test-pallets/utils" }
pallet-unique = { path = "pallets/unique", default-features = false }
pallet-unique-scheduler-v2 = { path = "pallets/scheduler-v2", default-features = false }
-pallet-test-utils = { default-features = false, path = "test-pallets/utils" }
-pallet-app-promotion = { path = "pallets/app-promotion", default-features = false }
-app-promotion-rpc = { path = "primitives/app_promotion_rpc", default-features = false }
+precompile-utils-macro = { path = "runtime/common/ethereum/precompiles/utils/macro" }
+struct-versioning = { path = "crates/struct-versioning" }
+uc-rpc = { path = "client/rpc" }
+unique-rpc = { path = "node/rpc" }
+up-common = { path = "primitives/common", default-features = false }
+up-data-structs = { path = "primitives/data-structs", default-features = false }
+up-pov-estimate-rpc = { path = "primitives/pov-estimate-rpc", default-features = false }
+up-rpc = { path = "primitives/rpc", default-features = false }
+up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.37" }
# Unique: Runtimes
+opal-runtime = { path = "runtime/opal" }
+quartz-runtime = { path = "runtime/quartz" }
unique-runtime = { path = "runtime/unique" }
-quartz-runtime = { path = "runtime/quartz" }
-opal-runtime = { path = "runtime/opal" }
# Frontier (Unique patches over the Parity version)
+fc-consensus = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
+fc-db = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
+fc-mapping-sync = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
+fc-rpc = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
+fc-rpc-core = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
fp-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
-fc-db = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
-fc-rpc = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
-fc-rpc-core = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
fp-storage = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
-fc-consensus = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
-fc-mapping-sync = { git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
+pallet-base-fee = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
-pallet-base-fee = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/uniquenetwork/unique-frontier", branch = "unique-polkadot-v0.9.37" }
# Parity
codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = "3.2.2" }
-scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
-polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
-polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
-polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-network = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-client-service = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
-cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
-cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
-cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
-cumulus-relay-chain-minimal-node = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
+cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
+cumulus-relay-chain-inprocess-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
+cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
+cumulus-relay-chain-minimal-node = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
@@ -107,67 +103,71 @@
pallet-sudo = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
pallet-treasury = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37", default-features = false }
-pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
parachain-info = { default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37" }
+polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37", default-features = false }
+polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
+polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" }
+sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-block-builder = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-consensus-aura = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-inherents = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-offchain = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-session = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
sp-trie = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+sp-version = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
+substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37", default-features = false }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37", default-features = false }
# Parity: Build utils
+substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
# Parity: Benchmarking
+frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
# Parity: Try Runtime
+frame-try-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
-frame-try-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" }
# ORML
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.37", default-features = false }
@@ -176,15 +176,15 @@
orml-xtokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.37", default-features = false }
# Other
-smallvec = "1.6.1"
derivative = { version = "2.2.0", features = ["use_core"] }
-serde = { default-features = false, features = ['derive'], version = "1.0.136" }
-log = { version = "0.4.16", default-features = false }
-num_enum = { version = "0.5.3", default-features = false }
+ethereum = { version = "0.14.0", default-features = false }
+evm-core = { default-features = false, version = "0.37.0" }
hex-literal = "0.3.4"
impl-trait-for-tuples = "0.2.2"
+jsonrpsee = { version = "0.16.2", features = ["macros", "server"] }
+log = { version = "0.4.16", default-features = false }
logtest = "2.0.0"
-ethereum = { version = "0.14.0", default-features = false }
-evm-core = { default-features = false, version = "0.37.0" }
+num_enum = { version = "0.5.3", default-features = false }
primitive-types = { version = "0.12.1", default-features = false }
-jsonrpsee = { version = "0.16.2", features = ["macros", "server"] }
+serde = { default-features = false, features = ['derive'], version = "1.0.136" }
+smallvec = "1.6.1"
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -26,7 +26,6 @@
};
use pallet_evm_coder_substrate::dispatch_to_evm;
use sp_std::{vec, vec::Vec};
-use sp_core::U256;
use up_data_structs::{
CollectionMode, CollectionPermissions, OwnerRestrictedSet, Property, SponsoringRateLimit,
SponsorshipState,
@@ -62,18 +61,9 @@
},
/// The collection has been changed.
CollectionChanged {
- /// Collection ID.
- #[indexed]
- collection_id: Address,
- },
-
- /// The token has been changed.
- TokenChanged {
/// Collection ID.
#[indexed]
collection_id: Address,
- /// Token ID.
- token_id: U256,
},
}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -86,7 +86,6 @@
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
-use crate::erc::CollectionHelpersEvents;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod dispatch;
@@ -1250,6 +1249,7 @@
mut stored_properties: Properties,
is_token_owner: impl Fn() -> Result<bool, DispatchError>,
set_token_properties: impl FnOnce(Properties),
+ log: evm_coder::ethereum::Log,
) -> DispatchResult {
let is_collection_admin = collection.is_owner_or_admin(sender);
let permissions = Self::property_permissions(collection.id);
@@ -1304,13 +1304,7 @@
}
}
- <PalletEvm<T>>::deposit_log(
- CollectionHelpersEvents::TokenChanged {
- collection_id: eth::collection_id_to_address(collection.id),
- token_id: token_id.into(),
- }
- .to_log(T::ContractAddress::get()),
- );
+ <PalletEvm<T>>::deposit_log(log.clone());
}
set_token_properties(stored_properties);
pallets/nonfungible/src/erc.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//! # Nonfungible Pallet EVM API18//!19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Nonfungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122extern crate alloc;23use core::{24 char::{REPLACEMENT_CHARACTER, decode_utf16},25 convert::TryInto,26};27use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};28use frame_support::BoundedVec;29use up_data_structs::{30 TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,31 CollectionPropertiesVec,32};33use pallet_evm_coder_substrate::{34 dispatch_to_evm, frontier_contract,35 execution::{Result, PreDispatch, Error},36};37use sp_std::{vec::Vec, vec};38use pallet_common::{39 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,40 erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},41 eth::{self, TokenUri},42};43use pallet_evm::{account::CrossAccountId, PrecompileHandle};44use pallet_evm_coder_substrate::call;45use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};46use sp_core::{U256, Get};4748use crate::{49 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,50 TokenProperties, SelfWeightOf, weights::WeightInfo,51};5253frontier_contract! {54 macro_rules! NonfungibleHandle_result {...}55 impl<T: Config> Contract for NonfungibleHandle<T> {...}56}5758/// @title A contract that allows to set and delete token properties and change token property permissions.59#[solidity_interface(name = TokenProperties, enum(derive(PreDispatch)), enum_attr(weight))]60impl<T: Config> NonfungibleHandle<T> {61 /// @notice Set permissions for token property.62 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.63 /// @param key Property key.64 /// @param isMutable Permission to mutate property.65 /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.66 /// @param tokenOwner Permission to mutate property by token owner if property is mutable.67 #[solidity(hide)]68 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(1))]69 fn set_token_property_permission(70 &mut self,71 caller: Caller,72 key: String,73 is_mutable: bool,74 collection_admin: bool,75 token_owner: bool,76 ) -> Result<()> {77 let caller = T::CrossAccountId::from_eth(caller);78 <Pallet<T>>::set_token_property_permissions(79 self,80 &caller,81 vec![PropertyKeyPermission {82 key: <Vec<u8>>::from(key)83 .try_into()84 .map_err(|_| "too long key")?,85 permission: PropertyPermission {86 mutable: is_mutable,87 collection_admin,88 token_owner,89 },90 }],91 )92 .map_err(dispatch_to_evm::<T>)93 }9495 /// @notice Set permissions for token property.96 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.97 /// @param permissions Permissions for keys.98 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(permissions.len() as u32))]99 fn set_token_property_permissions(100 &mut self,101 caller: Caller,102 permissions: Vec<eth::TokenPropertyPermission>,103 ) -> Result<()> {104 let caller = T::CrossAccountId::from_eth(caller);105 let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;106107 <Pallet<T>>::set_token_property_permissions(self, &caller, perms)108 .map_err(dispatch_to_evm::<T>)109 }110111 /// @notice Get permissions for token properties.112 fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {113 let perms = <Pallet<T>>::token_property_permission(self.id);114 Ok(perms115 .into_iter()116 .map(eth::TokenPropertyPermission::from)117 .collect())118 }119120 /// @notice Set token property value.121 /// @dev Throws error if `msg.sender` has no permission to edit the property.122 /// @param tokenId ID of the token.123 /// @param key Property key.124 /// @param value Property value.125 #[solidity(hide)]126 #[weight(<SelfWeightOf<T>>::set_token_properties(1))]127 fn set_property(128 &mut self,129 caller: Caller,130 token_id: U256,131 key: String,132 value: Bytes,133 ) -> Result<()> {134 let caller = T::CrossAccountId::from_eth(caller);135 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;136 let key = <Vec<u8>>::from(key)137 .try_into()138 .map_err(|_| "key too long")?;139 let value = value.0.try_into().map_err(|_| "value too long")?;140141 let nesting_budget = self142 .recorder143 .weight_calls_budget(<StructureWeight<T>>::find_parent());144145 <Pallet<T>>::set_token_property(146 self,147 &caller,148 TokenId(token_id),149 Property { key, value },150 &nesting_budget,151 )152 .map_err(dispatch_to_evm::<T>)153 }154155 /// @notice Set token properties value.156 /// @dev Throws error if `msg.sender` has no permission to edit the property.157 /// @param tokenId ID of the token.158 /// @param properties settable properties159 #[weight(<SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]160 fn set_properties(161 &mut self,162 caller: Caller,163 token_id: U256,164 properties: Vec<eth::Property>,165 ) -> Result<()> {166 let caller = T::CrossAccountId::from_eth(caller);167 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;168169 let nesting_budget = self170 .recorder171 .weight_calls_budget(<StructureWeight<T>>::find_parent());172173 let properties = properties174 .into_iter()175 .map(eth::Property::try_into)176 .collect::<Result<Vec<_>>>()?;177178 <Pallet<T>>::set_token_properties(179 self,180 &caller,181 TokenId(token_id),182 properties.into_iter(),183 false,184 &nesting_budget,185 )186 .map_err(dispatch_to_evm::<T>)187 }188189 /// @notice Delete token property value.190 /// @dev Throws error if `msg.sender` has no permission to edit the property.191 /// @param tokenId ID of the token.192 /// @param key Property key.193 #[solidity(hide)]194 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]195 fn delete_property(&mut self, token_id: U256, caller: Caller, key: String) -> Result<()> {196 let caller = T::CrossAccountId::from_eth(caller);197 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;198 let key = <Vec<u8>>::from(key)199 .try_into()200 .map_err(|_| "key too long")?;201202 let nesting_budget = self203 .recorder204 .weight_calls_budget(<StructureWeight<T>>::find_parent());205206 <Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)207 .map_err(dispatch_to_evm::<T>)208 }209210 /// @notice Delete token properties value.211 /// @dev Throws error if `msg.sender` has no permission to edit the property.212 /// @param tokenId ID of the token.213 /// @param keys Properties key.214 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]215 fn delete_properties(216 &mut self,217 token_id: U256,218 caller: Caller,219 keys: Vec<String>,220 ) -> Result<()> {221 let caller = T::CrossAccountId::from_eth(caller);222 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;223 let keys = keys224 .into_iter()225 .map(|k| Ok(<Vec<u8>>::from(k).try_into().map_err(|_| "key too long")?))226 .collect::<Result<Vec<_>>>()?;227228 let nesting_budget = self229 .recorder230 .weight_calls_budget(<StructureWeight<T>>::find_parent());231232 <Pallet<T>>::delete_token_properties(233 self,234 &caller,235 TokenId(token_id),236 keys.into_iter(),237 &nesting_budget,238 )239 .map_err(dispatch_to_evm::<T>)240 }241242 /// @notice Get token property value.243 /// @dev Throws error if key not found244 /// @param tokenId ID of the token.245 /// @param key Property key.246 /// @return Property value bytes247 fn property(&self, token_id: U256, key: String) -> Result<Bytes> {248 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;249 let key = <Vec<u8>>::from(key)250 .try_into()251 .map_err(|_| "key too long")?;252253 let props = <TokenProperties<T>>::get((self.id, token_id));254 let prop = props.get(&key).ok_or("key not found")?;255256 Ok(prop.to_vec().into())257 }258}259260#[derive(ToLog)]261pub enum ERC721Events {262 /// @dev This emits when ownership of any NFT changes by any mechanism.263 /// This event emits when NFTs are created (`from` == 0) and destroyed264 /// (`to` == 0). Exception: during contract creation, any number of NFTs265 /// may be created and assigned without emitting Transfer. At the time of266 /// any transfer, the approved address for that NFT (if any) is reset to none.267 Transfer {268 #[indexed]269 from: Address,270 #[indexed]271 to: Address,272 #[indexed]273 token_id: U256,274 },275 /// @dev This emits when the approved address for an NFT is changed or276 /// reaffirmed. The zero address indicates there is no approved address.277 /// When a Transfer event emits, this also indicates that the approved278 /// address for that NFT (if any) is reset to none.279 Approval {280 #[indexed]281 owner: Address,282 #[indexed]283 approved: Address,284 #[indexed]285 token_id: U256,286 },287 /// @dev This emits when an operator is enabled or disabled for an owner.288 /// The operator can manage all NFTs of the owner.289 #[allow(dead_code)]290 ApprovalForAll {291 #[indexed]292 owner: Address,293 #[indexed]294 operator: Address,295 approved: bool,296 },297}298299/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension300/// @dev See https://eips.ethereum.org/EIPS/eip-721301#[solidity_interface(name = ERC721Metadata, expect_selector = 0x5b5e139f, enum(derive(PreDispatch)), enum_attr(weight))]302impl<T: Config> NonfungibleHandle<T>303where304 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,305{306 /// @notice A descriptive name for a collection of NFTs in this contract307 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`308 #[solidity(hide, rename_selector = "name")]309 fn name_proxy(&self) -> String {310 self.name()311 }312313 /// @notice An abbreviated name for NFTs in this contract314 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`315 #[solidity(hide, rename_selector = "symbol")]316 fn symbol_proxy(&self) -> String {317 self.symbol()318 }319320 /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.321 ///322 /// @dev If the token has a `url` property and it is not empty, it is returned.323 /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.324 /// If the collection property `baseURI` is empty or absent, return "" (empty string)325 /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix326 /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).327 ///328 /// @return token's const_metadata329 #[solidity(rename_selector = "tokenURI")]330 fn token_uri(&self, token_id: U256) -> Result<String> {331 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;332333 match get_token_property(self, token_id_u32, &key::url()).as_deref() {334 Err(_) | Ok("") => (),335 Ok(url) => {336 return Ok(url.into());337 }338 };339340 let base_uri =341 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())342 .map(BoundedVec::into_inner)343 .map(String::from_utf8)344 .transpose()345 .map_err(|e| {346 Error::Revert(alloc::format!(347 "Can not convert value \"baseURI\" to string with error \"{}\"",348 e349 ))350 })?;351352 let base_uri = match base_uri.as_deref() {353 None | Some("") => {354 return Ok("".into());355 }356 Some(base_uri) => base_uri.into(),357 };358359 Ok(360 match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {361 Err(_) | Ok("") => base_uri,362 Ok(suffix) => base_uri + suffix,363 },364 )365 }366}367368/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension369/// @dev See https://eips.ethereum.org/EIPS/eip-721370#[solidity_interface(name = ERC721Enumerable, expect_selector = 0x780e9d63, enum(derive(PreDispatch)), enum_attr(weight))]371impl<T: Config> NonfungibleHandle<T> {372 /// @notice Enumerate valid NFTs373 /// @param index A counter less than `totalSupply()`374 /// @return The token identifier for the `index`th NFT,375 /// (sort order not specified)376 fn token_by_index(&self, index: U256) -> U256 {377 index378 }379380 /// @dev Not implemented381 fn token_of_owner_by_index(&self, _owner: Address, _index: U256) -> Result<U256> {382 // TODO: Not implemetable383 Err("not implemented".into())384 }385386 /// @notice Count NFTs tracked by this contract387 /// @return A count of valid NFTs tracked by this contract, where each one of388 /// them has an assigned and queryable owner not equal to the zero address389 fn total_supply(&self) -> Result<U256> {390 self.consume_store_reads(1)?;391 Ok(<Pallet<T>>::total_supply(self).into())392 }393}394395/// @title ERC-721 Non-Fungible Token Standard396/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md397#[solidity_interface(name = ERC721, events(ERC721Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x80ac58cd)]398impl<T: Config> NonfungibleHandle<T> {399 /// @notice Count all NFTs assigned to an owner400 /// @dev NFTs assigned to the zero address are considered invalid, and this401 /// function throws for queries about the zero address.402 /// @param owner An address for whom to query the balance403 /// @return The number of NFTs owned by `owner`, possibly zero404 fn balance_of(&self, owner: Address) -> Result<U256> {405 self.consume_store_reads(1)?;406 let owner = T::CrossAccountId::from_eth(owner);407 let balance = <AccountBalance<T>>::get((self.id, owner));408 Ok(balance.into())409 }410 /// @notice Find the owner of an NFT411 /// @dev NFTs assigned to zero address are considered invalid, and queries412 /// about them do throw.413 /// @param tokenId The identifier for an NFT414 /// @return The address of the owner of the NFT415 fn owner_of(&self, token_id: U256) -> Result<Address> {416 self.consume_store_reads(1)?;417 let token: TokenId = token_id.try_into()?;418 Ok(*<TokenData<T>>::get((self.id, token))419 .ok_or("token not found")?420 .owner421 .as_eth())422 }423 /// @dev Not implemented424 #[solidity(rename_selector = "safeTransferFrom")]425 fn safe_transfer_from_with_data(426 &mut self,427 _from: Address,428 _to: Address,429 _token_id: U256,430 _data: Bytes,431 ) -> Result<()> {432 // TODO: Not implemetable433 Err("not implemented".into())434 }435 /// @dev Not implemented436 fn safe_transfer_from(&mut self, _from: Address, _to: Address, _token_id: U256) -> Result<()> {437 // TODO: Not implemetable438 Err("not implemented".into())439 }440441 /// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE442 /// TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE443 /// THEY MAY BE PERMANENTLY LOST444 /// @dev Throws unless `msg.sender` is the current owner or an authorized445 /// operator for this NFT. Throws if `from` is not the current owner. Throws446 /// if `to` is the zero address. Throws if `tokenId` is not a valid NFT.447 /// @param from The current owner of the NFT448 /// @param to The new owner449 /// @param tokenId The NFT to transfer450 #[weight(<SelfWeightOf<T>>::transfer_from())]451 fn transfer_from(452 &mut self,453 caller: Caller,454 from: Address,455 to: Address,456 token_id: U256,457 ) -> Result<()> {458 let caller = T::CrossAccountId::from_eth(caller);459 let from = T::CrossAccountId::from_eth(from);460 let to = T::CrossAccountId::from_eth(to);461 let token = token_id.try_into()?;462 let budget = self463 .recorder464 .weight_calls_budget(<StructureWeight<T>>::find_parent());465466 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token, &budget)467 .map_err(dispatch_to_evm::<T>)?;468 Ok(())469 }470471 /// @notice Set or reaffirm the approved address for an NFT472 /// @dev The zero address indicates there is no approved address.473 /// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized474 /// operator of the current owner.475 /// @param approved The new approved NFT controller476 /// @param tokenId The NFT to approve477 #[weight(<SelfWeightOf<T>>::approve())]478 fn approve(&mut self, caller: Caller, approved: Address, token_id: U256) -> Result<()> {479 let caller = T::CrossAccountId::from_eth(caller);480 let approved = T::CrossAccountId::from_eth(approved);481 let token = token_id.try_into()?;482483 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))484 .map_err(dispatch_to_evm::<T>)?;485 Ok(())486 }487488 /// @notice Sets or unsets the approval of a given operator.489 /// The `operator` is allowed to transfer all tokens of the `caller` on their behalf.490 /// @param operator Operator491 /// @param approved Should operator status be granted or revoked?492 #[weight(<SelfWeightOf<T>>::set_allowance_for_all())]493 fn set_approval_for_all(494 &mut self,495 caller: Caller,496 operator: Address,497 approved: bool,498 ) -> Result<()> {499 let caller = T::CrossAccountId::from_eth(caller);500 let operator = T::CrossAccountId::from_eth(operator);501502 <Pallet<T>>::set_allowance_for_all(self, &caller, &operator, approved)503 .map_err(dispatch_to_evm::<T>)?;504 Ok(())505 }506507 /// @dev Not implemented508 fn get_approved(&self, _token_id: U256) -> Result<Address> {509 // TODO: Not implemetable510 Err("not implemented".into())511 }512513 /// @notice Tells whether the given `owner` approves the `operator`.514 #[weight(<SelfWeightOf<T>>::allowance_for_all())]515 fn is_approved_for_all(&self, owner: Address, operator: Address) -> Result<bool> {516 let owner = T::CrossAccountId::from_eth(owner);517 let operator = T::CrossAccountId::from_eth(operator);518519 Ok(<Pallet<T>>::allowance_for_all(self, &owner, &operator))520 }521}522523/// @title ERC721 Token that can be irreversibly burned (destroyed).524#[solidity_interface(name = ERC721Burnable, enum(derive(PreDispatch)), enum_attr(weight))]525impl<T: Config> NonfungibleHandle<T> {526 /// @notice Burns a specific ERC721 token.527 /// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized528 /// operator of the current owner.529 /// @param tokenId The NFT to approve530 #[weight(<SelfWeightOf<T>>::burn_item())]531 fn burn(&mut self, caller: Caller, token_id: U256) -> Result<()> {532 let caller = T::CrossAccountId::from_eth(caller);533 let token = token_id.try_into()?;534535 <Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;536 Ok(())537 }538}539540/// @title ERC721 minting logic.541#[solidity_interface(name = ERC721UniqueMintable, enum(derive(PreDispatch)), enum_attr(weight))]542impl<T: Config> NonfungibleHandle<T> {543 /// @notice Function to mint a token.544 /// @param to The new owner545 /// @return uint256 The id of the newly minted token546 #[weight(<SelfWeightOf<T>>::create_item())]547 fn mint(&mut self, caller: Caller, to: Address) -> Result<U256> {548 let token_id: U256 = <TokensMinted<T>>::get(self.id)549 .checked_add(1)550 .ok_or("item id overflow")?551 .into();552 self.mint_check_id(caller, to, token_id)?;553 Ok(token_id)554 }555556 /// @notice Function to mint a token.557 /// @dev `tokenId` should be obtained with `nextTokenId` method,558 /// unlike standard, you can't specify it manually559 /// @param to The new owner560 /// @param tokenId ID of the minted NFT561 #[solidity(hide, rename_selector = "mint")]562 #[weight(<SelfWeightOf<T>>::create_item())]563 fn mint_check_id(&mut self, caller: Caller, to: Address, token_id: U256) -> Result<bool> {564 let caller = T::CrossAccountId::from_eth(caller);565 let to = T::CrossAccountId::from_eth(to);566 let token_id: u32 = token_id.try_into()?;567 let budget = self568 .recorder569 .weight_calls_budget(<StructureWeight<T>>::find_parent());570571 if <TokensMinted<T>>::get(self.id)572 .checked_add(1)573 .ok_or("item id overflow")?574 != token_id575 {576 return Err("item id should be next".into());577 }578579 <Pallet<T>>::create_item(580 self,581 &caller,582 CreateItemData::<T> {583 properties: BoundedVec::default(),584 owner: to,585 },586 &budget,587 )588 .map_err(dispatch_to_evm::<T>)?;589590 Ok(true)591 }592593 /// @notice Function to mint token with the given tokenUri.594 /// @param to The new owner595 /// @param tokenUri Token URI that would be stored in the NFT properties596 /// @return uint256 The id of the newly minted token597 #[solidity(rename_selector = "mintWithTokenURI")]598 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]599 fn mint_with_token_uri(600 &mut self,601 caller: Caller,602 to: Address,603 token_uri: String,604 ) -> Result<U256> {605 let token_id: U256 = <TokensMinted<T>>::get(self.id)606 .checked_add(1)607 .ok_or("item id overflow")?608 .into();609 self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;610 Ok(token_id)611 }612613 /// @notice Function to mint token with the given tokenUri.614 /// @dev `tokenId` should be obtained with `nextTokenId` method,615 /// unlike standard, you can't specify it manually616 /// @param to The new owner617 /// @param tokenId ID of the minted NFT618 /// @param tokenUri Token URI that would be stored in the NFT properties619 #[solidity(hide, rename_selector = "mintWithTokenURI")]620 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(1))]621 fn mint_with_token_uri_check_id(622 &mut self,623 caller: Caller,624 to: Address,625 token_id: U256,626 token_uri: String,627 ) -> Result<bool> {628 let key = key::url();629 let permission = get_token_permission::<T>(self.id, &key)?;630 if !permission.collection_admin {631 return Err("Operation is not allowed".into());632 }633634 let caller = T::CrossAccountId::from_eth(caller);635 let to = T::CrossAccountId::from_eth(to);636 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;637 let budget = self638 .recorder639 .weight_calls_budget(<StructureWeight<T>>::find_parent());640641 if <TokensMinted<T>>::get(self.id)642 .checked_add(1)643 .ok_or("item id overflow")?644 != token_id645 {646 return Err("item id should be next".into());647 }648649 let mut properties = CollectionPropertiesVec::default();650 properties651 .try_push(Property {652 key,653 value: token_uri654 .into_bytes()655 .try_into()656 .map_err(|_| "token uri is too long")?,657 })658 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;659660 <Pallet<T>>::create_item(661 self,662 &caller,663 CreateItemData::<T> {664 properties,665 owner: to,666 },667 &budget,668 )669 .map_err(dispatch_to_evm::<T>)?;670 Ok(true)671 }672}673674fn get_token_property<T: Config>(675 collection: &CollectionHandle<T>,676 token_id: u32,677 key: &up_data_structs::PropertyKey,678) -> Result<String> {679 collection.consume_store_reads(1)?;680 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))681 .map_err(|_| Error::Revert("Token properties not found".into()))?;682 if let Some(property) = properties.get(key) {683 return Ok(String::from_utf8_lossy(property).into());684 }685686 Err("Property tokenURI not found".into())687}688689fn get_token_permission<T: Config>(690 collection_id: CollectionId,691 key: &PropertyKey,692) -> Result<PropertyPermission> {693 let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)694 .map_err(|_| Error::Revert("No permissions for collection".into()))?;695 let a = token_property_permissions696 .get(key)697 .map(Clone::clone)698 .ok_or_else(|| {699 let key = String::from_utf8(key.clone().into_inner()).unwrap_or_default();700 Error::Revert(alloc::format!("No permission for key {}", key))701 })?;702 Ok(a)703}704705/// @title Unique extensions for ERC721.706#[solidity_interface(name = ERC721UniqueExtensions, enum(derive(PreDispatch)), enum_attr(weight))]707impl<T: Config> NonfungibleHandle<T>708where709 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,710{711 /// @notice A descriptive name for a collection of NFTs in this contract712 fn name(&self) -> String {713 decode_utf16(self.name.iter().copied())714 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))715 .collect::<String>()716 }717718 /// @notice An abbreviated name for NFTs in this contract719 fn symbol(&self) -> String {720 String::from_utf8_lossy(&self.token_prefix).into()721 }722723 /// @notice A description for the collection.724 fn description(&self) -> String {725 decode_utf16(self.description.iter().copied())726 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))727 .collect::<String>()728 }729730 /// Returns the owner (in cross format) of the token.731 ///732 /// @param tokenId Id for the token.733 fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {734 Self::token_owner(&self, token_id.try_into()?)735 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))736 .map_err(|_| Error::Revert("token not found".into()))737 }738739 /// Returns the token properties.740 ///741 /// @param tokenId Id for the token.742 /// @param keys Properties keys. Empty keys for all propertyes.743 /// @return Vector of properties key/value pairs.744 fn properties(&self, token_id: U256, keys: Vec<String>) -> Result<Vec<eth::Property>> {745 let keys = keys746 .into_iter()747 .map(|key| {748 <Vec<u8>>::from(key)749 .try_into()750 .map_err(|_| Error::Revert("key too large".into()))751 })752 .collect::<Result<Vec<_>>>()?;753754 <Self as CommonCollectionOperations<T>>::token_properties(755 &self,756 token_id.try_into()?,757 if keys.is_empty() { None } else { Some(keys) },758 )759 .into_iter()760 .map(eth::Property::try_from)761 .collect::<Result<Vec<_>>>()762 }763764 /// @notice Set or reaffirm the approved address for an NFT765 /// @dev The zero address indicates there is no approved address.766 /// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized767 /// operator of the current owner.768 /// @param approved The new substrate address approved NFT controller769 /// @param tokenId The NFT to approve770 #[weight(<SelfWeightOf<T>>::approve())]771 fn approve_cross(772 &mut self,773 caller: Caller,774 approved: eth::CrossAddress,775 token_id: U256,776 ) -> Result<()> {777 let caller = T::CrossAccountId::from_eth(caller);778 let approved = approved.into_sub_cross_account::<T>()?;779 let token = token_id.try_into()?;780781 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))782 .map_err(dispatch_to_evm::<T>)?;783 Ok(())784 }785786 /// @notice Transfer ownership of an NFT787 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`788 /// is the zero address. Throws if `tokenId` is not a valid NFT.789 /// @param to The new owner790 /// @param tokenId The NFT to transfer791 #[weight(<SelfWeightOf<T>>::transfer())]792 fn transfer(&mut self, caller: Caller, to: Address, token_id: U256) -> Result<()> {793 let caller = T::CrossAccountId::from_eth(caller);794 let to = T::CrossAccountId::from_eth(to);795 let token = token_id.try_into()?;796 let budget = self797 .recorder798 .weight_calls_budget(<StructureWeight<T>>::find_parent());799800 <Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;801 Ok(())802 }803804 /// @notice Transfer ownership of an NFT805 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`806 /// is the zero address. Throws if `tokenId` is not a valid NFT.807 /// @param to The new owner808 /// @param tokenId The NFT to transfer809 #[weight(<SelfWeightOf<T>>::transfer())]810 fn transfer_cross(811 &mut self,812 caller: Caller,813 to: eth::CrossAddress,814 token_id: U256,815 ) -> Result<()> {816 let caller = T::CrossAccountId::from_eth(caller);817 let to = to.into_sub_cross_account::<T>()?;818 let token = token_id.try_into()?;819 let budget = self820 .recorder821 .weight_calls_budget(<StructureWeight<T>>::find_parent());822823 <Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;824 Ok(())825 }826827 /// @notice Transfer ownership of an NFT from cross account address to cross account address828 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`829 /// is the zero address. Throws if `tokenId` is not a valid NFT.830 /// @param from Cross acccount address of current owner831 /// @param to Cross acccount address of new owner832 /// @param tokenId The NFT to transfer833 #[weight(<SelfWeightOf<T>>::transfer())]834 fn transfer_from_cross(835 &mut self,836 caller: Caller,837 from: eth::CrossAddress,838 to: eth::CrossAddress,839 token_id: U256,840 ) -> Result<()> {841 let caller = T::CrossAccountId::from_eth(caller);842 let from = from.into_sub_cross_account::<T>()?;843 let to = to.into_sub_cross_account::<T>()?;844 let token_id = token_id.try_into()?;845 let budget = self846 .recorder847 .weight_calls_budget(<StructureWeight<T>>::find_parent());848 Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, &budget)849 .map_err(dispatch_to_evm::<T>)?;850 Ok(())851 }852853 /// @notice Burns a specific ERC721 token.854 /// @dev Throws unless `msg.sender` is the current owner or an authorized855 /// operator for this NFT. Throws if `from` is not the current owner. Throws856 /// if `to` is the zero address. Throws if `tokenId` is not a valid NFT.857 /// @param from The current owner of the NFT858 /// @param tokenId The NFT to transfer859 #[solidity(hide)]860 #[weight(<SelfWeightOf<T>>::burn_from())]861 fn burn_from(&mut self, caller: Caller, from: Address, token_id: U256) -> Result<()> {862 let caller = T::CrossAccountId::from_eth(caller);863 let from = T::CrossAccountId::from_eth(from);864 let token = token_id.try_into()?;865 let budget = self866 .recorder867 .weight_calls_budget(<StructureWeight<T>>::find_parent());868869 <Pallet<T>>::burn_from(self, &caller, &from, token, &budget)870 .map_err(dispatch_to_evm::<T>)?;871 Ok(())872 }873874 /// @notice Burns a specific ERC721 token.875 /// @dev Throws unless `msg.sender` is the current owner or an authorized876 /// operator for this NFT. Throws if `from` is not the current owner. Throws877 /// if `to` is the zero address. Throws if `tokenId` is not a valid NFT.878 /// @param from The current owner of the NFT879 /// @param tokenId The NFT to transfer880 #[weight(<SelfWeightOf<T>>::burn_from())]881 fn burn_from_cross(882 &mut self,883 caller: Caller,884 from: eth::CrossAddress,885 token_id: U256,886 ) -> Result<()> {887 let caller = T::CrossAccountId::from_eth(caller);888 let from = from.into_sub_cross_account::<T>()?;889 let token = token_id.try_into()?;890 let budget = self891 .recorder892 .weight_calls_budget(<StructureWeight<T>>::find_parent());893894 <Pallet<T>>::burn_from(self, &caller, &from, token, &budget)895 .map_err(dispatch_to_evm::<T>)?;896 Ok(())897 }898899 /// @notice Returns next free NFT ID.900 fn next_token_id(&self) -> Result<U256> {901 self.consume_store_reads(1)?;902 Ok(<TokensMinted<T>>::get(self.id)903 .checked_add(1)904 .ok_or("item id overflow")?905 .into())906 }907908 /// @notice Function to mint multiple tokens.909 /// @dev `tokenIds` should be an array of consecutive numbers and first number910 /// should be obtained with `nextTokenId` method911 /// @param to The new owner912 /// @param tokenIds IDs of the minted NFTs913 #[solidity(hide)]914 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]915 fn mint_bulk(&mut self, caller: Caller, to: Address, token_ids: Vec<U256>) -> Result<bool> {916 let caller = T::CrossAccountId::from_eth(caller);917 let to = T::CrossAccountId::from_eth(to);918 let mut expected_index = <TokensMinted<T>>::get(self.id)919 .checked_add(1)920 .ok_or("item id overflow")?;921 let budget = self922 .recorder923 .weight_calls_budget(<StructureWeight<T>>::find_parent());924925 let total_tokens = token_ids.len();926 for id in token_ids.into_iter() {927 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;928 if id != expected_index {929 return Err("item id should be next".into());930 }931 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;932 }933 let data = (0..total_tokens)934 .map(|_| CreateItemData::<T> {935 properties: BoundedVec::default(),936 owner: to.clone(),937 })938 .collect();939940 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)941 .map_err(dispatch_to_evm::<T>)?;942 Ok(true)943 }944945 /// @notice Function to mint multiple tokens with the given tokenUris.946 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive947 /// numbers and first number should be obtained with `nextTokenId` method948 /// @param to The new owner949 /// @param tokens array of pairs of token ID and token URI for minted tokens950 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]951 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32) + <SelfWeightOf<T>>::set_token_properties(tokens.len() as u32))]952 fn mint_bulk_with_token_uri(953 &mut self,954 caller: Caller,955 to: Address,956 tokens: Vec<TokenUri>,957 ) -> Result<bool> {958 let key = key::url();959 let caller = T::CrossAccountId::from_eth(caller);960 let to = T::CrossAccountId::from_eth(to);961 let mut expected_index = <TokensMinted<T>>::get(self.id)962 .checked_add(1)963 .ok_or("item id overflow")?;964 let budget = self965 .recorder966 .weight_calls_budget(<StructureWeight<T>>::find_parent());967968 let mut data = Vec::with_capacity(tokens.len());969 for TokenUri { id, uri } in tokens {970 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;971 if id != expected_index {972 return Err("item id should be next".into());973 }974 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;975976 let mut properties = CollectionPropertiesVec::default();977 properties978 .try_push(Property {979 key: key.clone(),980 value: uri981 .into_bytes()982 .try_into()983 .map_err(|_| "token uri is too long")?,984 })985 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;986987 data.push(CreateItemData::<T> {988 properties,989 owner: to.clone(),990 });991 }992993 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)994 .map_err(dispatch_to_evm::<T>)?;995 Ok(true)996 }997998 /// @notice Function to mint a token.999 /// @param to The new owner crossAccountId1000 /// @param properties Properties of minted token1001 /// @return uint256 The id of the newly minted token1002 #[weight(<SelfWeightOf<T>>::create_item() + <SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]1003 fn mint_cross(1004 &mut self,1005 caller: Caller,1006 to: eth::CrossAddress,1007 properties: Vec<eth::Property>,1008 ) -> Result<U256> {1009 let token_id = <TokensMinted<T>>::get(self.id)1010 .checked_add(1)1011 .ok_or("item id overflow")?;10121013 let to = to.into_sub_cross_account::<T>()?;10141015 let properties = properties1016 .into_iter()1017 .map(eth::Property::try_into)1018 .collect::<Result<Vec<_>>>()?1019 .try_into()1020 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;10211022 let caller = T::CrossAccountId::from_eth(caller);10231024 let budget = self1025 .recorder1026 .weight_calls_budget(<StructureWeight<T>>::find_parent());10271028 <Pallet<T>>::create_item(1029 self,1030 &caller,1031 CreateItemData::<T> {1032 properties,1033 owner: to,1034 },1035 &budget,1036 )1037 .map_err(dispatch_to_evm::<T>)?;10381039 Ok(token_id.into())1040 }10411042 /// @notice Returns collection helper contract address1043 fn collection_helper_address(&self) -> Address {1044 T::ContractAddress::get()1045 }1046}10471048#[solidity_interface(1049 name = UniqueNFT,1050 is(1051 ERC721,1052 ERC721Enumerable,1053 ERC721UniqueExtensions,1054 ERC721UniqueMintable,1055 ERC721Burnable,1056 ERC721Metadata(if(this.flags.erc721metadata)),1057 Collection(via(common_mut returns CollectionHandle<T>)),1058 TokenProperties,1059 ),1060 enum(derive(PreDispatch)),1061)]1062impl<T: Config> NonfungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}10631064// Not a tests, but code generators1065generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);1066generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);10671068impl<T: Config> CommonEvmHandler for NonfungibleHandle<T>1069where1070 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,1071{1072 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");10731074 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {1075 call::<T, UniqueNFTCall<T>, _, _>(handle, self)1076 }1077}pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -112,7 +112,7 @@
};
use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_core::H160;
+use sp_core::{Get, H160};
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
use core::ops::Deref;
@@ -622,6 +622,10 @@
stored_properties,
is_token_owner,
|properties| <TokenProperties<T>>::set((collection.id, token_id), properties),
+ erc::ERC721TokenEvent::TokenChanged {
+ token_id: token_id.into(),
+ }
+ .to_log(T::ContractAddress::get()),
)
}
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -17,9 +17,14 @@
}
}
+/// @dev inlined interface
+contract ERC721TokenEvent {
+ event TokenChanged(uint256 indexed tokenId);
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0xde0695c2
-contract TokenProperties is Dummy, ERC165 {
+contract TokenProperties is Dummy, ERC165, ERC721TokenEvent {
// /// @notice Set permissions for token property.
// /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
// /// @param key Property key.
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -59,8 +59,19 @@
pub const ADDRESS_FOR_PARTIALLY_OWNED_TOKENS: H160 = H160::repeat_byte(0xff);
+/// Rft events.
+#[derive(ToLog)]
+pub enum ERC721TokenEvent {
+ /// The token has been changed.
+ TokenChanged {
+ /// Token ID.
+ #[indexed]
+ token_id: U256,
+ },
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
-#[solidity_interface(name = TokenProperties, enum(derive(PreDispatch)), enum_attr(weight))]
+#[solidity_interface(name = TokenProperties, events(ERC721TokenEvent), enum(derive(PreDispatch)), enum_attr(weight))]
impl<T: Config> RefungibleHandle<T> {
/// @notice Set permissions for token property.
/// @dev Throws error if `msg.sender` is not admin or owner of the collection.
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -100,7 +100,7 @@
Event as CommonEvent, Pallet as PalletCommon,
};
use pallet_structure::Pallet as PalletStructure;
-use sp_core::H160;
+use sp_core::{Get, H160};
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
use up_data_structs::{
@@ -571,6 +571,10 @@
stored_properties,
is_token_owner,
|properties| <TokenProperties<T>>::set((collection.id, token_id), properties),
+ erc::ERC721TokenEvent::TokenChanged {
+ token_id: token_id.into(),
+ }
+ .to_log(T::ContractAddress::get()),
)
}
pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -17,9 +17,14 @@
}
}
+/// @dev inlined interface
+contract ERC721TokenEvent {
+ event TokenChanged(uint256 indexed tokenId);
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0xde0695c2
-contract TokenProperties is Dummy, ERC165 {
+contract TokenProperties is Dummy, ERC165, ERC721TokenEvent {
// /// @notice Set permissions for token property.
// /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
// /// @param key Property key.
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -22,7 +22,6 @@
event CollectionCreated(address indexed owner, address indexed collectionId);
event CollectionDestroyed(address indexed collectionId);
event CollectionChanged(address indexed collectionId);
- event TokenChanged(address indexed collectionId, uint256 tokenId);
}
/// @title Contract, which allows users to operate with collections
tests/src/eth/abi/collectionHelpers.jsondiffbeforeafterboth--- a/tests/src/eth/abi/collectionHelpers.json
+++ b/tests/src/eth/abi/collectionHelpers.json
@@ -45,25 +45,6 @@
"type": "event"
},
{
- "anonymous": false,
- "inputs": [
- {
- "indexed": true,
- "internalType": "address",
- "name": "collectionId",
- "type": "address"
- },
- {
- "indexed": false,
- "internalType": "uint256",
- "name": "tokenId",
- "type": "uint256"
- }
- ],
- "name": "TokenChanged",
- "type": "event"
- },
- {
"inputs": [
{ "internalType": "uint32", "name": "collectionId", "type": "uint32" }
],
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -54,6 +54,19 @@
"inputs": [
{
"indexed": true,
+ "internalType": "uint256",
+ "name": "tokenId",
+ "type": "uint256"
+ }
+ ],
+ "name": "TokenChanged",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -54,6 +54,19 @@
"inputs": [
{
"indexed": true,
+ "internalType": "uint256",
+ "name": "tokenId",
+ "type": "uint256"
+ }
+ ],
+ "name": "TokenChanged",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -17,7 +17,6 @@
event CollectionCreated(address indexed owner, address indexed collectionId);
event CollectionDestroyed(address indexed collectionId);
event CollectionChanged(address indexed collectionId);
- event TokenChanged(address indexed collectionId, uint256 tokenId);
}
/// @title Contract, which allows users to operate with collections
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -12,9 +12,14 @@
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
+/// @dev inlined interface
+interface ERC721TokenEvent {
+ event TokenChanged(uint256 indexed tokenId);
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0xde0695c2
-interface TokenProperties is Dummy, ERC165 {
+interface TokenProperties is Dummy, ERC165, ERC721TokenEvent {
// /// @notice Set permissions for token property.
// /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
// /// @param key Property key.
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -12,9 +12,14 @@
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
+/// @dev inlined interface
+interface ERC721TokenEvent {
+ event TokenChanged(uint256 indexed tokenId);
+}
+
/// @title A contract that allows to set and delete token properties and change token property permissions.
/// @dev the ERC-165 identifier for this interface is 0xde0695c2
-interface TokenProperties is Dummy, ERC165 {
+interface TokenProperties is Dummy, ERC165, ERC721TokenEvent {
// /// @notice Set permissions for token property.
// /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
// /// @param key Property key.
tests/src/eth/events.test.tsdiffbeforeafterboth--- a/tests/src/eth/events.test.ts
+++ b/tests/src/eth/events.test.ts
@@ -29,8 +29,10 @@
});
});
-function clearEvents(ethEvents: NormalizedEvent[], subEvents: IEvent[]) {
- ethEvents.splice(0);
+function clearEvents(ethEvents: NormalizedEvent[] | null, subEvents: IEvent[]) {
+ if (ethEvents !== null) {
+ ethEvents.splice(0);
+ }
subEvents.splice(0);
}
@@ -374,7 +376,6 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
- const collectionHelper = await helper.ethNativeContract.collectionHelpers(owner);
const result = await collection.methods.mint(owner).send({from: owner});
const tokenId = result.events.Transfer.returnValues.tokenId;
await collection.methods.setTokenPropertyPermissions([
@@ -384,38 +385,29 @@
[TokenPermissionField.CollectionAdmin, true]],
],
]).send({from: owner});
-
- const ethEvents: any = [];
- collectionHelper.events.allEvents((_: any, event: any) => {
- ethEvents.push(event);
- });
const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['TokenPropertySet', 'TokenPropertyDeleted']}]);
{
- await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
+ const result = await collection.methods.setProperties(tokenId, [{key: 'A', value: [1,2,3]}]).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.containSubset([
- {
- event: 'TokenChanged',
- returnValues: {
- collectionId: collectionAddress,
- },
+ expect(result.events.TokenChanged).to.be.like({
+ event: 'TokenChanged',
+ returnValues: {
+ tokenId: tokenId,
},
- ]);
+ });
expect(subEvents).to.containSubset([{method: 'TokenPropertySet'}]);
- clearEvents(ethEvents, subEvents);
+ clearEvents(null, subEvents);
}
{
- await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
+ const result = await collection.methods.deleteProperties(tokenId, ['A']).send({from: owner});
await helper.wait.newBlocks(1);
- expect(ethEvents).to.containSubset([
- {
- event: 'TokenChanged',
- returnValues: {
- collectionId: collectionAddress,
- },
+ expect(result.events.TokenChanged).to.be.like({
+ event: 'TokenChanged',
+ returnValues: {
+ tokenId: tokenId,
},
- ]);
+ });
expect(subEvents).to.containSubset([{method: 'TokenPropertyDeleted'}]);
}
unsubscribe();