Skip to content
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

Implement ink! chain extensions #592

Merged
merged 88 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
71318f8
add new tests for #[ink(namespace = ..)] and #[ink(selector = ..)] attrs
Robbepop Nov 24, 2020
689f841
[lang] implement new errors for ink! attributes: namespace, selector
Robbepop Nov 24, 2020
1006358
add #[ink(extension = N: u32)] attribute
Robbepop Nov 24, 2020
c1dbe2c
apply rustfmt
Robbepop Nov 24, 2020
1d485f4
[lang] add initial implementation of chain extension proc. macro
Robbepop Nov 24, 2020
6b08ead
[lang] rename AttributeArg -> AttributeFrag
Robbepop Nov 24, 2020
4497728
rename AttributeFrag::kind field to arg
Robbepop Nov 24, 2020
879c645
rename AttributeArgKind -> AttributeArg
Robbepop Nov 24, 2020
1bbfa2e
[lang] apply rustfmt
Robbepop Nov 24, 2020
ecb7d70
add Display impl for AttributeArgKind
Robbepop Nov 24, 2020
b20e76e
[lang] use AttributeArgKind in sanitize_attributes and ensure_first m…
Robbepop Nov 24, 2020
509277d
[lang/ir] improve error reporting for duplicate ink! attributes
Robbepop Nov 30, 2020
e4e6381
[lang/ir] refactoring and improvements to chain extension IR impl
Robbepop Nov 30, 2020
4ca9e3a
[lang/ir] add tests for IR implementation of chain extensions
Robbepop Nov 30, 2020
d3b7eb5
[lang/ir] remove some code dupe
Robbepop Nov 30, 2020
4a2fb12
[lang/ir] add getters to ChainExtension
Robbepop Nov 30, 2020
ed35fc3
[lang/ir] add re-exports for ChainExtension definitions
Robbepop Nov 30, 2020
954f9ec
[lang/codegen] add initial impl for ChainExtensions
Robbepop Nov 30, 2020
3ae09cf
[env] add ChainExtension assoc type to the Environment trait
Robbepop Nov 30, 2020
ad5b3c7
[lang] initial impl to make it possible to use chain extension syntax
Robbepop Nov 30, 2020
d7e2c93
[env] improvements to chain extensions API
Robbepop Nov 30, 2020
2adb3f1
[lang/macro] add UI test for chain extension
Robbepop Nov 30, 2020
359c4d3
[lang/macro] register new UI test
Robbepop Nov 30, 2020
56e6481
[lang/codegen] fix some codegen bugs with new chain extension feature
Robbepop Nov 30, 2020
818797a
[lang, env] apply rustfmt
Robbepop Nov 30, 2020
8d9b50b
[lang/ir] apply clippy suggestions and fix outdated error messages
Robbepop Nov 30, 2020
f918b1a
[lang/ir] fix some tests and incorrect error messages
Robbepop Nov 30, 2020
e37c2ba
[examples] apply clippy suggestion
Robbepop Nov 30, 2020
30fbe6c
add ErrorCode to ink! chain extension trait
Robbepop Jan 5, 2021
120fa8d
add FromStatusCode trait to ink_lang
Robbepop Jan 5, 2021
f028bfa
add #[ink(expect_output)] and #[ink(expect_ok)] attributes
Robbepop Jan 5, 2021
7d0bb2f
add ink_lang::IsResultType trait
Robbepop Jan 5, 2021
5762797
add ChainExtensionMethodInputs iterator
Robbepop Jan 5, 2021
34426a6
hide docs for IsResultType trait
Robbepop Jan 5, 2021
8d537a1
add some docs to chain extension codegen
Robbepop Jan 5, 2021
3650961
implement expect_ok and expect_output where bounds in codegen
Robbepop Jan 5, 2021
5ce9ff7
apply code review suggestions by (cmichi)
Robbepop Jan 6, 2021
3d6cc04
add ReturnCode::into_u32 getter
Robbepop Jan 6, 2021
0dd9379
change return type of ext::call_chain_extension: RetCode -> u32
Robbepop Jan 6, 2021
24fb801
[lang] add ChainExtension trait
Robbepop Jan 7, 2021
93ac621
change EnvBackend::call_chain_extension signature
Robbepop Jan 7, 2021
00163c0
remove old high-level API for calling chain extension methods
Robbepop Jan 7, 2021
ae700ef
[env] add new high-level module to handle chain extension calls
Robbepop Jan 7, 2021
8543907
rename ChainExtensionMethodInstance -> ChainExtensionMethod
Robbepop Jan 7, 2021
ccff12d
[env] add doc examples to chain extension method API
Robbepop Jan 7, 2021
40fdc9b
Merge branch 'master' of github.com:paritytech/ink into robin-impl-ch…
Robbepop Jan 7, 2021
b6ee46e
apply rustfmt
Robbepop Jan 7, 2021
69c3ca4
[env] clippy: allow complex type in ChainExtensionMethod type state
Robbepop Jan 7, 2021
e036316
silence some warnings
Robbepop Jan 7, 2021
bbf8989
re-export IsResultType from ink_lang crate
Robbepop Jan 7, 2021
53ababb
[lang] remove FromStatusCode trait
Robbepop Jan 7, 2021
6871d8e
[lang] update codegen for chain extensions
Robbepop Jan 7, 2021
95fa730
[lang] update simple chain extension test
Robbepop Jan 7, 2021
483e8f0
apply rustfmt
Robbepop Jan 7, 2021
273719a
update some license headers
Robbepop Jan 7, 2021
45a55fb
[env] fix where bound
Robbepop Jan 8, 2021
ca7d512
extend chain extension test case to cover all cases
Robbepop Jan 8, 2021
1bfb725
add messages for read_small, access and unlock_access
Robbepop Jan 8, 2021
fecaa76
fix some bugs with chain extension method signatures in test
Robbepop Jan 8, 2021
f29f757
fix some bugs and docs in chain extension test
Robbepop Jan 8, 2021
7c8a10e
fix test
Robbepop Jan 8, 2021
dfd9762
update quickcheck to 1.0
Robbepop Jan 8, 2021
8b19a0b
[env] implement chain extension calling for off-chain env
Robbepop Jan 11, 2021
9a27816
apply rustfmt
Robbepop Jan 11, 2021
8a0a9bf
add docs to #[ink::chain_extension] proc. macro
Robbepop Jan 11, 2021
66847c4
rename env_types -> env everywhere
Robbepop Jan 11, 2021
9516c55
make doc examples for #[ink::chain_extension] compile
Robbepop Jan 11, 2021
017f71d
add yet another technical limitation
Robbepop Jan 11, 2021
413e79f
make link to simple.rs test case more stable (point to revision)
Robbepop Jan 12, 2021
c39e3a3
fix docs (code suggestion)
Robbepop Jan 12, 2021
c98519e
fix docs (code suggestion)
Robbepop Jan 12, 2021
8fa81ee
fix docs (code suggestion)
Robbepop Jan 12, 2021
4511979
fix docs (code suggestion)
Robbepop Jan 12, 2021
1541098
add dev. note to Backend::call_chain_extension
Robbepop Jan 12, 2021
336bc90
fix docs example (code suggestion)
Robbepop Jan 12, 2021
a14a3ae
[env] chain extension: make doc examples/tests compile
Robbepop Jan 12, 2021
31fad38
fix some doc comments according to review suggestions
Robbepop Jan 12, 2021
9ea71ed
review suggestion: telling -> meaning
Robbepop Jan 12, 2021
bdad11d
fix docs (review suggestion)
Robbepop Jan 12, 2021
2eadb1a
fix docs (review suggestion)
Robbepop Jan 12, 2021
a839e88
improve docs (review suggestion)
Robbepop Jan 12, 2021
b6eaeb9
rename chain extension test file
Robbepop Jan 12, 2021
4d05e11
Merge branch 'robin-impl-chain-extension' of github.com:paritytech/in…
Robbepop Jan 12, 2021
cb2fc00
analyse_error_code add doc comments for possible errors
Robbepop Jan 12, 2021
016a993
rename expect_ok -> returns_result and expect_output -> handle_status
Robbepop Jan 12, 2021
a14405a
[lang/ir] improve error reporting for ink! namespace attribute with m…
Robbepop Jan 12, 2021
5182c29
[lang/*] implement new handle_status and returns_result attributes
Robbepop Jan 12, 2021
5fcb008
[env] apply rustfmt
Robbepop Jan 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ std = [
"sha3",
"blake2",
]
ink-unstable-chain-extensions = []
21 changes: 0 additions & 21 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,27 +436,6 @@ where
})
}

/// Calls the chain extension with the given ID and inputs.
///
/// Returns the given output type.
///
/// # Errors
///
/// - If the given function ID does not exist in the runtime.
/// - If the given inputs cannot be properly decoded by the runtime.
/// - If the given output type cannot be properly decoded by the contract.
/// - If some chain extension specific conditions are not met.
#[cfg(feature = "ink-unstable-chain-extensions")]
pub fn call_chain_extension<I, O>(func_id: u32, input: &I) -> Result<O>
where
I: scale::Codec + 'static,
O: scale::Codec + 'static,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
EnvBackend::call_chain_extension(instance, func_id, input)
})
}

/// Returns the execution input to the executed contract and decodes it as `T`.
///
/// # Note
Expand Down
28 changes: 23 additions & 5 deletions crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub trait EnvBackend {
H: CryptoHash,
T: scale::Encode;

/// Calls the chain extension with the given ID and inputs.
/// Low-level interface to call a chain extension method.
///
/// Returns the output of the chain extension of the specified type.
///
Expand All @@ -138,11 +138,29 @@ pub trait EnvBackend {
/// - If the inputs had an unexpected encoding.
/// - If the output could not be properly decoded.
/// - If some extension specific condition has not been met.
Robbepop marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "ink-unstable-chain-extensions")]
fn call_chain_extension<I, O>(&mut self, func_id: u32, input: &I) -> Result<O>
///
/// # Dev. Note
///
/// A valid implementation applies the `status_to_result` closure on
/// the status code returned by the actual call to the chain extension
/// method.
/// Only if the closure finds that the given status code indicates a
/// successful call to the chain extension method is the resulting
/// output buffer passed to the `decode_to_result` closure, in order to
/// drive the decoding and error management process from the outside.
fn call_chain_extension<I, T, E, ErrorCode, F, D>(
&mut self,
func_id: u32,
input: &I,
status_to_result: F,
decode_to_result: D,
) -> ::core::result::Result<T, E>
where
I: scale::Codec + 'static,
O: scale::Codec + 'static;
I: scale::Encode,
T: scale::Decode,
E: From<ErrorCode>,
F: FnOnce(u32) -> ::core::result::Result<(), ErrorCode>,
D: FnOnce(&[u8]) -> ::core::result::Result<T, E>;
}

/// Environmental contract functionality.
Expand Down
14 changes: 7 additions & 7 deletions crates/env/src/call/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ where
E: Environment,
{
CallBuilder {
env_types: Default::default(),
env: Default::default(),
callee: Default::default(),
gas_limit: Default::default(),
transferred_value: Default::default(),
Expand All @@ -220,7 +220,7 @@ pub struct CallBuilder<E, Callee, GasLimit, TransferredValue, Args, RetType>
where
E: Environment,
{
env_types: PhantomData<fn() -> E>,
env: PhantomData<fn() -> E>,
/// The current parameters that have been built up so far.
callee: Callee,
gas_limit: GasLimit,
Expand All @@ -242,7 +242,7 @@ where
) -> CallBuilder<E, Set<E::AccountId>, GasLimit, TransferredValue, Args, RetType>
{
CallBuilder {
env_types: Default::default(),
env: Default::default(),
callee: Set(callee),
gas_limit: self.gas_limit,
transferred_value: self.transferred_value,
Expand All @@ -264,7 +264,7 @@ where
gas_limit: u64,
) -> CallBuilder<E, Callee, Set<u64>, TransferredValue, Args, RetType> {
CallBuilder {
env_types: Default::default(),
env: Default::default(),
callee: self.callee,
gas_limit: Set(gas_limit),
transferred_value: self.transferred_value,
Expand All @@ -286,7 +286,7 @@ where
transferred_value: E::Balance,
) -> CallBuilder<E, Callee, GasLimit, Set<E::Balance>, Args, RetType> {
CallBuilder {
env_types: Default::default(),
env: Default::default(),
callee: self.callee,
gas_limit: self.gas_limit,
transferred_value: Set(transferred_value),
Expand Down Expand Up @@ -327,7 +327,7 @@ where
R: IndicateReturnType,
{
CallBuilder {
env_types: Default::default(),
env: Default::default(),
callee: self.callee,
gas_limit: self.gas_limit,
transferred_value: self.transferred_value,
Expand Down Expand Up @@ -362,7 +362,7 @@ where
RetType,
> {
CallBuilder {
env_types: Default::default(),
env: Default::default(),
callee: self.callee,
gas_limit: self.gas_limit,
transferred_value: self.transferred_value,
Expand Down
12 changes: 6 additions & 6 deletions crates/env/src/call/create_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub struct CreateBuilder<E, CodeHash, GasLimit, Endowment, Args, R>
where
E: Environment,
{
env_types: PhantomData<fn() -> E>,
env: PhantomData<fn() -> E>,
code_hash: CodeHash,
gas_limit: GasLimit,
endowment: Endowment,
Expand Down Expand Up @@ -181,7 +181,7 @@ where
R: FromAccountId<E>,
{
CreateBuilder {
env_types: Default::default(),
env: Default::default(),
code_hash: Default::default(),
gas_limit: Default::default(),
endowment: Default::default(),
Expand All @@ -202,7 +202,7 @@ where
code_hash: E::Hash,
) -> CreateBuilder<E, Set<E::Hash>, GasLimit, Endowment, Args, R> {
CreateBuilder {
env_types: Default::default(),
env: Default::default(),
code_hash: Set(code_hash),
gas_limit: self.gas_limit,
endowment: self.endowment,
Expand All @@ -224,7 +224,7 @@ where
gas_limit: u64,
) -> CreateBuilder<E, CodeHash, Set<u64>, Endowment, Args, R> {
CreateBuilder {
env_types: Default::default(),
env: Default::default(),
code_hash: self.code_hash,
gas_limit: Set(gas_limit),
endowment: self.endowment,
Expand All @@ -246,7 +246,7 @@ where
endowment: E::Balance,
) -> CreateBuilder<E, CodeHash, GasLimit, Set<E::Balance>, Args, R> {
CreateBuilder {
env_types: Default::default(),
env: Default::default(),
code_hash: self.code_hash,
gas_limit: self.gas_limit,
endowment: Set(endowment),
Expand Down Expand Up @@ -276,7 +276,7 @@ where
) -> CreateBuilder<E, CodeHash, GasLimit, Endowment, Set<ExecutionInput<Args>>, R>
{
CreateBuilder {
env_types: Default::default(),
env: Default::default(),
code_hash: self.code_hash,
gas_limit: self.gas_limit,
endowment: self.endowment,
Expand Down