-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support call_runtime
#1641
Support call_runtime
#1641
Changes from 55 commits
d6f55bc
d3a1291
7ad9137
6a47080
1a6cb26
6e21f63
4918b82
b9503cc
5f5e2ae
ed4a155
9210619
d80b3bb
2e3d71c
99982d4
9943cbe
f825412
2991153
2e7bcb4
880b84c
4e69291
0f8f142
cc13064
93c535b
4ef1ce9
a15dbce
e81fb98
9f59e7a
2285c87
13225e2
d4665f9
84dc23e
ee7cfcb
ca6238d
89147f1
f3073de
e981d47
db85259
883739d
dff8d92
c3fe8f2
614dae7
315900a
1dfd5f5
560b954
23f71a5
4671f0d
59a0cb0
3dcd483
27e0f0b
bf34580
f15c1b6
507e526
fe98dfe
b1f9845
fcf4d85
8284ddb
c81398f
855f4e0
fe76dda
3b4beb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,5 @@ std = [ | |
ink-debug = [ | ||
"ink_env/ink-debug", | ||
] | ||
call-runtime = ["ink_env/call-runtime"] | ||
show-codegen-docs = [] |
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 |
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 <[email protected]>"] | ||
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 = "12.0.0", default-features = false, features = ["disable_panic_handler", "disable_oom", "disable_allocator"] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is pretty ugly. Let's keep it for now, but can you explain why we need to have these particular feature flags There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
agryaznov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sp-runtime = { version = "12.0.0", default-features = false } | ||
agryaznov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[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 = [] |
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>; | ||
… | ||
} | ||
``` | ||
HCastano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, why was this removed? Looks accidental @pmikolajczyk41 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have done this during some semi-automatic merging - that explains the last request for change above :|