-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic contract calling runtime * Offchain setting * Onchain env: reach seal function * Feature-gating * Pass call * Revert - e2e framework doesn't support custom environment * Use just encodable argument * Pass decodable struct (however call is trapped :( ) * Works with 0 transfer * Fix * Docs, remove leftovers * Clippy * docline * Ignore test * typo * CHANGELOG.md, example README.md * Update CHANGELOG.md Co-authored-by: German <german.nikolishin@gmail.com> * Update crates/env/Cargo.toml * Syntactic improvements * Comparison to chain extension * Indices explanation * Reason for sp-io in deps * Rename enum variant. Docs. Return result. Failure e2e * Env API docs * spellcheck * ... * Clean Cargo.toml * Note about unstable host * Remove offline test * Rephrase note * Review * Doc about panic in off-chain env * Add feature instead of ignoring * Add feature instead of ignoring * Error * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Rename variant error * PAnics * Warnign * #[allow(clippy::enum_variant_names)] * uitest * uitest * Missing testcases * Update examples/call-runtime/lib.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update examples/call-runtime/lib.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Bump example version * Fix some nitpicks * Rename error variant * Remove allowance macro * Note * Remove note * Remove example * As integration test * Versions * Fix changelog --------- Co-authored-by: Andrew Jones <ascjones@gmail.com> Co-authored-by: German <german.nikolishin@gmail.com> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> Co-authored-by: Hernando Castano <hernando@hcastano.com>
- Loading branch information
1 parent
e9321aa
commit 93ee7fb
Showing
15 changed files
with
497 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore build artifacts from the local tests sub-crate. | ||
/target/ | ||
|
||
# Ignore backup files creates by cargo fmt. | ||
**/*.rs.bk | ||
|
||
# Remove Cargo.lock when creating an executable, leave it for libraries | ||
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[package] | ||
name = "call-runtime" | ||
version = "4.0.0" | ||
authors = ["Parity Technologies <admin@parity.io>"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
ink = { path = "../../crates/ink", default-features = false, features = ["call-runtime"] } | ||
|
||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } | ||
|
||
# Substrate | ||
# | ||
# We need to explicitly turn off some of the `sp-io` features, to avoid conflicts | ||
# (especially for global allocator). | ||
# | ||
# See also: https://substrate.stackexchange.com/questions/4733/error-when-compiling-a-contract-using-the-xcm-chain-extension. | ||
sp-io = { version = "18.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } | ||
sp-runtime = { version = "19.0.0", default-features = false } | ||
|
||
[dev-dependencies] | ||
ink_e2e = { path = "../../crates/e2e" } | ||
|
||
[lib] | ||
path = "lib.rs" | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink/std", | ||
"scale/std", | ||
"scale-info/std", | ||
"sp-runtime/std", | ||
"sp-io/std", | ||
] | ||
ink-as-dependency = [] | ||
e2e-tests = [] | ||
|
||
# Assumes that the node used in E2E testing allows using the `call-runtime` API, including triggering | ||
# `Balances::transfer` extrinsic. | ||
permissive-node = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# `call-runtime` example | ||
|
||
## What is this example about? | ||
|
||
It demonstrates how to call a runtime dispatchable from an ink! contract. | ||
|
||
## Chain-side configuration | ||
|
||
To integrate this example into Substrate you need to adjust pallet contracts configuration in your runtime: | ||
```rust | ||
// In your node's runtime configuration file (runtime.rs) | ||
impl pallet_contracts::Config for Runtime { | ||
… | ||
// `Everything` or anything that will allow for the `Balances::transfer` extrinsic. | ||
type CallFilter = frame_support::traits::Everything; | ||
type UnsafeUnstableInterface = ConstBool<true>; | ||
… | ||
} | ||
``` | ||
|
||
## Comparison to `ChainExtension` | ||
|
||
Just as a chain extension, `call_runtime` API allows contracts for direct calling to the runtime. | ||
You can trigger any extrinsic that is not forbidden by `pallet_contracts::Config::CallFilter`. | ||
Consider writing a chain extension if you need to perform one of the following tasks: | ||
- Return data. | ||
- Provide functionality **exclusively** to contracts. | ||
- Provide custom weights. | ||
- Avoid the need to keep the `Call` data structure stable. |
Oops, something went wrong.