Refactor sr-api to not depend on client anymore (#4086)

* Refactor sr-api to not depend on client anymore

* Fix benches

* Apply suggestions from code review

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Apply suggestions from code review
This commit is contained in:
Bastian Köcher
2019-11-11 16:26:49 +01:00
committed by Benjamin Kampmann
parent e26d1a0b3e
commit 2ecffa1cd0
140 changed files with 1514 additions and 984 deletions
+134 -52
View File
@@ -125,7 +125,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -785,7 +785,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1074,7 +1074,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1308,7 +1308,7 @@ dependencies = [
"proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1746,7 +1746,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -1855,7 +1855,7 @@ dependencies = [
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -2806,6 +2806,7 @@ dependencies = [
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"sr-staking-primitives 2.0.0",
@@ -2840,12 +2841,14 @@ dependencies = [
"srml-transaction-payment-rpc-runtime-api 2.0.0",
"srml-treasury 2.0.0",
"srml-utility 2.0.0",
"substrate-client 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-consensus-babe-primitives 2.0.0",
"substrate-inherents 2.0.0",
"substrate-keyring 2.0.0",
"substrate-offchain-primitives 2.0.0",
"substrate-primitives 2.0.0",
"substrate-session 2.0.0",
"substrate-transaction-pool-runtime-api 2.0.0",
"substrate-wasm-builder-runner 1.0.4",
]
@@ -2889,6 +2892,7 @@ dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
@@ -2904,11 +2908,13 @@ dependencies = [
"srml-system 2.0.0",
"srml-timestamp 2.0.0",
"srml-transaction-payment 2.0.0",
"substrate-client 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-consensus-aura-primitives 2.0.0",
"substrate-inherents 2.0.0",
"substrate-offchain-primitives 2.0.0",
"substrate-primitives 2.0.0",
"substrate-session 2.0.0",
"substrate-transaction-pool-runtime-api 2.0.0",
"substrate-wasm-builder-runner 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -3274,7 +3280,7 @@ dependencies = [
"proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -3372,7 +3378,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -3382,7 +3388,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -3901,7 +3907,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4064,7 +4070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4228,24 +4234,47 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sr-api-macros"
name = "sr-api"
version = "2.0.0"
dependencies = [
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api-proc-macro 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"sr-version 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-common 2.0.0",
"substrate-primitives 2.0.0",
"substrate-state-machine 2.0.0",
"substrate-test-runtime-client 2.0.0",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sr-api-proc-macro"
version = "2.0.0"
dependencies = [
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-version 2.0.0",
"substrate-test-runtime-client 2.0.0",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sr-api-test"
version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-version 2.0.0",
"substrate-consensus-common 2.0.0",
"substrate-state-machine 2.0.0",
"substrate-test-runtime-client 2.0.0",
"trybuild 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -4296,6 +4325,7 @@ dependencies = [
"sr-io 2.0.0",
"sr-std 2.0.0",
"substrate-application-crypto 2.0.0",
"substrate-inherents 2.0.0",
"substrate-offchain 2.0.0",
"substrate-primitives 2.0.0",
]
@@ -4510,9 +4540,9 @@ version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-client 2.0.0",
]
[[package]]
@@ -4838,7 +4868,7 @@ dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4884,9 +4914,8 @@ version = "2.0.0"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api-macros 2.0.0",
"srml-support-procedural-tools 2.0.0",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4897,7 +4926,7 @@ dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"srml-support-procedural-tools-derive 2.0.0",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4906,7 +4935,7 @@ version = "2.0.0"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4983,7 +5012,7 @@ name = "srml-system-rpc-runtime-api"
version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-client 2.0.0",
"sr-api 2.0.0",
]
[[package]]
@@ -5039,9 +5068,9 @@ version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-client 2.0.0",
]
[[package]]
@@ -5136,7 +5165,7 @@ dependencies = [
"proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -5204,6 +5233,7 @@ dependencies = [
"prost 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prost-build 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"substrate-authority-discovery-primitives 2.0.0",
"substrate-client 2.0.0",
@@ -5218,9 +5248,9 @@ name = "substrate-authority-discovery-primitives"
version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-client 2.0.0",
]
[[package]]
@@ -5231,6 +5261,7 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"substrate-block-builder 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-common 2.0.0",
"substrate-inherents 2.0.0",
@@ -5251,6 +5282,28 @@ dependencies = [
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "substrate-block-builder"
version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-primitives 2.0.0",
"substrate-state-machine 2.0.0",
]
[[package]]
name = "substrate-block-builder-runtime-api"
version = "2.0.0"
dependencies = [
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-inherents 2.0.0",
]
[[package]]
name = "substrate-build-script-utils"
version = "2.0.0"
@@ -5276,7 +5329,7 @@ dependencies = [
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -5331,10 +5384,11 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api-macros 2.0.0",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"sr-version 2.0.0",
"substrate-block-builder 2.0.0",
"substrate-client-db 2.0.0",
"substrate-consensus-common 2.0.0",
"substrate-executor 2.0.0",
@@ -5388,12 +5442,14 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"sr-version 2.0.0",
"srml-aura 2.0.0",
"srml-support 2.0.0",
"substrate-application-crypto 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-aura-primitives 2.0.0",
"substrate-consensus-common 2.0.0",
@@ -5416,10 +5472,10 @@ name = "substrate-consensus-aura-primitives"
version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-application-crypto 2.0.0",
"substrate-client 2.0.0",
]
[[package]]
@@ -5442,12 +5498,15 @@ dependencies = [
"pdqselect 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"sr-version 2.0.0",
"srml-babe 2.0.0",
"srml-support 2.0.0",
"substrate-application-crypto 2.0.0",
"substrate-block-builder 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-babe-primitives 2.0.0",
"substrate-consensus-common 2.0.0",
@@ -5473,10 +5532,10 @@ version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"schnorrkel 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-application-crypto 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-slots 2.0.0",
]
@@ -5509,6 +5568,7 @@ dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"srml-timestamp 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-common 2.0.0",
"substrate-consensus-pow-primitives 2.0.0",
@@ -5521,9 +5581,9 @@ name = "substrate-consensus-pow-primitives"
version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-client 2.0.0",
"substrate-primitives 2.0.0",
]
@@ -5588,7 +5648,7 @@ version = "2.0.0"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -5655,6 +5715,7 @@ dependencies = [
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"srml-finality-tracker 2.0.0",
"substrate-client 2.0.0",
@@ -5682,10 +5743,10 @@ version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-application-crypto 2.0.0",
"substrate-client 2.0.0",
]
[[package]]
@@ -5701,10 +5762,11 @@ dependencies = [
name = "substrate-inherents"
version = "2.0.0"
dependencies = [
"derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-primitives 2.0.0",
]
[[package]]
@@ -5764,6 +5826,7 @@ dependencies = [
"slog_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"substrate-block-builder 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-babe-primitives 2.0.0",
"substrate-consensus-common 2.0.0",
@@ -5799,6 +5862,7 @@ dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"substrate-client 2.0.0",
"substrate-client-db 2.0.0",
@@ -5816,8 +5880,8 @@ dependencies = [
name = "substrate-offchain-primitives"
version = "2.0.0"
dependencies = [
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"substrate-client 2.0.0",
]
[[package]]
@@ -5920,6 +5984,7 @@ dependencies = [
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"sr-version 2.0.0",
@@ -6011,7 +6076,7 @@ dependencies = [
"rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-externalities 2.0.0",
"substrate-runtime-interface 2.0.0",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"trybuild 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -6065,6 +6130,7 @@ dependencies = [
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"substrate-application-crypto 2.0.0",
@@ -6086,6 +6152,7 @@ dependencies = [
"substrate-telemetry 2.0.0",
"substrate-test-runtime-client 2.0.0",
"substrate-transaction-pool 2.0.0",
"substrate-transaction-pool-runtime-api 2.0.0",
"sysinfo 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -6116,10 +6183,9 @@ dependencies = [
name = "substrate-session"
version = "2.0.0"
dependencies = [
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
"substrate-client 2.0.0",
"substrate-primitives 2.0.0",
]
[[package]]
@@ -6199,6 +6265,7 @@ dependencies = [
"memory-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-io 2.0.0",
"sr-primitives 2.0.0",
"sr-std 2.0.0",
@@ -6210,6 +6277,7 @@ dependencies = [
"srml-system-rpc-runtime-api 2.0.0",
"srml-timestamp 2.0.0",
"substrate-application-crypto 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-aura-primitives 2.0.0",
"substrate-consensus-babe-primitives 2.0.0",
@@ -6222,6 +6290,7 @@ dependencies = [
"substrate-session 2.0.0",
"substrate-state-machine 2.0.0",
"substrate-test-runtime-client 2.0.0",
"substrate-transaction-pool-runtime-api 2.0.0",
"substrate-trie 2.0.0",
"substrate-wasm-builder-runner 1.0.4",
"trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -6233,6 +6302,7 @@ version = "2.0.0"
dependencies = [
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-primitives 2.0.0",
"substrate-block-builder 2.0.0",
"substrate-primitives 2.0.0",
"substrate-test-client 2.0.0",
"substrate-test-runtime 2.0.0",
@@ -6265,12 +6335,22 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"substrate-client 2.0.0",
"substrate-keyring 2.0.0",
"substrate-primitives 2.0.0",
"substrate-test-runtime-client 2.0.0",
"substrate-transaction-graph 2.0.0",
"substrate-transaction-pool-runtime-api 2.0.0",
]
[[package]]
name = "substrate-transaction-pool-runtime-api"
version = "2.0.0"
dependencies = [
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"substrate-primitives 2.0.0",
]
[[package]]
@@ -6344,7 +6424,7 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -6370,7 +6450,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -6444,7 +6524,7 @@ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -6745,7 +6825,9 @@ version = "0.0.1"
dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-api 2.0.0",
"sr-primitives 2.0.0",
"substrate-block-builder-runtime-api 2.0.0",
"substrate-cli 2.0.0",
"substrate-client 2.0.0",
"substrate-consensus-common 2.0.0",
@@ -7039,7 +7121,7 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -7071,7 +7153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -7091,7 +7173,7 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -7889,7 +7971,7 @@ dependencies = [
"checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee"
"checksum subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab3af2eb31c42e8f0ccf43548232556c42737e01a96db6e1777b0be108e79799"
"checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
"checksum syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7bedb3320d0f3035594b0b723c8a28d7d336a3eda3881db79e61d676fb644c"
"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
"checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203"
"checksum sysinfo 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d5bd3b813d94552a8033c650691645f8dd5a63d614dddd62428a95d3931ef7b6"
+6 -1
View File
@@ -15,6 +15,8 @@ members = [
"core/consensus/slots",
"core/consensus/uncles",
"core/consensus/pow",
"core/block-builder",
"core/block-builder/runtime-api",
"core/executor",
"core/executor/runtime-test",
"core/externalities",
@@ -36,7 +38,9 @@ members = [
"core/service",
"core/service/test",
"core/session",
"core/sr-api-macros",
"core/sr-api",
"core/sr-api/proc-macro",
"core/sr-api/test",
"core/sr-arithmetic",
"core/sr-io",
"core/sr-primitives",
@@ -51,6 +55,7 @@ members = [
"core/test-runtime/client",
"core/transaction-pool",
"core/transaction-pool/graph",
"core/transaction-pool/runtime-api",
"core/trie",
"core/utils/fork-tree",
"core/utils/wasm-builder",
@@ -28,3 +28,4 @@ futures-timer = "0.4"
parking_lot = "0.9.0"
peerset = { package = "substrate-peerset", path = "../../core/peerset" }
test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" }
sr-api = { path = "../sr-api" }
@@ -7,15 +7,15 @@ edition = "2018"
[dependencies]
codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" }
client = { package = "substrate-client", path = "../../client", default-features = false }
sr-api = { path = "../../sr-api", default-features = false }
sr-primitives = { path = "../../sr-primitives", default-features = false }
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
[features]
default = ["std"]
std = [
"rstd/std",
"client/std",
"codec/std",
"sr-primitives/std"
"rstd/std",
"sr-api/std",
"codec/std",
"sr-primitives/std"
]
@@ -18,7 +18,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
use client::decl_runtime_apis;
use rstd::vec::Vec;
use sr_primitives::RuntimeDebug;
@@ -29,7 +28,7 @@ pub struct Signature(pub Vec<u8>);
#[cfg_attr(feature = "std", derive(Hash))]
pub struct AuthorityId(pub Vec<u8>);
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// The authority discovery api.
///
/// This api is used by the `core/authority-discovery` module to retrieve our
@@ -105,7 +105,7 @@ where
Block: BlockT + Unpin + 'static,
Network: NetworkProvider,
Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend<Block>,
<Client as ProvideRuntimeApi>::Api: AuthorityDiscoveryApi<Block>,
<Client as ProvideRuntimeApi>::Api: AuthorityDiscoveryApi<Block, Error = client::error::Error>,
Self: Future<Output = ()>,
{
/// Return a new authority discovery.
@@ -303,7 +303,7 @@ where
Block: BlockT + Unpin + 'static,
Network: NetworkProvider,
Client: ProvideRuntimeApi + Send + Sync + 'static + HeaderBackend<Block>,
<Client as ProvideRuntimeApi>::Api: AuthorityDiscoveryApi<Block>,
<Client as ProvideRuntimeApi>::Api: AuthorityDiscoveryApi<Block, Error = client::error::Error>,
{
type Output = ();
@@ -404,7 +404,7 @@ fn hash_authority_id(id: &[u8]) -> Result<libp2p::kad::record::Key> {
#[cfg(test)]
mod tests {
use super::*;
use client::runtime_api::{ApiExt, Core, RuntimeVersion, StorageProof};
use sr_api::{ApiExt, Core, RuntimeVersion, StorageProof};
use futures::channel::mpsc::channel;
use futures::executor::block_on;
use futures::future::poll_fn;
@@ -501,6 +501,8 @@ mod tests {
}
impl ApiExt<Block> for RuntimeApi {
type Error = client::error::Error;
fn map_api_result<F: FnOnce(&Self) -> std::result::Result<R, E>, R, E>(
&self,
_: F,
+2 -1
View File
@@ -14,7 +14,8 @@ client = { package = "substrate-client", path = "../../core/client" }
consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
inherents = { package = "substrate-inherents", path = "../inherents" }
substrate-telemetry = { path = "../telemetry" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" }
transaction_pool = { package = "substrate-transaction-pool", path = "../transaction-pool" }
block-builder = { package = "substrate-block-builder", path = "../block-builder" }
[dev-dependencies]
test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" }
@@ -20,10 +20,7 @@
//
use std::{time, sync::Arc};
use client::{
error, Client as SubstrateClient, CallExecutor,
block_builder::api::BlockBuilder as BlockBuilderApi,
};
use client::{error, Client as SubstrateClient, CallExecutor};
use codec::Decode;
use consensus_common::{evaluation};
use inherents::InherentData;
@@ -37,6 +34,7 @@ use sr_primitives::{
};
use transaction_pool::txpool::{self, Pool as TransactionPool};
use substrate_telemetry::{telemetry, CONSENSUS_INFO};
use block_builder::BlockBuilderApi;
/// Proposer factory.
pub struct ProposerFactory<C, A> where A: txpool::ChainApi {
@@ -55,7 +53,8 @@ where
Block: BlockT<Hash=H256>,
RA: Send + Sync + 'static,
SubstrateClient<B, E, Block, RA>: ProvideRuntimeApi,
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi>::Api: BlockBuilderApi<Block>,
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi>::Api:
BlockBuilderApi<Block, Error = client::error::Error>,
{
type Proposer = Proposer<Block, SubstrateClient<B, E, Block, RA>, A>;
type Error = error::Error;
@@ -102,7 +101,8 @@ where
Block: BlockT<Hash=H256>,
RA: Send + Sync + 'static,
SubstrateClient<B, E, Block, RA>: ProvideRuntimeApi,
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi>::Api: BlockBuilderApi<Block>,
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi>::Api:
BlockBuilderApi<Block, Error = client::error::Error>,
{
type Create = futures::future::Ready<Result<Block, error::Error>>;
type Error = error::Error;
@@ -126,7 +126,8 @@ impl<Block, B, E, RA, A> Proposer<Block, SubstrateClient<B, E, Block, RA>, A> wh
Block: BlockT<Hash=H256>,
RA: Send + Sync + 'static,
SubstrateClient<B, E, Block, RA>: ProvideRuntimeApi,
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi>::Api: BlockBuilderApi<Block>,
<SubstrateClient<B, E, Block, RA> as ProvideRuntimeApi>::Api:
BlockBuilderApi<Block, Error = client::error::Error>,
{
fn propose_with(
&self,
@@ -167,7 +168,7 @@ impl<Block, B, E, RA, A> Proposer<Block, SubstrateClient<B, E, Block, RA>, A> wh
}
trace!("[{:?}] Pushing to the block.", pending.hash);
match client::block_builder::BlockBuilder::push(&mut block_builder, pending.data.clone()) {
match block_builder::BlockBuilder::push(&mut block_builder, pending.data.clone()) {
Ok(()) => {
debug!("[{:?}] Pushed to the block.", pending.hash);
}
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "substrate-block-builder"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
state-machine = { package = "substrate-state-machine", path = "../state-machine" }
sr-primitives = { path = "../sr-primitives" }
primitives = { package = "substrate-primitives", path = "../primitives" }
codec = { package = "parity-scale-codec", version = "1.0.6", features = ["derive"] }
runtime_api = { package = "substrate-block-builder-runtime-api", path = "runtime-api" }
sr-api = { path = "../sr-api" }
@@ -0,0 +1,20 @@
[package]
name = "substrate-block-builder-runtime-api"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
sr-primitives = { path = "../../sr-primitives", default-features = false }
sr-api = { path = "../../sr-api", default-features = false }
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
inherents = { package = "substrate-inherents", path = "../../inherents", default-features = false }
[features]
default = [ "std" ]
std = [
"sr-primitives/std",
"inherents/std",
"sr-api/std",
"rstd/std",
]
@@ -1,4 +1,4 @@
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
@@ -14,15 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! The runtime api for building blocks.
//! The block builder runtime api.
#![cfg_attr(not(feature = "std"), no_std)]
use sr_primitives::{traits::Block as BlockT, ApplyResult};
use rstd::vec::Vec;
use sr_api_macros::decl_runtime_apis;
pub use inherents::{InherentData, CheckInherentsResult};
decl_runtime_apis! {
/// The `BlockBuilder` api trait that provides required functions for building a block for a runtime.
use inherents::{InherentData, CheckInherentsResult};
sr_api::decl_runtime_apis! {
/// The `BlockBuilder` api trait that provides the required functionality for building a block.
#[api_version(3)]
pub trait BlockBuilder {
/// Apply the given extrinsics.
@@ -31,7 +32,9 @@ decl_runtime_apis! {
#[renamed("finalise_block", 3)]
fn finalize_block() -> <Block as BlockT>::Header;
/// Generate inherent extrinsics. The inherent data will vary from chain to chain.
fn inherent_extrinsics(inherent: InherentData) -> Vec<<Block as BlockT>::Extrinsic>;
fn inherent_extrinsics(
inherent: InherentData,
) -> rstd::vec::Vec<<Block as BlockT>::Extrinsic>;
/// Check that the inherents are valid. The inherent data will vary from chain to chain.
fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult;
/// Generate a random seed.
@@ -14,59 +14,66 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use super::api::BlockBuilder as BlockBuilderApi;
use std::vec::Vec;
//! Substrate block builder
//!
//! This crate provides the [`BlockBuilder`] utility and the corresponding runtime api
//! [`BlockBuilder`](api::BlockBuilder).
//!
//! The block builder utility is used in the node as an abstraction over the runtime api to
//! initialize a block, to push extrinsics and to finalize a block.
#![warn(missing_docs)]
use codec::Encode;
use sr_primitives::generic::BlockId;
use sr_primitives::traits::{
Header as HeaderT, Hash, Block as BlockT, One, HashFor, ProvideRuntimeApi, ApiRef, DigestFor,
use sr_primitives::{
generic::BlockId,
traits::{
Header as HeaderT, Hash, Block as BlockT, HashFor, ProvideRuntimeApi, ApiRef, DigestFor,
NumberFor, One,
},
};
use primitives::{H256, ExecutionContext};
use primitives::ExecutionContext;
use state_machine::StorageProof;
use crate::blockchain::HeaderBackend;
use crate::runtime_api::{Core, ApiExt};
use crate::error;
use sr_api::{Core, ApiExt, ApiErrorFor};
pub use runtime_api::BlockBuilder as BlockBuilderApi;
/// Error when the runtime failed to apply an extrinsic.
pub struct ApplyExtrinsicFailed(pub sr_primitives::ApplyError);
/// Utility for building new (valid) blocks from a stream of extrinsics.
pub struct BlockBuilder<'a, Block, A: ProvideRuntimeApi> where Block: BlockT {
header: <Block as BlockT>::Header,
extrinsics: Vec<<Block as BlockT>::Extrinsic>,
pub struct BlockBuilder<'a, Block: BlockT, A: ProvideRuntimeApi> {
header: Block::Header,
extrinsics: Vec<Block::Extrinsic>,
api: ApiRef<'a, A::Api>,
block_id: BlockId<Block>,
}
impl<'a, Block, A> BlockBuilder<'a, Block, A>
where
Block: BlockT<Hash=H256>,
A: ProvideRuntimeApi + HeaderBackend<Block> + 'a,
Block: BlockT,
A: ProvideRuntimeApi + 'a,
A::Api: BlockBuilderApi<Block>,
ApiErrorFor<A, Block>: From<ApplyExtrinsicFailed>,
{
/// Create a new instance of builder from the given client, building on the
/// latest block.
pub fn new(api: &'a A, inherent_digests: DigestFor<Block>) -> error::Result<Self> {
Self::at_block(&BlockId::Hash(api.info().best_hash), api, false, inherent_digests)
}
/// Create a new instance of builder from the given client using a
/// particular block's ID to build upon with optional proof recording enabled.
/// Create a new instance of builder based on the given `parent_hash` and `parent_number`.
///
/// While proof recording is enabled, all accessed trie nodes are saved.
/// These recorded trie nodes can be used by a third party to prove the
/// output of this block builder without having access to the full storage.
pub fn at_block(
block_id: &BlockId<Block>,
pub fn new(
api: &'a A,
parent_hash: Block::Hash,
parent_number: NumberFor<Block>,
proof_recording: bool,
inherent_digests: DigestFor<Block>,
) -> error::Result<Self> {
let number = api.block_number_from_id(block_id)?
.ok_or_else(|| error::Error::UnknownBlock(format!("{}", block_id)))?
+ One::one();
let parent_hash = api.block_hash_from_id(block_id)?
.ok_or_else(|| error::Error::UnknownBlock(format!("{}", block_id)))?;
) -> Result<Self, ApiErrorFor<A, Block>> {
let header = <<Block as BlockT>::Header as HeaderT>::new(
number,
parent_number + One::one(),
Default::default(),
Default::default(),
parent_hash,
@@ -79,22 +86,24 @@ where
api.record_proof();
}
let block_id = BlockId::Hash(parent_hash);
api.initialize_block_with_context(
block_id, ExecutionContext::BlockConstruction, &header,
&block_id, ExecutionContext::BlockConstruction, &header,
)?;
Ok(BlockBuilder {
Ok(Self {
header,
extrinsics: Vec::new(),
api,
block_id: *block_id,
block_id,
})
}
/// Push onto the block's list of extrinsics.
///
/// This will ensure the extrinsic can be validly executed (by executing it);
pub fn push(&mut self, xt: <Block as BlockT>::Extrinsic) -> error::Result<()> {
pub fn push(&mut self, xt: <Block as BlockT>::Extrinsic) -> Result<(), ApiErrorFor<A, Block>> {
let block_id = &self.block_id;
let extrinsics = &mut self.extrinsics;
@@ -109,19 +118,19 @@ where
Ok(())
}
Err(e) => {
Err(error::Error::ApplyExtrinsicFailed(e))
Err(ApplyExtrinsicFailed(e))?
}
}
})
}
/// Consume the builder to return a valid `Block` containing all pushed extrinsics.
pub fn bake(mut self) -> error::Result<Block> {
pub fn bake(mut self) -> Result<Block, ApiErrorFor<A, Block>> {
self.bake_impl()?;
Ok(<Block as BlockT>::new(self.header, self.extrinsics))
}
fn bake_impl(&mut self) -> error::Result<()> {
fn bake_impl(&mut self) -> Result<(), ApiErrorFor<A, Block>> {
self.header = self.api.finalize_block_with_context(
&self.block_id, ExecutionContext::BlockConstruction
)?;
@@ -141,7 +150,9 @@ where
///
/// The proof will be `Some(_)`, if proof recording was enabled while creating
/// the block builder.
pub fn bake_and_extract_proof(mut self) -> error::Result<(Block, Option<StorageProof>)> {
pub fn bake_and_extract_proof(mut self)
-> Result<(Block, Option<StorageProof>), ApiErrorFor<A, Block>>
{
self.bake_impl()?;
let proof = self.api.extract_proof();
+24 -49
View File
@@ -5,29 +5,30 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
derive_more = { version = "0.15.0", optional = true }
fnv = { version = "1.0.6", optional = true }
log = { version = "0.4.8", optional = true }
parking_lot = { version = "0.9.0", optional = true }
hex-literal = { version = "0.2.1", optional = true }
futures = { version = "0.1.29", optional = true }
futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"], optional = true }
consensus = { package = "substrate-consensus-common", path = "../consensus/common", optional = true }
executor = { package = "substrate-executor", path = "../executor", optional = true }
state-machine = { package = "substrate-state-machine", path = "../state-machine", optional = true }
keyring = { package = "substrate-keyring", path = "../keyring", optional = true }
trie = { package = "substrate-trie", path = "../trie", optional = true }
substrate-telemetry = { path = "../telemetry", optional = true }
hash-db = { version = "0.15.2", default-features = false }
kvdb = { git = "https://github.com/paritytech/parity-common", optional = true, rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
sr-primitives = { path = "../sr-primitives", default-features = false }
runtime-version = { package = "sr-version", path = "../sr-version", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
inherents = { package = "substrate-inherents", path = "../inherents", default-features = false }
sr-api-macros = { path = "../sr-api-macros" }
header-metadata = { package = "substrate-header-metadata", path = "header-metadata", optional = true }
derive_more = { version = "0.15.0" }
fnv = { version = "1.0.6" }
log = { version = "0.4.8" }
parking_lot = { version = "0.9.0" }
hex-literal = { version = "0.2.1" }
futures = { version = "0.1.29" }
futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] }
consensus = { package = "substrate-consensus-common", path = "../consensus/common" }
executor = { package = "substrate-executor", path = "../executor" }
state-machine = { package = "substrate-state-machine", path = "../state-machine" }
keyring = { package = "substrate-keyring", path = "../keyring" }
trie = { package = "substrate-trie", path = "../trie" }
substrate-telemetry = { path = "../telemetry" }
hash-db = { version = "0.15.2" }
kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../primitives" }
sr-primitives = { path = "../sr-primitives" }
runtime-version = { package = "sr-version", path = "../sr-version" }
rstd = { package = "sr-std", path = "../sr-std" }
inherents = { package = "substrate-inherents", path = "../inherents" }
sr-api = { path = "../sr-api" }
header-metadata = { package = "substrate-header-metadata", path = "header-metadata" }
block-builder = { package = "substrate-block-builder", path = "../block-builder" }
[dev-dependencies]
env_logger = "0.7.0"
@@ -37,29 +38,3 @@ test-client = { package = "substrate-test-runtime-client", path = "../test-runti
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" }
[features]
default = ["std"]
std = [
"rstd/std",
"codec/std",
"primitives/std",
"inherents/std",
"sr-primitives/std",
"runtime-version/std",
"hash-db/std",
"header-metadata",
"consensus",
"parking_lot",
"derive_more",
"fnv",
"log",
"hex-literal",
"futures",
"futures03",
"executor",
"state-machine",
"keyring",
"trie",
"substrate-telemetry",
"kvdb"
]
+1 -1
View File
@@ -30,7 +30,7 @@ use primitives::{
traits::{CodeExecutor, KeystoreExt},
};
use crate::runtime_api::{ProofRecorder, InitializeBlock};
use sr_api::{ProofRecorder, InitializeBlock};
use crate::backend;
use crate::error;
+50 -15
View File
@@ -53,11 +53,10 @@ use consensus::{
};
use header_metadata::{HeaderMetadata, CachedHeaderMetadata};
use sr_api::{CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder, InitializeBlock};
use block_builder::BlockBuilderApi;
use crate::{
runtime_api::{
CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder,
InitializeBlock,
},
backend::{
self, BlockImportOperation, PrunableStateChangesTrieStorage,
ClientImportOperation, Finalizer, ImportSummary,
@@ -70,9 +69,7 @@ use crate::{
call_executor::{CallExecutor, LocalCallExecutor},
notifications::{StorageNotifications, StorageEventStream},
light::{call_executor::prove_execution, fetcher::ChangesProof},
block_builder::{self, api::BlockBuilder as BlockBuilderAPI},
error::Error,
cht, error, in_mem, genesis
error::Error, cht, error, in_mem, genesis
};
/// Type that implements `futures::Stream` of block import events.
@@ -749,9 +746,16 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
E: Clone + Send + Sync,
RA: Send + Sync,
Self: ProvideRuntimeApi,
<Self as ProvideRuntimeApi>::Api: BlockBuilderAPI<Block>
<Self as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, Error = Error>
{
block_builder::BlockBuilder::new(self, inherent_digests)
let info = self.info();
block_builder::BlockBuilder::new(
self,
info.chain.best_hash,
info.chain.best_number,
false,
inherent_digests,
)
}
/// Create a new block, built on top of `parent`.
@@ -763,9 +767,15 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
E: Clone + Send + Sync,
RA: Send + Sync,
Self: ProvideRuntimeApi,
<Self as ProvideRuntimeApi>::Api: BlockBuilderAPI<Block>
<Self as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, Error = Error>
{
block_builder::BlockBuilder::at_block(parent, &self, false, inherent_digests)
block_builder::BlockBuilder::new(
self,
self.expect_block_hash_from_id(parent)?,
self.expect_block_number_from_id(parent)?,
false,
inherent_digests,
)
}
/// Create a new block, built on top of `parent` with proof recording enabled.
@@ -781,9 +791,15 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
E: Clone + Send + Sync,
RA: Send + Sync,
Self: ProvideRuntimeApi,
<Self as ProvideRuntimeApi>::Api: BlockBuilderAPI<Block>
<Self as ProvideRuntimeApi>::Api: BlockBuilderApi<Block, Error = Error>
{
block_builder::BlockBuilder::at_block(parent, &self, true, inherent_digests)
block_builder::BlockBuilder::new(
self,
self.expect_block_hash_from_id(parent)?,
self.expect_block_number_from_id(parent)?,
true,
inherent_digests,
)
}
/// Lock the import lock, and run operations inside.
@@ -1367,7 +1383,7 @@ impl<B, E, Block, RA> ChainHeaderBackend<Block> for Client<B, E, Block, RA> wher
B: backend::Backend<Block, Blake2Hasher>,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
Block: BlockT<Hash=H256>,
RA: Send + Sync
RA: Send + Sync,
{
fn header(&self, id: BlockId<Block>) -> error::Result<Option<Block::Header>> {
self.backend.blockchain().header(id)
@@ -1390,6 +1406,23 @@ impl<B, E, Block, RA> ChainHeaderBackend<Block> for Client<B, E, Block, RA> wher
}
}
impl<B, E, Block, RA> sr_primitives::traits::BlockIdTo<Block> for Client<B, E, Block, RA> where
B: backend::Backend<Block, Blake2Hasher>,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
Block: BlockT<Hash=H256>,
RA: Send + Sync,
{
type Error = Error;
fn to_hash(&self, block_id: &BlockId<Block>) -> error::Result<Option<Block::Hash>> {
self.block_hash_from_id(block_id)
}
fn to_number(&self, block_id: &BlockId<Block>) -> error::Result<Option<NumberFor<Block>>> {
self.block_number_from_id(block_id)
}
}
impl<B, E, Block, RA> ChainHeaderBackend<Block> for &Client<B, E, Block, RA> where
B: backend::Backend<Block, Blake2Hasher>,
E: CallExecutor<Block, Blake2Hasher> + Send + Sync,
@@ -1444,11 +1477,13 @@ impl<B, E, Block, RA> CallRuntimeAt<Block> for Client<B, E, Block, RA> where
E: CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync,
Block: BlockT<Hash=H256>,
{
type Error = Error;
fn call_api_at<
'a,
R: Encode + Decode + PartialEq,
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
C: CoreApi<Block>,
C: CoreApi<Block, Error = Error>,
>(
&self,
core_api: &C,
+6
View File
@@ -124,6 +124,12 @@ impl<'a> From<&'a str> for Error {
}
}
impl From<block_builder::ApplyExtrinsicFailed> for Error {
fn from(err: block_builder::ApplyExtrinsicFailed) -> Self {
Self::ApplyExtrinsicFailed(err.0)
}
}
impl Error {
/// Chain a blockchain error.
pub fn from_blockchain(e: Box<Error>) -> Self {
-26
View File
@@ -73,44 +73,25 @@
//! ```
//!
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
#![recursion_limit="128"]
#[macro_use]
pub mod runtime_api;
#[cfg(feature = "std")]
pub mod error;
#[cfg(feature = "std")]
pub mod blockchain;
#[cfg(feature = "std")]
pub mod backend;
#[cfg(feature = "std")]
pub mod cht;
#[cfg(feature = "std")]
pub mod in_mem;
#[cfg(feature = "std")]
pub mod genesis;
pub mod block_builder;
#[cfg(feature = "std")]
pub mod light;
#[cfg(feature = "std")]
pub mod leaves;
#[cfg(feature = "std")]
pub mod children;
#[cfg(feature = "std")]
mod call_executor;
#[cfg(feature = "std")]
mod client;
#[cfg(feature = "std")]
mod notifications;
#[cfg(feature = "std")]
pub use crate::blockchain::Info as ChainInfo;
#[cfg(feature = "std")]
pub use crate::call_executor::{CallExecutor, LocalCallExecutor};
#[cfg(feature = "std")]
pub use crate::client::{
new_with_backend,
new_in_mem,
@@ -119,14 +100,7 @@ pub use crate::client::{
LongestChain, BlockOf, ProvideUncles, ForkBlocks,
utils, apply_aux,
};
#[cfg(feature = "std")]
pub use crate::notifications::{StorageEventStream, StorageChangeSet};
#[cfg(feature = "std")]
pub use state_machine::{ExecutionStrategy, StorageProof};
#[cfg(feature = "std")]
pub use crate::leaves::LeafSet;
#[cfg(feature = "std")]
pub use crate::blockchain::well_known_cache_keys;
#[doc(inline)]
pub use sr_api_macros::{decl_runtime_apis, impl_runtime_apis};
@@ -33,7 +33,8 @@ use state_machine::{
};
use hash_db::Hasher;
use crate::runtime_api::{ProofRecorder, InitializeBlock};
use sr_api::{ProofRecorder, InitializeBlock};
use crate::backend::RemoteBackend;
use crate::call_executor::CallExecutor;
use crate::error::{Error as ClientError, Result as ClientResult};
+3 -1
View File
@@ -20,13 +20,15 @@ client = { package = "substrate-client", path = "../../client" }
substrate-telemetry = { path = "../../telemetry" }
keystore = { package = "substrate-keystore", path = "../../keystore" }
consensus_common = { package = "substrate-consensus-common", path = "../common" }
sr-primitives = { path = "../../sr-primitives" }
sr-primitives = { path = "../../sr-primitives" }
sr-api = { path = "../../sr-api" }
futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] }
futures01 = { package = "futures", version = "0.1" }
futures-timer = "0.4.0"
parking_lot = "0.9.0"
log = "0.4.8"
derive_more = "0.15.0"
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" }
[dev-dependencies]
keyring = { package = "substrate-keyring", path = "../../keyring" }
@@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
substrate-client = { path = "../../../client", default-features = false }
sr-api = { path = "../../../sr-api", default-features = false }
app-crypto = { package = "substrate-application-crypto", path = "../../../application-crypto", default-features = false }
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
sr-primitives = { path = "../../../sr-primitives", default-features = false }
@@ -18,6 +18,6 @@ std = [
"rstd/std",
"codec/std",
"sr-primitives/std",
"substrate-client/std",
"sr-api/std",
"app-crypto/std",
]
@@ -19,7 +19,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Encode, Decode, Codec};
use substrate_client::decl_runtime_apis;
use rstd::vec::Vec;
use sr_primitives::ConsensusEngineId;
@@ -74,7 +73,7 @@ pub enum ConsensusLog<AuthorityId: Codec> {
OnDisabled(AuthorityIndex),
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// API necessary for block authorship with aura.
pub trait AuraApi<AuthorityId: Codec> {
/// Return the slot duration in seconds for Aura.
+19 -11
View File
@@ -39,16 +39,17 @@ use consensus_common::import_queue::{
Verifier, BasicQueue, BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport,
};
use client::{
block_builder::api::BlockBuilder as BlockBuilderApi, blockchain::ProvideCache,
runtime_api::ApiExt, error::Result as CResult, backend::AuxStore, BlockOf,
blockchain::ProvideCache, error::Result as CResult, backend::AuxStore, BlockOf,
well_known_cache_keys::{self, Id as CacheKeyId},
};
use block_builder_api::BlockBuilder as BlockBuilderApi;
use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification};
use sr_primitives::traits::{Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi, Zero, Member};
use primitives::crypto::Pair;
use inherents::{InherentDataProviders, InherentData, RuntimeString};
use inherents::{InherentDataProviders, InherentData};
use futures::prelude::*;
use parking_lot::Mutex;
@@ -65,6 +66,8 @@ use slots::check_equivocation;
use keystore::KeyStorePtr;
use sr_api::ApiExt;
pub use aura_primitives::*;
pub use consensus_common::SyncOracle;
pub use digest::CompatibleDigestItem;
@@ -85,7 +88,7 @@ impl SlotDuration {
A: Codec,
B: BlockT,
C: AuxStore + ProvideRuntimeApi,
C::Api: AuraApi<B, A>,
C::Api: AuraApi<B, A, Error = client::error::Error>,
{
slots::SlotDuration::get_or_compute(client, |a, b| a.slot_duration(b)).map(Self)
}
@@ -332,7 +335,7 @@ enum Error<B: BlockT> {
TooFarInFuture,
Client(client::error::Error),
DataProvider(String),
Runtime(RuntimeString)
Runtime(String),
}
fn find_pre_digest<B: BlockT, P: Pair>(header: &B::Header) -> Result<u64, Error<B>>
@@ -438,7 +441,7 @@ impl<C, P, T> AuraVerifier<C, P, T>
inherent_data: InherentData,
timestamp_now: u64,
) -> Result<(), Error<B>>
where C: ProvideRuntimeApi, C::Api: BlockBuilderApi<B>
where C: ProvideRuntimeApi, C::Api: BlockBuilderApi<B, Error = client::error::Error>
{
const MAX_TIMESTAMP_DRIFT_SECS: u64 = 60;
@@ -471,7 +474,7 @@ impl<C, P, T> AuraVerifier<C, P, T>
thread::sleep(Duration::from_secs(diff));
Ok(())
},
Some(TIError::Other(e)) => Err(Error::Runtime(e)),
Some(TIError::Other(e)) => Err(Error::Runtime(e.into())),
None => Err(Error::DataProvider(
self.inherent_data_providers.error_to_string(&i, &e)
)),
@@ -485,7 +488,7 @@ impl<C, P, T> AuraVerifier<C, P, T>
#[forbid(deprecated)]
impl<B: BlockT, C, P, T> Verifier<B> for AuraVerifier<C, P, T> where
C: ProvideRuntimeApi + Send + Sync + client::backend::AuxStore + ProvideCache<B> + BlockOf,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>>,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>> + ApiExt<B, Error = client::error::Error>,
DigestItemFor<B>: CompatibleDigestItem<P>,
P: Pair + Send + Sync + 'static,
P::Public: Send + Sync + Hash + Eq + Clone + Decode + Encode + Debug + 'static,
@@ -499,7 +502,9 @@ impl<B: BlockT, C, P, T> Verifier<B> for AuraVerifier<C, P, T> where
justification: Option<Justification>,
mut body: Option<Vec<B::Extrinsic>>,
) -> Result<(BlockImportParams<B>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
let mut inherent_data = self.inherent_data_providers.create_inherent_data().map_err(String::from)?;
let mut inherent_data = self.inherent_data_providers
.create_inherent_data()
.map_err(|e| e.into_string())?;
let (timestamp_now, slot_now, _) = AuraSlotCompatible.extract_timestamp_and_slot(&inherent_data)
.map_err(|e| format!("Could not extract timestamp and slot: {:?}", e))?;
let hash = header.hash();
@@ -530,7 +535,10 @@ impl<B: BlockT, C, P, T> Verifier<B> for AuraVerifier<C, P, T> where
// skip the inherents verification if the runtime API is old.
if self.client
.runtime_api()
.has_api_with::<dyn BlockBuilderApi<B>, _>(&BlockId::Hash(parent_hash), |v| v >= 2)
.has_api_with::<dyn BlockBuilderApi<B, Error = ()>, _>(
&BlockId::Hash(parent_hash),
|v| v >= 2,
)
.map_err(|e| format!("{:?}", e))?
{
self.check_inherents(
@@ -667,7 +675,7 @@ pub fn import_queue<B, C, P, T>(
) -> Result<AuraImportQueue<B>, consensus_common::Error> where
B: BlockT,
C: 'static + ProvideRuntimeApi + BlockOf + ProvideCache<B> + Send + Sync + AuxStore,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>>,
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>> + ApiExt<B, Error = client::error::Error>,
DigestItemFor<B>: CompatibleDigestItem<P>,
P: Pair + Send + Sync + 'static,
P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode,
+3
View File
@@ -21,6 +21,8 @@ substrate-telemetry = { path = "../../telemetry" }
keystore = { package = "substrate-keystore", path = "../../keystore" }
srml-babe = { path = "../../../srml/babe" }
client = { package = "substrate-client", path = "../../client" }
sr-api = { path = "../../sr-api" }
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" }
header-metadata = { package = "substrate-header-metadata", path = "../../client/header-metadata" }
consensus-common = { package = "substrate-consensus-common", path = "../common" }
uncles = { package = "substrate-consensus-uncles", path = "../uncles" }
@@ -44,6 +46,7 @@ substrate-executor = { path = "../../executor" }
network = { package = "substrate-network", path = "../../network", features = ["test-helpers"]}
service = { package = "substrate-service", path = "../../service" }
test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" }
block-builder = { package = "substrate-block-builder", path = "../../block-builder" }
tokio = "0.1.22"
env_logger = "0.7.0"
tempfile = "3.1.0"
@@ -6,7 +6,7 @@ description = "Primitives for BABE consensus"
edition = "2018"
[dependencies]
substrate-client = { path = "../../../client", default-features = false }
sr-api = { path = "../../../sr-api", default-features = false }
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
sr-primitives = { path = "../../../sr-primitives", default-features = false }
app-crypto = { package = "substrate-application-crypto", path = "../../../application-crypto", default-features = false }
@@ -19,7 +19,7 @@ default = ["std"]
std = [
"rstd/std",
"sr-primitives/std",
"substrate-client/std",
"sr-api/std",
"codec/std",
"schnorrkel",
"slots",
@@ -24,7 +24,6 @@ mod digest;
use codec::{Encode, Decode};
use rstd::vec::Vec;
use sr_primitives::{ConsensusEngineId, RuntimeDebug};
use substrate_client::decl_runtime_apis;
#[cfg(feature = "std")]
pub use digest::{BabePreDigest, CompatibleDigestItem};
@@ -165,7 +164,7 @@ impl slots::SlotData for BabeConfiguration {
const SLOT_KEY: &'static [u8] = b"babe_configuration";
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// API necessary for block authorship with BABE.
pub trait BabeApi {
/// Return the configuration for BABE. Currently,
+13 -12
View File
@@ -66,7 +66,7 @@ use consensus_common::ImportResult;
use consensus_common::import_queue::{
BoxJustificationImport, BoxFinalityProofImport,
};
use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification, RuntimeString};
use sr_primitives::{generic::{BlockId, OpaqueDigestItemId}, Justification};
use sr_primitives::traits::{
Block as BlockT, Header, DigestItemFor, ProvideRuntimeApi,
Zero,
@@ -75,11 +75,7 @@ use keystore::KeyStorePtr;
use parking_lot::Mutex;
use primitives::{Blake2Hasher, H256, Pair};
use inherents::{InherentDataProviders, InherentData};
use substrate_telemetry::{
telemetry,
CONSENSUS_TRACE,
CONSENSUS_DEBUG,
};
use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG};
use consensus_common::{
self, BlockImport, Environment, Proposer, BlockCheckParams,
ForkChoiceStrategy, BlockImportParams, BlockOrigin, Error as ConsensusError,
@@ -91,11 +87,13 @@ use srml_babe::{
use consensus_common::SelectChain;
use consensus_common::import_queue::{Verifier, BasicQueue, CacheKeyId};
use client::{
block_builder::api::BlockBuilder as BlockBuilderApi,
blockchain::{self, HeaderBackend, ProvideCache}, BlockchainEvents, CallExecutor, Client,
error::Result as ClientResult, error::Error as ClientError, backend::{AuxStore, Backend},
ProvideUncles,
};
use block_builder_api::BlockBuilder as BlockBuilderApi;
use slots::{CheckedHeader, check_equivocation};
use futures::prelude::*;
use log::{warn, debug, info, trace};
@@ -104,6 +102,8 @@ use epoch_changes::descendent_query;
use header_metadata::HeaderMetadata;
use schnorrkel::SignatureError;
use sr_api::ApiExt;
mod aux_schema;
mod verification;
mod epoch_changes;
@@ -167,7 +167,7 @@ enum Error<B: BlockT> {
#[display(fmt = "Checking inherents failed: {}", _0)]
CheckInherents(String),
Client(client::error::Error),
Runtime(RuntimeString),
Runtime(inherents::Error),
ForkTree(Box<fork_tree::Error<client::error::Error>>),
}
@@ -202,7 +202,7 @@ impl Config {
/// Either fetch the slot duration from disk or compute it from the genesis
/// state.
pub fn get_or_compute<B: BlockT, C>(client: &C) -> ClientResult<Self> where
C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi<B>,
C: AuxStore + ProvideRuntimeApi, C::Api: BabeApi<B, Error = client::error::Error>,
{
trace!(target: "babe", "Getting slot duration");
match slots::SlotDuration::get_or_compute(client, |a, b| a.configuration(b)).map(Self) {
@@ -554,7 +554,7 @@ impl<B, E, Block: BlockT, RA, PRA> BabeVerifier<B, E, Block, RA, PRA> {
block_id: BlockId<Block>,
inherent_data: InherentData,
) -> Result<(), Error<Block>>
where PRA: ProvideRuntimeApi, PRA::Api: BlockBuilderApi<Block>
where PRA: ProvideRuntimeApi, PRA::Api: BlockBuilderApi<Block, Error = client::error::Error>
{
let inherent_res = self.api.runtime_api().check_inherents(
&block_id,
@@ -623,7 +623,8 @@ impl<B, E, Block, RA, PRA> Verifier<Block> for BabeVerifier<B, E, Block, RA, PRA
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
RA: Send + Sync,
PRA: ProvideRuntimeApi + Send + Sync + AuxStore + ProvideCache<Block>,
PRA::Api: BlockBuilderApi<Block> + BabeApi<Block>,
PRA::Api: BlockBuilderApi<Block, Error = client::error::Error>
+ BabeApi<Block, Error = client::error::Error>,
{
fn verify(
&mut self,
@@ -1141,7 +1142,7 @@ pub fn import_queue<B, E, Block: BlockT<Hash=H256>, I, RA, PRA>(
E: CallExecutor<Block, Blake2Hasher> + Clone + Send + Sync + 'static,
RA: Send + Sync + 'static,
PRA: ProvideRuntimeApi + ProvideCache<Block> + Send + Sync + AuxStore + 'static,
PRA::Api: BlockBuilderApi<Block> + BabeApi<Block>,
PRA::Api: BlockBuilderApi<Block> + BabeApi<Block> + ApiExt<Block, Error = client::error::Error>,
{
register_babe_inherent_data_provider(&inherent_data_providers, babe_link.config.slot_duration)?;
+1 -1
View File
@@ -23,7 +23,7 @@ use super::*;
use authorship::claim_slot;
use babe_primitives::{AuthorityPair, SlotNumber};
use client::block_builder::BlockBuilder;
use block_builder::BlockBuilder;
use consensus_common::NoNetwork as DummyOracle;
use consensus_common::import_queue::{
BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport,
+1 -1
View File
@@ -36,7 +36,7 @@ pub enum Error {
FaultyTimer(std::io::Error),
/// Error while working with inherent data.
#[display(fmt="InherentData error: {}", _0)]
InherentData(String),
InherentData(inherents::Error),
/// Unable to propose a block.
#[display(fmt="Unable to create block proposal.")]
CannotPropose,
+1
View File
@@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive
primitives = { package = "substrate-primitives", path = "../../primitives" }
sr-primitives = { path = "../../sr-primitives" }
client = { package = "substrate-client", path = "../../client" }
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../block-builder/runtime-api" }
srml-timestamp = { path = "../../../srml/timestamp" }
inherents = { package = "substrate-inherents", path = "../../inherents" }
pow-primitives = { package = "substrate-consensus-pow-primitives", path = "primitives" }
@@ -6,7 +6,7 @@ description = "Primitives for Aura consensus"
edition = "2018"
[dependencies]
substrate-client = { path = "../../../client", default-features = false }
sr-api = { path = "../../../sr-api", default-features = false }
rstd = { package = "sr-std", path = "../../../sr-std", default-features = false }
sr-primitives = { path = "../../../sr-primitives", default-features = false }
primitives = { package = "substrate-primitives", path = "../../../primitives", default-features = false }
@@ -16,7 +16,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features =
default = ["std"]
std = [
"rstd/std",
"substrate-client/std",
"sr-api/std",
"sr-primitives/std",
"primitives/std",
"codec/std",
@@ -21,7 +21,6 @@
use rstd::vec::Vec;
use sr_primitives::ConsensusEngineId;
use codec::Decode;
use substrate_client::decl_runtime_apis;
/// The `ConsensusEngineId` of PoW.
pub const POW_ENGINE_ID: ConsensusEngineId = [b'p', b'o', b'w', b'_'];
@@ -48,7 +47,7 @@ impl TotalDifficulty for u128 {
}
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// API necessary for timestamp-based difficulty adjustment algorithms.
pub trait TimestampApi<Moment: Decode> {
/// Return the timestamp in the current block.
+8 -8
View File
@@ -33,10 +33,10 @@ use std::sync::Arc;
use std::thread;
use std::collections::HashMap;
use client::{
BlockOf, blockchain::{HeaderBackend, ProvideCache},
block_builder::api::BlockBuilder as BlockBuilderApi, backend::AuxStore,
BlockOf, blockchain::{HeaderBackend, ProvideCache}, backend::AuxStore,
well_known_cache_keys::Id as CacheKeyId,
};
use block_builder_api::BlockBuilder as BlockBuilderApi;
use sr_primitives::{Justification, RuntimeString};
use sr_primitives::generic::{BlockId, Digest, DigestItem};
use sr_primitives::traits::{Block as BlockT, Header as HeaderT, ProvideRuntimeApi};
@@ -75,7 +75,7 @@ pub enum Error<B: BlockT> {
#[display(fmt = "Error with block built on {:?}: {:?}", _0, _1)]
BlockBuiltError(B::Hash, ConsensusError),
#[display(fmt = "Creating inherents failed: {}", _0)]
CreateInherents(RuntimeString),
CreateInherents(inherents::Error),
#[display(fmt = "Checking inherents failed: {}", _0)]
CheckInherents(String),
Client(client::error::Error),
@@ -210,7 +210,7 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> PowVerifier<B, C, S, Algorithm> {
inherent_data: InherentData,
timestamp_now: u64,
) -> Result<(), Error<B>> where
C: ProvideRuntimeApi, C::Api: BlockBuilderApi<B>
C: ProvideRuntimeApi, C::Api: BlockBuilderApi<B, Error = client::error::Error>
{
const MAX_TIMESTAMP_DRIFT_SECS: u64 = 60;
@@ -248,7 +248,7 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> PowVerifier<B, C, S, Algorithm> {
impl<B: BlockT<Hash=H256>, C, S, Algorithm> Verifier<B> for PowVerifier<B, C, S, Algorithm> where
C: ProvideRuntimeApi + Send + Sync + HeaderBackend<B> + AuxStore + ProvideCache<B> + BlockOf,
C::Api: BlockBuilderApi<B>,
C::Api: BlockBuilderApi<B, Error = client::error::Error>,
S: SelectChain<B>,
Algorithm: PowAlgorithm<B> + Send + Sync,
{
@@ -260,8 +260,8 @@ impl<B: BlockT<Hash=H256>, C, S, Algorithm> Verifier<B> for PowVerifier<B, C, S,
mut body: Option<Vec<B::Extrinsic>>,
) -> Result<(BlockImportParams<B>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
let inherent_data = self.inherent_data_providers
.create_inherent_data().map_err(String::from)?;
let timestamp_now = inherent_data.timestamp_inherent_data().map_err(String::from)?;
.create_inherent_data().map_err(|e| e.into_string())?;
let timestamp_now = inherent_data.timestamp_inherent_data().map_err(|e| e.into_string())?;
let best_hash = match self.select_chain.as_ref() {
Some(select_chain) => select_chain.best_chain()
@@ -340,7 +340,7 @@ pub fn import_queue<B, C, S, Algorithm>(
B: BlockT<Hash=H256>,
C: ProvideRuntimeApi + HeaderBackend<B> + BlockOf + ProvideCache<B> + AuxStore,
C: Send + Sync + AuxStore + 'static,
C::Api: BlockBuilderApi<B>,
C::Api: BlockBuilderApi<B, Error = client::error::Error>,
Algorithm: PowAlgorithm<B> + Send + Sync + 'static,
S: SelectChain<B> + 'static,
{
+1 -1
View File
@@ -146,7 +146,7 @@ impl<SC: SlotCompatible + Unpin> Stream for Slots<SC> {
let inherent_data = match self.inherent_data_providers.create_inherent_data() {
Ok(id) => id,
Err(err) => return Poll::Ready(Some(Err(consensus_common::Error::InherentData(err.into_owned())))),
Err(err) => return Poll::Ready(Some(Err(consensus_common::Error::InherentData(err)))),
};
let result = self.timestamp_extractor.extract_timestamp_and_slot(&inherent_data);
let (timestamp, slot_num, offset) = match result {
@@ -38,3 +38,4 @@ state_machine = { package = "substrate-state-machine", path = "../state-machine"
env_logger = "0.7.0"
tokio = "0.1.22"
tempfile = "3.1.0"
sr-api = { path = "../sr-api" }
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
client = { package = "substrate-client", path = "../../client", default-features = false }
sr-api = { path = "../../sr-api", default-features = false }
app-crypto = { package = "substrate-application-crypto", path = "../../application-crypto", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
sr-primitives = { path = "../../sr-primitives", default-features = false }
@@ -15,7 +15,7 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }
[features]
default = ["std"]
std = [
"client/std",
"sr-api/std",
"codec/std",
"sr-primitives/std",
"rstd/std",
@@ -25,7 +25,6 @@ extern crate alloc;
use serde::Serialize;
use codec::{Encode, Decode, Input, Codec};
use sr_primitives::{ConsensusEngineId, RuntimeDebug};
use client::decl_runtime_apis;
use rstd::borrow::Cow;
use rstd::vec::Vec;
@@ -211,7 +210,7 @@ impl<'a> Decode for VersionedAuthorityList<'a> {
}
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// APIs for integrating the GRANDPA finality gadget into runtimes.
/// This should be implemented on the runtime side.
///
+4 -5
View File
@@ -25,11 +25,8 @@ use parking_lot::Mutex;
use futures03::{StreamExt as _, TryStreamExt as _};
use tokio::runtime::current_thread;
use keyring::Ed25519Keyring;
use client::{
error::Result,
runtime_api::{Core, RuntimeVersion, ApiExt, StorageProof},
LongestChain,
};
use client::{error::Result, LongestChain};
use sr_api::{Core, RuntimeVersion, ApiExt, StorageProof};
use test_client::{self, runtime::BlockNumber};
use consensus_common::{BlockOrigin, ForkChoiceStrategy, ImportedAux, BlockImportParams, ImportResult};
use consensus_common::import_queue::{BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport};
@@ -244,6 +241,8 @@ impl Core<Block> for RuntimeApi {
}
impl ApiExt<Block> for RuntimeApi {
type Error = client::error::Error;
fn map_api_result<F: FnOnce(&Self) -> result::Result<R, E>, R, E>(
&self,
_: F
+5 -3
View File
@@ -7,8 +7,9 @@ edition = "2018"
[dependencies]
parking_lot = { version = "0.9.0", optional = true }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
sr-primitives = { path = "../sr-primitives", default-features = false }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] }
derive_more = { version = "0.15.0", optional = true }
[features]
default = [ "std" ]
@@ -16,5 +17,6 @@ std = [
"parking_lot",
"rstd/std",
"codec/std",
"sr-primitives/std",
"primitives/std",
"derive_more",
]
+41 -11
View File
@@ -43,7 +43,37 @@ use parking_lot::RwLock;
#[cfg(feature = "std")]
use std::{sync::Arc, format};
pub use sr_primitives::RuntimeString;
/// An error that can occur within the inherent data system.
#[derive(Debug, Encode, Decode, derive_more::Display)]
#[cfg(feature = "std")]
pub struct Error(String);
#[cfg(feature = "std")]
impl<T: Into<String>> From<T> for Error {
fn from(data: T) -> Error {
Self(data.into())
}
}
#[cfg(feature = "std")]
impl Error {
/// Convert this error into a `String`.
pub fn into_string(self) -> String {
self.0
}
}
/// An error that can occur within the inherent data system.
#[derive(Encode, primitives::RuntimeDebug)]
#[cfg(not(feature = "std"))]
pub struct Error(&'static str);
#[cfg(not(feature = "std"))]
impl From<&'static str> for Error {
fn from(data: &'static str) -> Error {
Self(data)
}
}
/// An identifier for an inherent.
pub type InherentIdentifier = [u8; 8];
@@ -73,7 +103,7 @@ impl InherentData {
&mut self,
identifier: InherentIdentifier,
inherent: &I,
) -> Result<(), RuntimeString> {
) -> Result<(), Error> {
match self.data.entry(identifier) {
Entry::Vacant(entry) => {
entry.insert(inherent.encode());
@@ -106,7 +136,7 @@ impl InherentData {
pub fn get_data<I: codec::Decode>(
&self,
identifier: &InherentIdentifier,
) -> Result<Option<I>, RuntimeString> {
) -> Result<Option<I>, Error> {
match self.data.get(identifier) {
Some(inherent) =>
I::decode(&mut &inherent[..])
@@ -163,7 +193,7 @@ impl CheckInherentsResult {
&mut self,
identifier: InherentIdentifier,
error: &E,
) -> Result<(), RuntimeString> {
) -> Result<(), Error> {
// Don't accept any other error
if self.fatal_error {
return Err("No other errors are accepted after an hard error!".into())
@@ -191,7 +221,7 @@ impl CheckInherentsResult {
pub fn get_error<E: codec::Decode>(
&self,
identifier: &InherentIdentifier,
) -> Result<Option<E>, RuntimeString> {
) -> Result<Option<E>, Error> {
self.errors.get_data(identifier)
}
@@ -245,7 +275,7 @@ impl InherentDataProviders {
pub fn register_provider<P: ProvideInherentData + Send + Sync +'static>(
&self,
provider: P,
) -> Result<(), RuntimeString> {
) -> Result<(), Error> {
if self.has_provider(&provider.inherent_identifier()) {
Err(
format!(
@@ -266,7 +296,7 @@ impl InherentDataProviders {
}
/// Create inherent data.
pub fn create_inherent_data(&self) -> Result<InherentData, RuntimeString> {
pub fn create_inherent_data(&self) -> Result<InherentData, Error> {
let mut data = InherentData::new();
self.providers.read().iter().try_for_each(|p| {
p.provide_inherent_data(&mut data)
@@ -305,7 +335,7 @@ impl InherentDataProviders {
pub trait ProvideInherentData {
/// Is called when this inherent data provider is registered at the given
/// `InherentDataProviders`.
fn on_register(&self, _: &InherentDataProviders) -> Result<(), RuntimeString> {
fn on_register(&self, _: &InherentDataProviders) -> Result<(), Error> {
Ok(())
}
@@ -315,7 +345,7 @@ pub trait ProvideInherentData {
/// Provide inherent data that should be included in a block.
///
/// The data should be stored in the given `InherentData` structure.
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), RuntimeString>;
fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error>;
/// Convert the given encoded error to a string.
///
@@ -445,7 +475,7 @@ mod tests {
const ERROR_TO_STRING: &str = "Found error!";
impl ProvideInherentData for TestInherentDataProvider {
fn on_register(&self, _: &InherentDataProviders) -> Result<(), RuntimeString> {
fn on_register(&self, _: &InherentDataProviders) -> Result<(), Error> {
*self.registered.write() = true;
Ok(())
}
@@ -454,7 +484,7 @@ mod tests {
&TEST_INHERENT_0
}
fn provide_inherent_data(&self, data: &mut InherentData) -> Result<(), RuntimeString> {
fn provide_inherent_data(&self, data: &mut InherentData) -> Result<(), Error> {
data.put_data(TEST_INHERENT_0, &42)
}
+1
View File
@@ -26,6 +26,7 @@ libp2p = { version = "0.13.0", default-features = false, features = ["libp2p-web
fork-tree = { path = "../../core/utils/fork-tree" }
consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
client = { package = "substrate-client", path = "../../core/client" }
block-builder = { package = "substrate-block-builder", path = "../../core/block-builder" }
header_metadata = { package = "substrate-header-metadata", path = "../../core/client/header-metadata" }
sr-primitives = { path = "../../core/sr-primitives" }
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
+1 -1
View File
@@ -34,7 +34,7 @@ use client::{
error::Result as ClientResult,
well_known_cache_keys::{self, Id as CacheKeyId},
};
use client::block_builder::BlockBuilder;
use block_builder::BlockBuilder;
use client::backend::{AuxStore, Backend, Finalizer};
use crate::config::Roles;
use consensus::block_validation::DefaultBlockAnnounceValidator;
+2 -1
View File
@@ -8,7 +8,8 @@ edition = "2018"
[dependencies]
bytes = "0.4.12"
client = { package = "substrate-client", path = "../../core/client" }
client = { package = "substrate-client", path = "../client" }
sr-api = { path = "../sr-api" }
fnv = "1.0.6"
futures01 = { package = "futures", version = "0.1" }
futures-preview = "0.3.0-alpha.19"
@@ -7,12 +7,12 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
client = { package = "substrate-client", path = "../../client", default-features = false }
sr-api = { path = "../../sr-api", default-features = false }
sr-primitives = { path = "../../sr-primitives", default-features = false }
[features]
default = ["std"]
std = [
"client/std",
"sr-api/std",
"sr-primitives/std"
]
@@ -19,13 +19,12 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
use client::decl_runtime_apis;
use sr_primitives::traits::NumberFor;
/// Local Storage Prefix used by the Offchain Worker API to
pub const STORAGE_PREFIX: &[u8] = b"storage";
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// The offchain worker api.
pub trait OffchainWorkerApi {
/// Starts the off-chain task for given block number.
+3 -7
View File
@@ -33,15 +33,11 @@
#![warn(missing_docs)]
use std::{
fmt,
marker::PhantomData,
sync::Arc,
};
use std::{fmt, marker::PhantomData, sync::Arc};
use parking_lot::Mutex;
use threadpool::ThreadPool;
use client::runtime_api::ApiExt;
use sr_api::ApiExt;
use futures::future::Future;
use log::{debug, warn};
use network::NetworkStateInfo;
@@ -106,7 +102,7 @@ impl<Client, Storage, Block> OffchainWorkers<
) -> impl Future<Output = ()> where A: ChainApi<Block=Block> + 'static {
let runtime = self.client.runtime_api();
let at = BlockId::number(*number);
let has_api = runtime.has_api::<dyn OffchainWorkerApi<Block>>(&at);
let has_api = runtime.has_api::<dyn OffchainWorkerApi<Block, Error = ()>>(&at);
debug!("Checking offchain workers at {:?}: {:?}", at, has_api);
if has_api.unwrap_or(false) {
+2 -2
View File
@@ -38,9 +38,9 @@ use std::borrow::Cow;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
#[cfg(feature = "std")]
pub use serde;// << for macro
pub use serde;
#[doc(hidden)]
pub use codec::{Encode, Decode};// << for macro
pub use codec::{Encode, Decode};
pub use substrate_debug_derive::RuntimeDebug;
+1
View File
@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
api = { package = "substrate-rpc-api", path = "./api" }
client = { package = "substrate-client", path = "../client" }
sr-api = { path = "../sr-api" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] }
jsonrpc-pubsub = "14.0.3"
+8 -5
View File
@@ -23,7 +23,8 @@ use std::{sync::Arc, convert::TryInto};
use futures03::future::{FutureExt, TryFutureExt};
use log::warn;
use client::{self, Client};
use client::{Client, error::Error as ClientError};
use rpc::futures::{
Sink, Future,
future::result,
@@ -87,7 +88,8 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
P::Error: 'static,
RA: Send + Sync + 'static,
Client<B, E, P::Block, RA>: ProvideRuntimeApi,
<Client<B, E, P::Block, RA> as ProvideRuntimeApi>::Api: SessionKeys<P::Block>,
<Client<B, E, P::Block, RA> as ProvideRuntimeApi>::Api:
SessionKeys<P::Block, Error = ClientError>,
{
type Metadata = crate::metadata::Metadata;
@@ -131,8 +133,9 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
Ok(self.pool.ready().map(|tx| tx.data.encode().into()).collect())
}
fn remove_extrinsic(&self,
bytes_or_hash: Vec<hash::ExtrinsicOrHash<ExHash<P>>>
fn remove_extrinsic(
&self,
bytes_or_hash: Vec<hash::ExtrinsicOrHash<ExHash<P>>>,
) -> Result<Vec<ExHash<P>>> {
let hashes = bytes_or_hash.into_iter()
.map(|x| match x {
@@ -155,7 +158,7 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
fn watch_extrinsic(&self,
_metadata: Self::Metadata,
subscriber: Subscriber<Status<ExHash<P>, BlockHash<P>>>,
xt: Bytes
xt: Bytes,
) {
let submit = || -> Result<_> {
let best_block_hash = self.client.info().chain.best_hash;
+6 -10
View File
@@ -24,17 +24,10 @@ mod tests;
use std::sync::Arc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use rpc::{
Result as RpcResult,
futures::Future,
};
use rpc::{Result as RpcResult, futures::Future};
use api::Subscriptions;
use client::{
Client, CallExecutor,
runtime_api::Metadata,
light::{blockchain::RemoteBlockchain, fetcher::Fetcher},
};
use client::{Client, CallExecutor, light::{blockchain::RemoteBlockchain, fetcher::Fetcher}};
use primitives::{
Blake2Hasher, Bytes, H256,
storage::{StorageKey, StorageData, StorageChangeSet},
@@ -44,6 +37,8 @@ use sr_primitives::{
traits::{Block as BlockT, ProvideRuntimeApi},
};
use sr_api::Metadata;
use self::error::{Error, FutureResult};
pub use api::state::*;
@@ -188,7 +183,8 @@ pub fn new_full<B, E, Block: BlockT, RA>(
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client<B, E, Block, RA>: ProvideRuntimeApi,
<Client<B, E, Block, RA> as ProvideRuntimeApi>::Api: Metadata<Block>,
<Client<B, E, Block, RA> as ProvideRuntimeApi>::Api:
Metadata<Block, Error = client::error::Error>,
{
State {
backend: Box::new(self::state_full::FullState::new(client, subscriptions)),
+8 -4
View File
@@ -29,8 +29,7 @@ use rpc::{
use api::Subscriptions;
use client::{
Client, CallExecutor, BlockchainEvents, runtime_api::Metadata,
backend::Backend, error::Result as ClientResult,
Client, CallExecutor, BlockchainEvents, backend::Backend, error::Result as ClientResult,
};
use primitives::{
H256, Blake2Hasher, Bytes, storage::{well_known_keys, StorageKey, StorageData, StorageChangeSet},
@@ -42,6 +41,8 @@ use sr_primitives::{
traits::{Block as BlockT, Header, NumberFor, ProvideRuntimeApi, SaturatedConversion},
};
use sr_api::Metadata;
use super::{StateBackend, error::{FutureResult, Error, Result}, client_err};
/// Ranges to query in state_queryStorage.
@@ -229,7 +230,8 @@ impl<B, E, Block, RA> StateBackend<B, E, Block, RA> for FullState<B, E, Block, R
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static + Clone,
RA: Send + Sync + 'static,
Client<B, E, Block, RA>: ProvideRuntimeApi,
<Client<B, E, Block, RA> as ProvideRuntimeApi>::Api: Metadata<Block>,
<Client<B, E, Block, RA> as ProvideRuntimeApi>::Api:
Metadata<Block, Error = client::error::Error>,
{
fn call(
&self,
@@ -326,7 +328,9 @@ impl<B, E, Block, RA> StateBackend<B, E, Block, RA> for FullState<B, E, Block, R
fn metadata(&self, block: Option<Block::Hash>) -> FutureResult<Bytes> {
Box::new(result(
self.block_or_best(block)
.and_then(|block| self.client.runtime_api().metadata(&BlockId::Hash(block)).map(Into::into))
.and_then(|block|
self.client.runtime_api().metadata(&BlockId::Hash(block)).map(Into::into)
)
.map_err(client_err)))
}
+3 -1
View File
@@ -10,7 +10,7 @@ default = ["rocksdb"]
# a path to a database, an error will be produced at runtime.
rocksdb = ["client_db/kvdb-rocksdb"]
wasmtime = [
"substrate-executor/wasmtime",
"substrate-executor/wasmtime",
]
[dependencies]
@@ -38,6 +38,8 @@ consensus_common = { package = "substrate-consensus-common", path = "../../core/
network = { package = "substrate-network", path = "../../core/network" }
chain-spec = { package = "substrate-chain-spec", path = "../chain-spec" }
client = { package = "substrate-client", path = "../../core/client" }
sr-api = { path = "../sr-api" }
tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../transaction-pool/runtime-api" }
client_db = { package = "substrate-client-db", path = "../../core/client/db" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
substrate-executor = { path = "../../core/executor" }
+9 -7
View File
@@ -19,8 +19,7 @@ use crate::{SpawnTaskHandle, start_rpc_servers, build_network_future, Transactio
use crate::status_sinks;
use crate::config::{Configuration, DatabaseConfig};
use client::{
BlockchainEvents, Client, runtime_api,
backend::RemoteBackend, light::blockchain::RemoteBlockchain,
BlockchainEvents, Client, backend::RemoteBackend, light::blockchain::RemoteBlockchain,
};
use chain_spec::{RuntimeGenesis, Extension};
use codec::{Decode, Encode, IoReader};
@@ -757,10 +756,11 @@ ServiceBuilder<
> where
Client<TBackend, TExec, TBl, TRtApi>: ProvideRuntimeApi,
<Client<TBackend, TExec, TBl, TRtApi> as ProvideRuntimeApi>::Api:
runtime_api::Metadata<TBl> +
sr_api::Metadata<TBl> +
offchain::OffchainWorkerApi<TBl> +
runtime_api::TaggedTransactionQueue<TBl> +
session::SessionKeys<TBl>,
tx_pool_api::TaggedTransactionQueue<TBl> +
session::SessionKeys<TBl> +
sr_api::ApiExt<TBl, Error = client::error::Error>,
TBl: BlockT<Hash = <Blake2Hasher as Hasher>::Out>,
TRtApi: 'static + Send + Sync,
TCfg: Default,
@@ -808,7 +808,8 @@ ServiceBuilder<
session::generate_initial_session_keys(
client.clone(),
config.dev_key_seed.clone().map(|s| vec![s]).unwrap_or_default()
&BlockId::Hash(client.info().chain.best_hash),
config.dev_key_seed.clone().map(|s| vec![s]).unwrap_or_default(),
)?;
let (signal, exit) = exit_future::signal();
@@ -1162,7 +1163,8 @@ pub(crate) fn maintain_transaction_pool<Api, Backend, Block, Executor, PoolApi>(
Block: BlockT<Hash = <Blake2Hasher as primitives::Hasher>::Out>,
Backend: 'static + client::backend::Backend<Block, Blake2Hasher>,
Client<Backend, Executor, Block, Api>: ProvideRuntimeApi,
<Client<Backend, Executor, Block, Api> as ProvideRuntimeApi>::Api: runtime_api::TaggedTransactionQueue<Block>,
<Client<Backend, Executor, Block, Api> as ProvideRuntimeApi>::Api:
tx_pool_api::TaggedTransactionQueue<Block>,
Executor: 'static + client::CallExecutor<Block, Blake2Hasher>,
PoolApi: 'static + txpool::ChainApi<Hash = Block::Hash, Block = Block>,
Api: 'static,
+2 -2
View File
@@ -36,7 +36,7 @@ use std::time::{Duration, Instant};
use futures::sync::mpsc;
use parking_lot::Mutex;
use client::{runtime_api::BlockT, Client};
use client::Client;
use exit_future::Signal;
use futures::prelude::*;
use futures03::{
@@ -51,7 +51,7 @@ use log::{log, warn, debug, error, Level};
use codec::{Encode, Decode};
use primitives::{Blake2Hasher, H256};
use sr_primitives::generic::BlockId;
use sr_primitives::traits::NumberFor;
use sr_primitives::traits::{NumberFor, Block as BlockT};
pub use self::error::Error;
pub use self::builder::{ServiceBuilder, ServiceBuilderExport, ServiceBuilderImport, ServiceBuilderRevert};
+2 -3
View File
@@ -5,11 +5,10 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
client = { package = "substrate-client", path = "../client", default-features = false }
sr-api = { path = "../sr-api", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
sr-primitives = { path = "../sr-primitives", optional = true }
primitives = { package = "substrate-primitives", path = "../primitives", optional = true }
[features]
default = [ "std" ]
std = [ "client/std", "rstd/std", "sr-primitives", "primitives" ]
std = [ "sr-api/std", "rstd/std", "sr-primitives" ]
+11 -18
View File
@@ -21,11 +21,9 @@
use rstd::vec::Vec;
#[cfg(feature = "std")]
use sr_primitives::traits::{ProvideRuntimeApi, Block as BlockT};
#[cfg(feature = "std")]
use primitives::{H256, Blake2Hasher};
use sr_primitives::{generic::BlockId, traits::{ProvideRuntimeApi, Block as BlockT}};
client::decl_runtime_apis! {
sr_api::decl_runtime_apis! {
/// Session keys runtime api.
pub trait SessionKeys {
/// Generate a set of session keys with optionally using the given seed.
@@ -39,28 +37,23 @@ client::decl_runtime_apis! {
}
}
/// Generate the initial session keys with the given seeds and store them in
/// Generate the initial session keys with the given seeds, at the given block and store them in
/// the client's keystore.
#[cfg(feature = "std")]
pub fn generate_initial_session_keys<B, E, Block, RA>(
client: std::sync::Arc<client::Client<B, E, Block, RA>>,
pub fn generate_initial_session_keys<Block, T>(
client: std::sync::Arc<T>,
at: &BlockId<Block>,
seeds: Vec<String>,
) -> Result<(), client::error::Error>
) -> Result<(), <<T as ProvideRuntimeApi>::Api as sr_api::ApiExt<Block>>::Error>
where
B: client::backend::Backend<Block, Blake2Hasher>,
E: client::CallExecutor<Block, Blake2Hasher>,
Block: BlockT<Hash=H256>,
client::Client<B, E, Block, RA>: ProvideRuntimeApi,
<client::Client<B, E, Block, RA> as ProvideRuntimeApi>::Api: SessionKeys<Block>,
Block: BlockT,
T: ProvideRuntimeApi,
<T as ProvideRuntimeApi>::Api: SessionKeys<Block>,
{
let info = client.info().chain;
let runtime_api = client.runtime_api();
for seed in seeds {
runtime_api.generate_session_keys(
&sr_primitives::generic::BlockId::Number(info.best_number),
Some(seed.as_bytes().to_vec()),
)?;
runtime_api.generate_session_keys(at, Some(seed.as_bytes().to_vec()))?;
}
Ok(())
-37
View File
@@ -1,37 +0,0 @@
[package]
name = "sr-api-macros"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[lib]
proc-macro = true
[dependencies]
quote = "1.0.2"
syn = { version = "1.0.7", features = [ "full", "fold", "extra-traits", "visit" ] }
proc-macro2 = "1.0.6"
blake2-rfc = "0.2.18"
proc-macro-crate = "0.1.4"
[dev-dependencies]
client = { package = "substrate-client", path = "../client" }
test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" }
state_machine = { package = "substrate-state-machine", path = "../state-machine" }
sr-primitives = { path = "../sr-primitives" }
sr-version = { path = "../sr-version" }
primitives = { package = "substrate-primitives", path = "../primitives" }
criterion = "0.3.0"
consensus_common = { package = "substrate-consensus-common", path = "../consensus/common" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
trybuild = "1.0.17"
rustversion = "1.0.0"
[[bench]]
name = "bench"
harness = false
# We actually don't need the `std` feature in this crate, but the tests require it.
[features]
default = [ "std" ]
std = []
@@ -1,5 +0,0 @@
error: `self` as argument not supported.
--> $DIR/adding_self_parameter.rs:5:11
|
5 | fn test(&self);
| ^
@@ -1,5 +0,0 @@
error: No api implementation given!
--> $DIR/empty_impl_runtime_apis_call.rs:18:1
|
18 | impl_runtime_apis! {}
| ^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
@@ -1,64 +0,0 @@
error[E0053]: method `test` has an incompatible type for trait
--> $DIR/impl_incorrect_method_signature.rs:20:17
|
14 | fn test(data: u64);
| --- type in trait
...
20 | fn test(data: String) {}
| ^^^^^^ expected u64, found struct `std::string::String`
|
= note: expected type `fn(u64)`
found type `fn(std::string::String)`
error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait
--> $DIR/impl_incorrect_method_signature.rs:18:1
|
12 | / decl_runtime_apis! {
13 | | pub trait Api {
14 | | fn test(data: u64);
15 | | }
16 | | }
| |_- type in trait
17 |
18 | impl_runtime_apis! {
| -^^^^^^^^^^^^^^^^^
| |
| _expected u64, found struct `std::string::String`
| |
19 | | impl self::Api<Block> for Runtime {
20 | | fn test(data: String) {}
21 | | }
... |
33 | | }
34 | | }
| |_- in this macro invocation
|
= note: expected type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sr_primitives::generic::block::BlockId<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<u8>) -> std::result::Result<sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::NativeOrEncoded<()>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>`
found type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sr_primitives::generic::block::BlockId<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option<std::string::String>, std::vec::Vec<u8>) -> std::result::Result<sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::NativeOrEncoded<()>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>`
error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:18:1
|
18 | / impl_runtime_apis! {
19 | | impl self::Api<Block> for Runtime {
20 | | fn test(data: String) {}
21 | | }
... |
33 | | }
34 | | }
| | ^
| | |
| |_expected u64, found struct `std::string::String`
| in this macro invocation
|
= note: expected type `u64`
found type `std::string::String`
error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:20:11
|
20 | fn test(data: String) {}
| ^^^^ expected u64, found struct `std::string::String`
|
= note: expected type `u64`
found type `std::string::String`
@@ -1,17 +0,0 @@
error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration!
--> $DIR/impl_two_traits_with_same_name.rs:33:15
|
33 | impl second::Api<Block> for Runtime {
| ^^^
error[E0277]: the trait bound `RuntimeApiImpl<RuntimeApiImplCall>: sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` is not satisfied
--> $DIR/impl_two_traits_with_same_name.rs:29:7
|
29 | impl self::Api<Block> for Runtime {
| ^^^^^^^^^^^^^^^^ the trait `sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` is not implemented for `RuntimeApiImpl<RuntimeApiImplCall>`
error[E0277]: the trait bound `RuntimeApiImpl<RuntimeApiImplCall>: sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` is not satisfied
--> $DIR/impl_two_traits_with_same_name.rs:33:7
|
33 | impl second::Api<Block> for Runtime {
| ^^^^^^^^^^^^^^^^^^ the trait `sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::Core<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` is not implemented for `RuntimeApiImpl<RuntimeApiImplCall>`
@@ -1,33 +0,0 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version_2.rs:3:1
|
3 | / decl_runtime_apis! {
4 | | #[api_version("1")]
5 | | pub trait Api {
6 | | fn test(data: u64);
7 | | }
8 | | }
| | ^ in this macro invocation
| |_|
|
|
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_2.rs:3:1
|
3 | / decl_runtime_apis! {
4 | | #[api_version("1")]
5 | | pub trait Api {
6 | | fn test(data: u64);
7 | | }
8 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_2.rs:4:4
|
4 | #[api_version("1")]
| ^^^^^^^^^^^
@@ -1,33 +0,0 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version_3.rs:3:1
|
3 | / decl_runtime_apis! {
4 | | #[api_version()]
5 | | pub trait Api {
6 | | fn test(data: u64);
7 | | }
8 | | }
| | ^ in this macro invocation
| |_|
|
|
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_3.rs:3:1
|
3 | / decl_runtime_apis! {
4 | | #[api_version()]
5 | | pub trait Api {
6 | | fn test(data: u64);
7 | | }
8 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_3.rs:4:4
|
4 | #[api_version()]
| ^^^^^^^^^^^
@@ -1,13 +0,0 @@
error: Missing `Block` generic parameter.
--> $DIR/missing_block_generic_parameter.rs:19:13
|
19 | impl self::Api for Runtime {
| ^^^
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/missing_block_generic_parameter.rs:19:7
|
19 | impl self::Api for Runtime {
| ^^^^^^^^^ expected 1 type argument
For more information about this error, try `rustc --explain E0107`.
@@ -1,67 +0,0 @@
error[E0053]: method `test` has an incompatible type for trait
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:20:17
|
14 | fn test(data: u64);
| --- type in trait
...
20 | fn test(data: &u64) {
| ^^^^ expected u64, found &u64
|
= note: expected type `fn(u64)`
found type `fn(&u64)`
error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:18:1
|
12 | / decl_runtime_apis! {
13 | | pub trait Api {
14 | | fn test(data: u64);
15 | | }
16 | | }
| |_- type in trait
17 |
18 | impl_runtime_apis! {
| -^^^^^^^^^^^^^^^^^
| |
| _expected u64, found &u64
| |
19 | | impl self::Api<Block> for Runtime {
20 | | fn test(data: &u64) {
21 | | unimplemented!()
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
= note: expected type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sr_primitives::generic::block::BlockId<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<u8>) -> std::result::Result<sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::NativeOrEncoded<()>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>`
found type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sr_primitives::generic::block::BlockId<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::ExecutionContext, std::option::Option<&u64>, std::vec::Vec<u8>) -> std::result::Result<sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::runtime_api::NativeOrEncoded<()>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api_client::error::Error>`
error[E0308]: mismatched types
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:18:1
|
18 | / impl_runtime_apis! {
19 | | impl self::Api<Block> for Runtime {
20 | | fn test(data: &u64) {
21 | | unimplemented!()
... |
35 | | }
36 | | }
| | ^
| | |
| |_expected u64, found &u64
| in this macro invocation
|
= note: expected type `u64`
found type `&u64`
error[E0308]: mismatched types
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:20:11
|
20 | fn test(data: &u64) {
| ^^^^^^^
| |
| expected u64, found &u64
| help: consider removing the borrow: `data`
|
= note: expected type `u64`
found type `&u64`
+33
View File
@@ -0,0 +1,33 @@
[package]
name = "sr-api"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
sr-api-proc-macro = { path = "proc-macro" }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
sr-primitives = { path = "../sr-primitives", default-features = false }
sr-version = { path = "../sr-version", default-features = false }
state-machine = { package = "substrate-state-machine", path = "../state-machine", optional = true }
[dev-dependencies]
criterion = "0.3.0"
test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" }
[[bench]]
name = "bench"
harness = false
[features]
default = [ "std" ]
std = [
"codec/std",
"primitives/std",
"rstd/std",
"sr-primitives/std",
"state-machine",
"sr-version/std",
]
@@ -16,8 +16,8 @@
use criterion::{Criterion, criterion_group, criterion_main};
use test_client::{
DefaultTestClientBuilderExt, TestClientBuilder,
TestClientBuilderExt, runtime::TestAPI,
DefaultTestClientBuilderExt, TestClientBuilder,
TestClientBuilderExt, runtime::TestAPI,
};
use sr_primitives::{generic::BlockId, traits::ProvideRuntimeApi};
use state_machine::ExecutionStrategy;
@@ -0,0 +1,26 @@
[package]
name = "sr-api-proc-macro"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[lib]
proc-macro = true
[dependencies]
quote = "1.0.2"
syn = { version = "1.0.8", features = [ "full", "fold", "extra-traits", "visit" ] }
proc-macro2 = "1.0.6"
blake2-rfc = "0.2.18"
proc-macro-crate = "0.1.4"
[dev-dependencies]
sr-api = { path = ".." }
sr-primitives = { path = "../../sr-primitives" }
sr-version = { path = "../../sr-version" }
test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" }
# Required for the doc tests
[features]
default = [ "std" ]
std = []
@@ -96,7 +96,7 @@ fn extend_generics_with_block(generics: &mut Generics) {
let c = generate_crate_access(HIDDEN_INCLUDES_ID);
generics.lt_token = Some(Default::default());
generics.params.insert(0, parse_quote!( Block: #c::runtime_api::BlockT ));
generics.params.insert(0, parse_quote!( Block: #c::BlockT ));
generics.gt_token = Some(Default::default());
}
@@ -186,12 +186,12 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
result.push(quote!(
#[cfg(any(feature = "std", test))]
fn convert_between_block_types
<I: #crate_::runtime_api::Encode, R: #crate_::runtime_api::Decode>(
<I: #crate_::Encode, R: #crate_::Decode>(
input: &I, error_desc: &'static str,
) -> std::result::Result<R, String>
{
<R as #crate_::runtime_api::Decode>::decode(
&mut &#crate_::runtime_api::Encode::encode(input)[..],
<R as #crate_::Decode>::decode(
&mut &#crate_::Encode::encode(input)[..],
).map_err(|e| format!("{} {}", error_desc, e.what()))
}
));
@@ -272,7 +272,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
result.push(quote!(
#[cfg(any(feature = "std", test))]
pub fn #fn_name<
'a, ApiImpl: #trait_ #ty_generics, NodeBlock: #crate_::runtime_api::BlockT
'a, ApiImpl: #trait_ #ty_generics, NodeBlock: #crate_::BlockT
#(, #impl_generics_params)*
>(
#( #fn_inputs ),*
@@ -396,24 +396,24 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
result.push(quote!(
#[cfg(any(feature = "std", test))]
pub fn #fn_name<
R: #crate_::runtime_api::Encode + #crate_::runtime_api::Decode + PartialEq,
R: #crate_::Encode + #crate_::Decode + PartialEq,
NC: FnOnce() -> std::result::Result<R, String> + std::panic::UnwindSafe,
Block: #crate_::runtime_api::BlockT,
T: #crate_::runtime_api::CallRuntimeAt<Block>,
C: #crate_::runtime_api::Core<Block>,
Block: #crate_::BlockT,
T: #crate_::CallRuntimeAt<Block>,
C: #crate_::Core<Block, Error = T::Error>,
>(
call_runtime_at: &T,
core_api: &C,
at: &#crate_::runtime_api::BlockId<Block>,
at: &#crate_::BlockId<Block>,
args: Vec<u8>,
changes: &std::cell::RefCell<#crate_::runtime_api::OverlayedChanges>,
initialized_block: &std::cell::RefCell<Option<#crate_::runtime_api::BlockId<Block>>>,
changes: &std::cell::RefCell<#crate_::OverlayedChanges>,
initialized_block: &std::cell::RefCell<Option<#crate_::BlockId<Block>>>,
native_call: Option<NC>,
context: #crate_::runtime_api::ExecutionContext,
recorder: &Option<std::rc::Rc<std::cell::RefCell<#crate_::runtime_api::ProofRecorder<Block>>>>,
) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<R>> {
context: #crate_::ExecutionContext,
recorder: &Option<std::rc::Rc<std::cell::RefCell<#crate_::ProofRecorder<Block>>>>,
) -> std::result::Result<#crate_::NativeOrEncoded<R>, T::Error> {
let version = call_runtime_at.runtime_version_at(at)?;
use #crate_::runtime_api::InitializeBlock;
use #crate_::InitializeBlock;
let initialize_block = if #skip_initialize_block {
InitializeBlock::Skip
} else {
@@ -553,7 +553,7 @@ impl<'a> ToClientSideDecl<'a> {
fn fold_trait_item_method(&mut self, method: TraitItemMethod)
-> (TraitItemMethod, Option<TraitItemMethod>, TraitItemMethod) {
let crate_ = self.crate_;
let context = quote!( #crate_::runtime_api::ExecutionContext::OffchainCall(None) );
let context = quote!( #crate_::ExecutionContext::OffchainCall(None) );
let fn_impl = self.create_method_runtime_api_impl(method.clone());
let fn_decl = self.create_method_decl(method.clone(), context);
let fn_decl_ctx = self.create_method_decl_with_context(method);
@@ -563,7 +563,7 @@ impl<'a> ToClientSideDecl<'a> {
fn create_method_decl_with_context(&mut self, method: TraitItemMethod) -> TraitItemMethod {
let crate_ = self.crate_;
let context_arg: syn::FnArg = parse_quote!( context: #crate_::runtime_api::ExecutionContext );
let context_arg: syn::FnArg = parse_quote!( context: #crate_::ExecutionContext );
let mut fn_decl_ctx = self.create_method_decl(method, quote!( context ));
fn_decl_ctx.sig.ident = Ident::new(&format!("{}_with_context", &fn_decl_ctx.sig.ident), Span::call_site());
fn_decl_ctx.sig.inputs.insert(2, context_arg);
@@ -604,10 +604,10 @@ impl<'a> ToClientSideDecl<'a> {
fn #name(
&self,
at: &#block_id,
context: #crate_::runtime_api::ExecutionContext,
context: #crate_::ExecutionContext,
params: Option<( #( #param_types ),* )>,
params_encoded: Vec<u8>,
) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<#ret_type>>;
) -> std::result::Result<#crate_::NativeOrEncoded<#ret_type>, Self::Error>;
}
)
}
@@ -630,7 +630,7 @@ impl<'a> ToClientSideDecl<'a> {
let params2 = params.clone();
let ret_type = return_type_extract_type(&method.sig.output);
fold_fn_decl_for_client_side(&mut method.sig, &self.block_id, &self.crate_);
fold_fn_decl_for_client_side(&mut method.sig, &self.block_id);
let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
let crate_ = self.crate_;
@@ -674,7 +674,7 @@ impl<'a> ToClientSideDecl<'a> {
parse_quote! {
{
let runtime_api_impl_params_encoded =
#crate_::runtime_api::Encode::encode(&( #( &#params ),* ));
#crate_::Encode::encode(&( #( &#params ),* ));
self.#name_impl(
__runtime_api_at_param__,
@@ -683,14 +683,16 @@ impl<'a> ToClientSideDecl<'a> {
runtime_api_impl_params_encoded,
).and_then(|r|
match r {
#crate_::runtime_api::NativeOrEncoded::Native(n) => {
#crate_::NativeOrEncoded::Native(n) => {
#native_handling
},
#crate_::runtime_api::NativeOrEncoded::Encoded(r) => {
<#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..])
#crate_::NativeOrEncoded::Encoded(r) => {
<#ret_type as #crate_::Decode>::decode(&mut &r[..])
.map_err(|err|
#crate_::error::Error::CallResultDecode(
#function_name, err
format!(
"Failed to decode result of `{}`: {}",
#function_name,
err.what(),
).into()
)
}
@@ -720,12 +722,12 @@ impl<'a> Fold for ToClientSideDecl<'a> {
'static
+ Send
+ Sync
+ #crate_::runtime_api::ApiExt<#block_ident>
+ #crate_::ApiExt<#block_ident>
);
} else {
// Add the `Core` runtime api as super trait.
let crate_ = &self.crate_;
input.supertraits.push(parse_quote!( #crate_::runtime_api::Core<#block_ident> ));
input.supertraits.push(parse_quote!( #crate_::Core<#block_ident> ));
}
// The client side trait is only required when compiling with the feature `std` or `test`.
@@ -783,12 +785,24 @@ fn generate_runtime_info_impl(trait_: &ItemTrait, version: u64) -> TokenStream {
let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID);
let id = generate_runtime_api_id(&trait_name.to_string());
let version = generate_runtime_api_version(version as u32);
let (impl_generics, ty_generics, where_clause) = trait_.generics.split_for_impl();
let impl_generics = trait_.generics.type_params().map(|t| {
let ident = &t.ident;
let colon_token = &t.colon_token;
let bounds = &t.bounds;
quote! { #ident #colon_token #bounds }
}).chain(std::iter::once(quote! { __Sr_Api_Error__ }));
let ty_generics = trait_.generics.type_params().map(|t| {
let ident = &t.ident;
quote! { #ident }
}).chain(std::iter::once(quote! { Error = __Sr_Api_Error__ }));
quote!(
#[cfg(any(feature = "std", test))]
impl #impl_generics #crate_::runtime_api::RuntimeApiInfo
for #trait_name #ty_generics #where_clause
impl < #( #impl_generics, )* > #crate_::RuntimeApiInfo
for #trait_name < #( #ty_generics, )* >
{
#id
#version
@@ -816,7 +830,7 @@ fn generate_client_side_decls(decls: &[ItemTrait]) -> TokenStream {
let decl = decl.clone();
let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID);
let block_id = quote!( #crate_::runtime_api::BlockId<Block> );
let block_id = quote!( #crate_::BlockId<Block> );
let mut found_attributes = HashMap::new();
let mut errors = Vec::new();
let trait_ = decl.ident.clone();
@@ -76,7 +76,7 @@ fn generate_impl_call(
Ok(
quote!(
#(
let #pnames : #ptypes = match #c_iter::runtime_api::Decode::decode(&mut #input) {
let #pnames : #ptypes = match #c_iter::Decode::decode(&mut #input) {
Ok(input) => input,
Err(e) => panic!("Bad input data provided to {}: {}", #fn_name_str, e.what()),
};
@@ -175,7 +175,7 @@ fn generate_dispatch_function(impls: &[ItemImpl]) -> Result<TokenStream> {
.into_iter()
.map(|(trait_, fn_name, impl_)| {
let name = prefix_function_with_trait(&trait_, &fn_name);
quote!( #name => Some(#c::runtime_api::Encode::encode(&{ #impl_ })), )
quote!( #name => Some(#c::Encode::encode(&{ #impl_ })), )
});
Ok(quote!(
@@ -209,12 +209,12 @@ fn generate_wasm_interface(impls: &[ItemImpl]) -> Result<TokenStream> {
&[0u8; 0]
} else {
unsafe {
#c::runtime_api::slice::from_raw_parts(input_data, input_len)
#c::slice::from_raw_parts(input_data, input_len)
}
};
let output = { #impl_ };
#c::runtime_api::to_substrate_wasm_fn_return_value(&output)
#c::to_substrate_wasm_fn_return_value(&output)
}
)
});
@@ -231,8 +231,8 @@ fn generate_block_and_block_id_ty(
let trait_ = Ident::new(trait_, Span::call_site());
let assoc_type = Ident::new(assoc_type, Span::call_site());
let block = quote!( <#runtime as #crate_::runtime_api::#trait_>::#assoc_type );
let block_id = quote!( #crate_::runtime_api::BlockId<#block> );
let block = quote!( <#runtime as #crate_::#trait_>::#assoc_type );
let block_id = quote!( #crate_::BlockId<#block> );
(block, block_id)
}
@@ -252,30 +252,30 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
pub struct RuntimeApi {}
/// Implements all runtime apis for the client side.
#[cfg(any(feature = "std", test))]
pub struct RuntimeApiImpl<C: #crate_::runtime_api::CallRuntimeAt<#block> + 'static> {
pub struct RuntimeApiImpl<C: #crate_::CallRuntimeAt<#block> + 'static> {
call: &'static C,
commit_on_success: std::cell::RefCell<bool>,
initialized_block: std::cell::RefCell<Option<#block_id>>,
changes: std::cell::RefCell<#crate_::runtime_api::OverlayedChanges>,
recorder: Option<std::rc::Rc<std::cell::RefCell<#crate_::runtime_api::ProofRecorder<#block>>>>,
changes: std::cell::RefCell<#crate_::OverlayedChanges>,
recorder: Option<std::rc::Rc<std::cell::RefCell<#crate_::ProofRecorder<#block>>>>,
}
// `RuntimeApi` itself is not threadsafe. However, an instance is only available in a
// `ApiRef` object and `ApiRef` also has an associated lifetime. This lifetimes makes it
// impossible to move `RuntimeApi` into another thread.
#[cfg(any(feature = "std", test))]
unsafe impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> Send for RuntimeApiImpl<C> {}
unsafe impl<C: #crate_::CallRuntimeAt<#block>> Send for RuntimeApiImpl<C> {}
#[cfg(any(feature = "std", test))]
unsafe impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> Sync for RuntimeApiImpl<C> {}
unsafe impl<C: #crate_::CallRuntimeAt<#block>> Sync for RuntimeApiImpl<C> {}
#[cfg(any(feature = "std", test))]
impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> #crate_::runtime_api::ApiExt<#block>
for RuntimeApiImpl<C>
{
impl<C: #crate_::CallRuntimeAt<#block>> #crate_::ApiExt<#block> for RuntimeApiImpl<C> {
type Error = C::Error;
fn map_api_result<F: FnOnce(&Self) -> std::result::Result<R, E>, R, E>(
&self,
map_call: F
) -> ::std::result::Result<R, E> where Self: Sized {
) -> std::result::Result<R, E> where Self: Sized {
*self.commit_on_success.borrow_mut() = false;
let res = map_call(self);
*self.commit_on_success.borrow_mut() = true;
@@ -288,7 +288,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
fn runtime_version_at(
&self,
at: &#block_id
) -> #crate_::error::Result<#crate_::runtime_api::RuntimeVersion> {
) -> std::result::Result<#crate_::RuntimeVersion, C::Error> {
self.call.runtime_version_at(at)
}
@@ -296,7 +296,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
self.recorder = Some(Default::default());
}
fn extract_proof(&mut self) -> Option<#crate_::runtime_api::StorageProof> {
fn extract_proof(&mut self) -> Option<#crate_::StorageProof> {
self.recorder
.take()
.map(|recorder| {
@@ -306,22 +306,22 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
.into_iter()
.map(|record| record.data)
.collect();
#crate_::runtime_api::StorageProof::new(trie_nodes)
#crate_::StorageProof::new(trie_nodes)
})
}
}
#[cfg(any(feature = "std", test))]
impl<C: #crate_::runtime_api::CallRuntimeAt<#block> + 'static>
#crate_::runtime_api::ConstructRuntimeApi<#block, C> for RuntimeApi
impl<C: #crate_::CallRuntimeAt<#block> + 'static> #crate_::ConstructRuntimeApi<#block, C>
for RuntimeApi
{
type RuntimeApi = RuntimeApiImpl<C>;
fn construct_runtime_api<'a>(
call: &'a C,
) -> #crate_::runtime_api::ApiRef<'a, Self::RuntimeApi> {
) -> #crate_::ApiRef<'a, Self::RuntimeApi> {
RuntimeApiImpl {
call: unsafe { ::std::mem::transmute(call) },
call: unsafe { std::mem::transmute(call) },
commit_on_success: true.into(),
initialized_block: None.into(),
changes: Default::default(),
@@ -331,29 +331,28 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
}
#[cfg(any(feature = "std", test))]
impl<C: #crate_::runtime_api::CallRuntimeAt<#block>> RuntimeApiImpl<C> {
impl<C: #crate_::CallRuntimeAt<#block>> RuntimeApiImpl<C> {
fn call_api_at<
R: #crate_::runtime_api::Encode + #crate_::runtime_api::Decode + PartialEq,
R: #crate_::Encode + #crate_::Decode + PartialEq,
F: FnOnce(
&C,
&Self,
&std::cell::RefCell<#crate_::runtime_api::OverlayedChanges>,
&std::cell::RefCell<Option<#crate_::runtime_api::BlockId<#block>>>,
&Option<std::rc::Rc<std::cell::RefCell<#crate_::runtime_api::ProofRecorder<#block>>>>,
) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<R>>,
&std::cell::RefCell<#crate_::OverlayedChanges>,
&std::cell::RefCell<Option<#crate_::BlockId<#block>>>,
&Option<std::rc::Rc<std::cell::RefCell<#crate_::ProofRecorder<#block>>>>,
) -> std::result::Result<#crate_::NativeOrEncoded<R>, E>,
E,
>(
&self,
call_api_at: F,
) -> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<R>> {
let res = unsafe {
call_api_at(
&self.call,
self,
&self.changes,
&self.initialized_block,
&self.recorder,
)
};
) -> std::result::Result<#crate_::NativeOrEncoded<R>, E> {
let res = call_api_at(
&self.call,
self,
&self.changes,
&self.initialized_block,
&self.recorder,
);
self.commit_on_ok(&res);
res
@@ -475,7 +474,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
input.sig.inputs = parse_quote! {
&self,
at: &#block_id,
context: #crate_::runtime_api::ExecutionContext,
context: #crate_::ExecutionContext,
params: Option<( #( #param_types ),* )>,
params_encoded: Vec<u8>,
};
@@ -488,7 +487,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
// Generate the correct return type.
input.sig.output = parse_quote!(
-> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<#ret_type>>
-> std::result::Result<#crate_::NativeOrEncoded<#ret_type>, RuntimeApiImplCall::Error>
);
// Generate the new method implementation that calls into the runtime.
@@ -535,7 +534,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID);
let block = self.node_block;
input.generics.params.push(
parse_quote!( RuntimeApiImplCall: #crate_::runtime_api::CallRuntimeAt<#block> + 'static )
parse_quote!( RuntimeApiImplCall: #crate_::CallRuntimeAt<#block> + 'static )
);
// The implementation for the `RuntimeApiImpl` is only required when compiling with
@@ -621,8 +620,7 @@ fn generate_runtime_api_versions(impls: &[ItemImpl]) -> Result<TokenStream> {
let c = generate_crate_access(HIDDEN_INCLUDES_ID);
Ok(quote!(
const RUNTIME_API_VERSIONS: #c::runtime_api::ApisVec =
#c::runtime_api::create_apis_vec!([ #( #result ),* ]);
const RUNTIME_API_VERSIONS: #c::ApisVec = #c::create_apis_vec!([ #( #result ),* ]);
))
}
@@ -44,14 +44,7 @@ mod utils;
/// # Example
///
/// ```rust
/// #[macro_use]
/// extern crate client;
/// extern crate sr_version as version;
///
/// use version::create_runtime_str;
/// # extern crate test_client;
/// # extern crate sr_primitives;
/// # extern crate primitives;
/// use sr_version::create_runtime_str;
/// #
/// # use sr_primitives::traits::GetNodeBlockType;
/// # use test_client::runtime::{Block, Header};
@@ -63,7 +56,7 @@ mod utils;
/// # type NodeBlock = Block;
/// # }
/// #
/// # decl_runtime_apis! {
/// # sr_api::decl_runtime_apis! {
/// # /// Declare the api trait.
/// # pub trait Balance {
/// # /// Get the balance.
@@ -77,9 +70,9 @@ mod utils;
/// # }
///
/// /// All runtime api implementations need to be done in one call of the macro!
/// impl_runtime_apis! {
/// # impl client::runtime_api::Core<Block> for Runtime {
/// # fn version() -> client::runtime_api::RuntimeVersion {
/// sr_api::impl_runtime_apis! {
/// # impl sr_api::Core<Block> for Runtime {
/// # fn version() -> sr_version::RuntimeVersion {
/// # unimplemented!()
/// # }
/// # fn execute_block(_block: Block) {}
@@ -103,7 +96,7 @@ mod utils;
/// }
///
/// /// Runtime version. This needs to be declared for each runtime.
/// pub const VERSION: version::RuntimeVersion = version::RuntimeVersion {
/// pub const VERSION: sr_version::RuntimeVersion = sr_version::RuntimeVersion {
/// spec_name: create_runtime_str!("node"),
/// impl_name: create_runtime_str!("test-node"),
/// authoring_version: 1,
@@ -134,10 +127,7 @@ pub fn impl_runtime_apis(input: TokenStream) -> TokenStream {
/// # Example
///
/// ```rust
/// #[macro_use]
/// extern crate client;
///
/// decl_runtime_apis! {
/// sr_api::decl_runtime_apis! {
/// /// Declare the api trait.
/// pub trait Balance {
/// /// Get the balance.
@@ -169,10 +159,7 @@ pub fn impl_runtime_apis(input: TokenStream) -> TokenStream {
/// spec version!). Such a method also does not need to be implemented in the runtime.
///
/// ```rust
/// #[macro_use]
/// extern crate client;
///
/// decl_runtime_apis! {
/// sr_api::decl_runtime_apis! {
/// /// Declare the api trait.
/// #[api_version(2)]
/// pub trait Balance {
@@ -37,17 +37,17 @@ fn generate_hidden_includes_mod_name(unique_id: &'static str) -> Ident {
/// Generates the hidden includes that are required to make the macro independent from its scope.
pub fn generate_hidden_includes(unique_id: &'static str) -> TokenStream {
if env::var("CARGO_PKG_NAME").unwrap() == "substrate-client" {
if env::var("CARGO_PKG_NAME").unwrap() == "sr-api" {
TokenStream::new()
} else {
let mod_name = generate_hidden_includes_mod_name(unique_id);
match crate_name("substrate-client") {
match crate_name("sr-api") {
Ok(client_name) => {
let client_name = Ident::new(&client_name, Span::call_site());
quote!(
#[doc(hidden)]
mod #mod_name {
pub extern crate #client_name as sr_api_client;
pub extern crate #client_name as sr_api;
}
)
},
@@ -62,11 +62,11 @@ pub fn generate_hidden_includes(unique_id: &'static str) -> TokenStream {
/// Generates the access to the `substrate_client` crate.
pub fn generate_crate_access(unique_id: &'static str) -> TokenStream {
if env::var("CARGO_PKG_NAME").unwrap() == "substrate-client" {
if env::var("CARGO_PKG_NAME").unwrap() == "sr-api" {
quote!( crate )
} else {
let mod_name = generate_hidden_includes_mod_name(unique_id);
quote!( self::#mod_name::sr_api_client )
quote!( self::#mod_name::sr_api )
}.into()
}
@@ -102,7 +102,6 @@ pub fn replace_wild_card_parameter_names(input: &mut Signature) {
pub fn fold_fn_decl_for_client_side(
input: &mut Signature,
block_id: &TokenStream,
crate_: &TokenStream,
) {
replace_wild_card_parameter_names(input);
@@ -113,7 +112,7 @@ pub fn fold_fn_decl_for_client_side(
// Wrap the output in a `Result`
input.output = {
let ty = return_type_extract_type(&input.output);
parse_quote!( -> std::result::Result<#ty, #crate_::error::Error> )
parse_quote!( -> std::result::Result<#ty, Self::Error> )
};
}
+206
View File
@@ -0,0 +1,206 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! Substrate runtime api
//!
//! The Substrate runtime api is the crucial interface between the node and the runtime.
//! Every call that goes into the runtime is done with a runtime api. The runtime apis are not fixed.
//! Every Substrate user can define its own apis with
//! [`decl_runtime_apis`](macro.decl_runtime_apis.html) and implement them in
//! the runtime with [`impl_runtime_apis`](macro.impl_runtime_apis.html).
//!
//! Every Substrate runtime needs to implement the [`Core`] runtime api. This api provides the basic
//! functionality that every runtime needs to export.
//!
//! Besides the macros and the [`Core`] runtime api, this crates provides the [`Metadata`] runtime
//! api, the [`ApiExt`] trait, the [`CallRuntimeAt`] trait and the [`ConstructRuntimeApi`] trait.
#![cfg_attr(not(feature = "std"), no_std)]
#[doc(hidden)]
#[cfg(feature = "std")]
pub use state_machine::{OverlayedChanges, StorageProof};
#[doc(hidden)]
#[cfg(feature = "std")]
pub use primitives::NativeOrEncoded;
#[doc(hidden)]
#[cfg(not(feature = "std"))]
pub use primitives::to_substrate_wasm_fn_return_value;
#[doc(hidden)]
pub use sr_primitives::{
traits::{
Block as BlockT, GetNodeBlockType, GetRuntimeBlockType,
Header as HeaderT, ApiRef, RuntimeApiInfo, Hash as HashT,
},
generic::BlockId, transaction_validity::TransactionValidity,
};
#[doc(hidden)]
pub use primitives::{offchain, ExecutionContext};
#[doc(hidden)]
pub use sr_version::{ApiId, RuntimeVersion, ApisVec, create_apis_vec};
#[doc(hidden)]
pub use rstd::{slice, mem};
#[cfg(feature = "std")]
use rstd::result;
#[doc(hidden)]
pub use codec::{Encode, Decode};
use primitives::OpaqueMetadata;
#[cfg(feature = "std")]
use std::{panic::UnwindSafe, cell::RefCell, rc::Rc};
#[cfg(feature = "std")]
use primitives::Hasher as HasherT;
pub use sr_api_proc_macro::{decl_runtime_apis, impl_runtime_apis};
#[cfg(feature = "std")]
/// A type that records all accessed trie nodes and generates a proof out of it.
pub type ProofRecorder<B> = state_machine::ProofRecorder<
<<<<B as BlockT>::Header as HeaderT>::Hashing as HashT>::Hasher as HasherT>::Out
>;
/// Something that can be constructed to a runtime api.
#[cfg(feature = "std")]
pub trait ConstructRuntimeApi<Block: BlockT, C: CallRuntimeAt<Block>> {
/// The actual runtime api that will be constructed.
type RuntimeApi;
/// Construct an instance of the runtime api.
fn construct_runtime_api<'a>(call: &'a C) -> ApiRef<'a, Self::RuntimeApi>;
}
/// An extension for the `RuntimeApi`.
#[cfg(feature = "std")]
pub trait ApiExt<Block: BlockT> {
/// Error type used by the interface.
type Error: std::fmt::Debug + From<String>;
/// The given closure will be called with api instance. Inside the closure any api call is
/// allowed. After doing the api call, the closure is allowed to map the `Result` to a
/// different `Result` type. This can be important, as the internal data structure that keeps
/// track of modifications to the storage, discards changes when the `Result` is an `Err`.
/// On `Ok`, the structure commits the changes to an internal buffer.
fn map_api_result<F: FnOnce(&Self) -> result::Result<R, E>, R, E>(
&self,
map_call: F
) -> result::Result<R, E> where Self: Sized;
/// Checks if the given api is implemented and versions match.
fn has_api<A: RuntimeApiInfo + ?Sized>(
&self,
at: &BlockId<Block>
) -> Result<bool, Self::Error> where Self: Sized {
self.runtime_version_at(at).map(|v| v.has_api::<A>())
}
/// Check if the given api is implemented and the version passes a predicate.
fn has_api_with<A: RuntimeApiInfo + ?Sized, P: Fn(u32) -> bool>(
&self,
at: &BlockId<Block>,
pred: P,
) -> Result<bool, Self::Error> where Self: Sized {
self.runtime_version_at(at).map(|v| v.has_api_with::<A, _>(pred))
}
/// Returns the runtime version at the given block id.
fn runtime_version_at(&self, at: &BlockId<Block>) -> Result<RuntimeVersion, Self::Error>;
/// Start recording all accessed trie nodes for generating proofs.
fn record_proof(&mut self);
/// Extract the recorded proof.
/// This stops the proof recording.
fn extract_proof(&mut self) -> Option<StorageProof>;
}
/// Before calling any runtime api function, the runtime need to be initialized
/// at the requested block. However, some functions like `execute_block` or
/// `initialize_block` itself don't require to have the runtime initialized
/// at the requested block.
///
/// `call_api_at` is instructed by this enum to do the initialization or to skip
/// it.
#[cfg(feature = "std")]
#[derive(Clone, Copy)]
pub enum InitializeBlock<'a, Block: BlockT> {
/// Skip initializing the runtime for a given block.
///
/// This is used by functions who do the initialization by themselves or don't require it.
Skip,
/// Initialize the runtime for a given block.
///
/// If the stored `BlockId` is `Some(_)`, the runtime is currently initialized at this block.
Do(&'a RefCell<Option<BlockId<Block>>>),
}
/// Something that can call into the runtime at a given block.
#[cfg(feature = "std")]
pub trait CallRuntimeAt<Block: BlockT> {
/// Error type used by the interface.
type Error: std::fmt::Debug + From<String>;
/// Calls the given api function with the given encoded arguments at the given block and returns
/// the encoded result.
fn call_api_at<
'a,
R: Encode + Decode + PartialEq,
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
C: Core<Block, Error = Self::Error>,
>(
&self,
core_api: &C,
at: &BlockId<Block>,
function: &'static str,
args: Vec<u8>,
changes: &RefCell<OverlayedChanges>,
initialize_block: InitializeBlock<'a, Block>,
native_call: Option<NC>,
context: ExecutionContext,
recorder: &Option<Rc<RefCell<ProofRecorder<Block>>>>,
) -> Result<NativeOrEncoded<R>, Self::Error>;
/// Returns the runtime version at the given block.
fn runtime_version_at(&self, at: &BlockId<Block>) -> Result<RuntimeVersion, Self::Error>;
}
/// Extracts the `Api::Error` for a type that provides a runtime api.
#[cfg(feature = "std")]
pub type ApiErrorFor<T, Block> = <
<T as sr_primitives::traits::ProvideRuntimeApi>::Api as ApiExt<Block>
>::Error;
decl_runtime_apis! {
/// The `Core` runtime api that every Substrate runtime needs to implement.
#[core_trait]
#[api_version(2)]
pub trait Core {
/// Returns the version of the runtime.
fn version() -> RuntimeVersion;
/// Execute the given block.
#[skip_initialize_block]
fn execute_block(block: Block);
/// Initialize a block with the given header.
#[renamed("initialise_block", 2)]
#[skip_initialize_block]
#[initialize_block]
fn initialize_block(header: &<Block as BlockT>::Header);
}
/// The `Metadata` api trait that returns metadata for the runtime.
pub trait Metadata {
/// Returns the metadata of a runtime.
fn metadata() -> OpaqueMetadata;
}
}
+21
View File
@@ -0,0 +1,21 @@
[package]
name = "sr-api-test"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
sr-api = { path = "../" }
test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" }
sr-version = { path = "../../sr-version" }
sr-primitives = { path = "../../sr-primitives" }
consensus_common = { package = "substrate-consensus-common", path = "../../consensus/common" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
state-machine = { package = "substrate-state-machine", path = "../../state-machine" }
trybuild = "1.0.17"
rustversion = "1.0.0"
# We only need this to generate the correct code.
[features]
default = [ "std" ]
std = []
@@ -14,11 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use sr_primitives::traits::{GetNodeBlockType, Block as BlockT};
use sr_primitives::generic::BlockId;
use client::runtime_api::{self, RuntimeApiInfo};
use client::{error::Result, decl_runtime_apis, impl_runtime_apis};
use test_client::runtime::Block;
use sr_api::{RuntimeApiInfo, decl_runtime_apis, impl_runtime_apis};
use sr_primitives::{traits::{GetNodeBlockType, Block as BlockT}, generic::BlockId};
use test_client::{client::error::Result, runtime::Block};
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
@@ -67,8 +67,8 @@ impl_runtime_apis! {
fn same_name() {}
}
impl runtime_api::Core<Block> for Runtime {
fn version() -> runtime_api::RuntimeVersion {
impl sr_api::Core<Block> for Runtime {
fn version() -> sr_version::RuntimeVersion {
unimplemented!()
}
fn execute_block(_: Block) {
@@ -80,7 +80,9 @@ impl_runtime_apis! {
}
}
type TestClient = client::Client<test_client::Backend, test_client::Executor, Block, RuntimeApi>;
type TestClient = test_client::client::Client<
test_client::Backend, test_client::Executor, Block, RuntimeApi
>;
#[test]
fn test_client_side_function_signature() {
@@ -98,15 +100,19 @@ fn test_client_side_function_signature() {
#[test]
fn check_runtime_api_info() {
assert_eq!(&Api::<Block>::ID, &runtime_decl_for_Api::ID);
assert_eq!(Api::<Block>::VERSION, runtime_decl_for_Api::VERSION);
assert_eq!(Api::<Block>::VERSION, 1);
assert_eq!(&Api::<Block, Error = ()>::ID, &runtime_decl_for_Api::ID);
assert_eq!(Api::<Block, Error = ()>::VERSION, runtime_decl_for_Api::VERSION);
assert_eq!(Api::<Block, Error = ()>::VERSION, 1);
assert_eq!(
ApiWithCustomVersion::<Block>::VERSION, runtime_decl_for_ApiWithCustomVersion::VERSION
ApiWithCustomVersion::<Block, Error = ()>::VERSION,
runtime_decl_for_ApiWithCustomVersion::VERSION,
);
assert_eq!(&ApiWithCustomVersion::<Block>::ID, &runtime_decl_for_ApiWithCustomVersion::ID);
assert_eq!(ApiWithCustomVersion::<Block>::VERSION, 2);
assert_eq!(
&ApiWithCustomVersion::<Block, Error = ()>::ID,
&runtime_decl_for_ApiWithCustomVersion::ID,
);
assert_eq!(ApiWithCustomVersion::<Block, Error = ()>::VERSION, 2);
}
fn check_runtime_api_versions_contains<T: RuntimeApiInfo + ?Sized>() {
@@ -115,7 +121,7 @@ fn check_runtime_api_versions_contains<T: RuntimeApiInfo + ?Sized>() {
#[test]
fn check_runtime_api_versions() {
check_runtime_api_versions_contains::<dyn Api<Block>>();
check_runtime_api_versions_contains::<dyn ApiWithCustomVersion<Block>>();
check_runtime_api_versions_contains::<dyn runtime_api::Core<Block>>();
check_runtime_api_versions_contains::<dyn Api<Block, Error = ()>>();
check_runtime_api_versions_contains::<dyn ApiWithCustomVersion<Block, Error = ()>>();
check_runtime_api_versions_contains::<dyn sr_api::Core<Block, Error = ()>>();
}
@@ -1,6 +1,4 @@
use client::decl_runtime_apis;
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api {
fn test(&self);
}
@@ -0,0 +1,5 @@
error: `self` as argument not supported.
--> $DIR/adding_self_parameter.rs:3:11
|
3 | fn test(&self);
| ^
@@ -1,6 +1,5 @@
use sr_primitives::traits::GetNodeBlockType;
use test_client::runtime::Block;
use client::decl_runtime_apis;
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
@@ -9,7 +8,7 @@ impl GetNodeBlockType for Runtime {
type NodeBlock = Block;
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api {
#[changed_in(2)]
fn test(data: u64);
@@ -1,5 +1,5 @@
error: `changed_in` version can not be greater than the `api_version`
--> $DIR/changed_in_unknown_version.rs:15:3
--> $DIR/changed_in_unknown_version.rs:14:3
|
15 | fn test(data: u64);
14 | fn test(data: u64);
| ^^
@@ -1,7 +1,6 @@
use sr_primitives::traits::Block as BlockT;
use client::decl_runtime_apis;
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api<Block: BlockT> {
fn test();
}
@@ -1,13 +1,13 @@
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro!
--> $DIR/declaring_old_block.rs:5:16
--> $DIR/declaring_old_block.rs:4:16
|
5 | pub trait Api<Block: BlockT> {
4 | pub trait Api<Block: BlockT> {
| ^^^^^
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
--> $DIR/declaring_old_block.rs:5:23
--> $DIR/declaring_old_block.rs:4:23
|
5 | pub trait Api<Block: BlockT> {
4 | pub trait Api<Block: BlockT> {
| ^^^^^^
warning: unused import: `sr_primitives::traits::Block as BlockT`
@@ -1,7 +1,6 @@
use sr_primitives::traits::Block as BlockT;
use client::decl_runtime_apis;
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api<B: BlockT> {
fn test();
}
@@ -1,7 +1,7 @@
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
--> $DIR/declaring_own_block_with_different_name.rs:5:19
--> $DIR/declaring_own_block_with_different_name.rs:4:19
|
5 | pub trait Api<B: BlockT> {
4 | pub trait Api<B: BlockT> {
| ^^^^^^
warning: unused import: `sr_primitives::traits::Block as BlockT`
@@ -1,6 +1,5 @@
use sr_primitives::traits::GetNodeBlockType;
use test_client::runtime::Block;
use client::{decl_runtime_apis, impl_runtime_apis};
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
@@ -9,12 +8,12 @@ impl GetNodeBlockType for Runtime {
type NodeBlock = Block;
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api {
fn test(data: u64);
}
}
impl_runtime_apis! {}
sr_api::impl_runtime_apis! {}
fn main() {}
@@ -0,0 +1,5 @@
error: No api implementation given!
--> $DIR/empty_impl_runtime_apis_call.rs:17:1
|
17 | sr_api::impl_runtime_apis! {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation
@@ -1,6 +1,5 @@
use sr_primitives::traits::{GetNodeBlockType, Block as BlockT};
use test_client::runtime::Block;
use client::{decl_runtime_apis, impl_runtime_apis, runtime_api};
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
@@ -9,18 +8,18 @@ impl GetNodeBlockType for Runtime {
type NodeBlock = Block;
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api {
fn test(data: u64);
}
}
impl_runtime_apis! {
sr_api::impl_runtime_apis! {
impl self::Api<Block> for Runtime {
fn test(data: String) {}
}
impl runtime_api::Core<Block> for Runtime {
impl sr_api::Core<Block> for Runtime {
fn version() -> runtime_api::RuntimeVersion {
unimplemented!()
}
@@ -0,0 +1,70 @@
error[E0433]: failed to resolve: use of undeclared type or module `runtime_api`
--> $DIR/impl_incorrect_method_signature.rs:23:19
|
23 | fn version() -> runtime_api::RuntimeVersion {
| ^^^^^^^^^^^ use of undeclared type or module `runtime_api`
error[E0053]: method `test` has an incompatible type for trait
--> $DIR/impl_incorrect_method_signature.rs:19:17
|
13 | fn test(data: u64);
| --- type in trait
...
19 | fn test(data: String) {}
| ^^^^^^ expected u64, found struct `std::string::String`
|
= note: expected type `fn(u64)`
found type `fn(std::string::String)`
error[E0053]: method `Api_test_runtime_api_impl` has an incompatible type for trait
--> $DIR/impl_incorrect_method_signature.rs:17:1
|
11 | / sr_api::decl_runtime_apis! {
12 | | pub trait Api {
13 | | fn test(data: u64);
14 | | }
15 | | }
| |_- type in trait
16 |
17 | sr_api::impl_runtime_apis! {
| -^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| _expected u64, found struct `std::string::String`
| |
18 | | impl self::Api<Block> for Runtime {
19 | | fn test(data: String) {}
20 | | }
... |
32 | | }
33 | | }
| |_- in this macro invocation
|
= note: expected type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::BlockId<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::ExecutionContext, std::option::Option<u64>, std::vec::Vec<u8>) -> std::result::Result<sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::CallRuntimeAt<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
found type `fn(&RuntimeApiImpl<RuntimeApiImplCall>, &sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::BlockId<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>, sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::ExecutionContext, std::option::Option<std::string::String>, std::vec::Vec<u8>) -> std::result::Result<sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::NativeOrEncoded<()>, <RuntimeApiImplCall as sr_api_hidden_includes_DECL_RUNTIME_APIS::sr_api::CallRuntimeAt<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>>::Error>`
error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:17:1
|
17 | / sr_api::impl_runtime_apis! {
18 | | impl self::Api<Block> for Runtime {
19 | | fn test(data: String) {}
20 | | }
... |
32 | | }
33 | | }
| | ^
| | |
| |_expected u64, found struct `std::string::String`
| in this macro invocation
|
= note: expected type `u64`
found type `std::string::String`
error[E0308]: mismatched types
--> $DIR/impl_incorrect_method_signature.rs:19:11
|
19 | fn test(data: String) {}
| ^^^^ expected u64, found struct `std::string::String`
|
= note: expected type `u64`
found type `std::string::String`
@@ -1,6 +1,5 @@
use sr_primitives::traits::GetNodeBlockType;
use test_client::runtime::Block;
use client::{decl_runtime_apis, impl_runtime_apis};
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
@@ -9,7 +8,7 @@ impl GetNodeBlockType for Runtime {
type NodeBlock = Block;
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api {
fn test(data: u64);
}
@@ -25,7 +24,7 @@ mod second {
}
}
impl_runtime_apis! {
sr_api::impl_runtime_apis! {
impl self::Api<Block> for Runtime {
fn test(data: u64) {}
}
@@ -0,0 +1,77 @@
error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration!
--> $DIR/impl_two_traits_with_same_name.rs:32:15
|
32 | impl second::Api<Block> for Runtime {
| ^^^
error: cannot find macro `decl_runtime_apis` in this scope
--> $DIR/impl_two_traits_with_same_name.rs:20:2
|
20 | decl_runtime_apis! {
| ^^^^^^^^^^^^^^^^^
error[E0425]: cannot find function `test2_call_api_at` in `second::runtime_decl_for_Api`
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
27 | / sr_api::impl_runtime_apis! {
28 | | impl self::Api<Block> for Runtime {
29 | | fn test(data: u64) {}
30 | | }
... |
34 | | }
35 | | }
| | ^
| | |
| |_not found in `second::runtime_decl_for_Api`
| in this macro invocation
error[E0425]: cannot find function `test2_native_call_generator` in `second::runtime_decl_for_Api`
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
27 | / sr_api::impl_runtime_apis! {
28 | | impl self::Api<Block> for Runtime {
29 | | fn test(data: u64) {}
30 | | }
... |
34 | | }
35 | | }
| | ^
| | |
| |_not found in `second::runtime_decl_for_Api`
| in this macro invocation
error[E0576]: cannot find method or associated constant `test2` in `second::runtime_decl_for_Api::Api`
--> $DIR/impl_two_traits_with_same_name.rs:33:6
|
33 | fn test2(data: u64) {}
| ^^^^^ not found in `second::runtime_decl_for_Api::Api`
error[E0603]: module `runtime_decl_for_Api` is private
--> $DIR/impl_two_traits_with_same_name.rs:27:1
|
27 | / sr_api::impl_runtime_apis! {
28 | | impl self::Api<Block> for Runtime {
29 | | fn test(data: u64) {}
30 | | }
... |
34 | | }
35 | | }
| |_^
error[E0119]: conflicting implementations of trait `runtime_decl_for_Api::Api<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` for type `Runtime`:
--> $DIR/impl_two_traits_with_same_name.rs:32:2
|
28 | impl self::Api<Block> for Runtime {
| --------------------------------- first implementation here
...
32 | impl second::Api<Block> for Runtime {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Runtime`
error[E0119]: conflicting implementations of trait `Api<sr_primitives::generic::block::Block<sr_primitives::generic::header::Header<u64, sr_primitives::traits::BlakeTwo256>, substrate_test_runtime::Extrinsic>>` for type `RuntimeApiImpl<_>`:
--> $DIR/impl_two_traits_with_same_name.rs:32:2
|
28 | impl self::Api<Block> for Runtime {
| --------------------------------- first implementation here
...
32 | impl second::Api<Block> for Runtime {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `RuntimeApiImpl<_>`
@@ -1,6 +1,4 @@
use client::decl_runtime_apis;
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
#[api_version]
pub trait Api {
fn test(data: u64);
@@ -1,12 +1,12 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version.rs:3:1
--> $DIR/invalid_api_version.rs:1:1
|
3 | / decl_runtime_apis! {
4 | | #[api_version]
5 | | pub trait Api {
6 | | fn test(data: u64);
7 | | }
8 | | }
1 | / sr_api::decl_runtime_apis! {
2 | | #[api_version]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
@@ -14,20 +14,20 @@ error: can't qualify macro invocation with `pub`
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version.rs:3:1
--> $DIR/invalid_api_version.rs:1:1
|
3 | / decl_runtime_apis! {
4 | | #[api_version]
5 | | pub trait Api {
6 | | fn test(data: u64);
7 | | }
8 | | }
1 | / sr_api::decl_runtime_apis! {
2 | | #[api_version]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version.rs:4:4
--> $DIR/invalid_api_version.rs:2:4
|
4 | #[api_version]
2 | #[api_version]
| ^^^^^^^^^^^
@@ -1,6 +1,4 @@
use client::decl_runtime_apis;
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
#[api_version("1")]
pub trait Api {
fn test(data: u64);
@@ -0,0 +1,33 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version_2.rs:1:1
|
1 | / sr_api::decl_runtime_apis! {
2 | | #[api_version("1")]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
|
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_2.rs:1:1
|
1 | / sr_api::decl_runtime_apis! {
2 | | #[api_version("1")]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_2.rs:2:4
|
2 | #[api_version("1")]
| ^^^^^^^^^^^
@@ -1,6 +1,4 @@
use client::decl_runtime_apis;
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
#[api_version()]
pub trait Api {
fn test(data: u64);
@@ -0,0 +1,33 @@
error: can't qualify macro invocation with `pub`
--> $DIR/invalid_api_version_3.rs:1:1
|
1 | / sr_api::decl_runtime_apis! {
2 | | #[api_version()]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
|
= help: try adjusting the macro to put `pub` inside the invocation
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_3.rs:1:1
|
1 | / sr_api::decl_runtime_apis! {
2 | | #[api_version()]
3 | | pub trait Api {
4 | | fn test(data: u64);
5 | | }
6 | | }
| | ^ in this macro invocation
| |_|
|
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
--> $DIR/invalid_api_version_3.rs:2:4
|
2 | #[api_version()]
| ^^^^^^^^^^^
@@ -1,6 +1,5 @@
use sr_primitives::traits::GetNodeBlockType;
use test_client::runtime::Block;
use client::{decl_runtime_apis, impl_runtime_apis};
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
@@ -9,13 +8,13 @@ impl GetNodeBlockType for Runtime {
type NodeBlock = Block;
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api {
fn test(data: u64);
}
}
impl_runtime_apis! {
sr_api::impl_runtime_apis! {
impl self::Api for Runtime {
fn test(data: u64) {
unimplemented!()
@@ -0,0 +1,11 @@
error: Missing `Block` generic parameter.
--> $DIR/missing_block_generic_parameter.rs:18:13
|
18 | impl self::Api for Runtime {
| ^^^
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/missing_block_generic_parameter.rs:18:7
|
18 | impl self::Api for Runtime {
| ^^^^^^^^^ expected 1 type argument
@@ -1,6 +1,5 @@
use sr_primitives::traits::GetNodeBlockType;
use test_client::runtime::Block;
use client::{decl_runtime_apis, impl_runtime_apis};
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
/// trait are done by the `construct_runtime!` macro in a real runtime.
@@ -9,13 +8,13 @@ impl GetNodeBlockType for Runtime {
type NodeBlock = Block;
}
decl_runtime_apis! {
sr_api::decl_runtime_apis! {
pub trait Api {
fn test(data: u64);
}
}
impl_runtime_apis! {
sr_api::impl_runtime_apis! {
impl Api<Block> for Runtime {
fn test(data: u64) {
unimplemented!()

Some files were not shown because too many files have changed in this diff Show More