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

Environment agnostic contract invocation API #2219

Merged
merged 37 commits into from
Apr 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fca4e05
WIP ideas
ascjones Apr 8, 2024
840aa43
Add invocation
ascjones Apr 11, 2024
9c88b33
SP
ascjones Apr 11, 2024
e12d262
Warnings
ascjones Apr 11, 2024
081d718
WIP add info trait
ascjones Apr 16, 2024
6b500cf
Revert "WIP add info trait"
ascjones Apr 16, 2024
667ad39
WIP TraitCallBuilder
ascjones Apr 19, 2024
08da1a0
Revert "WIP TraitCallBuilder"
ascjones Apr 19, 2024
95b8591
Generate and wire up TraitMessageBuilder
ascjones Apr 19, 2024
56ce1a7
trait impl
ascjones Apr 22, 2024
ebde85d
Utilize message builder from call builder
ascjones Apr 22, 2024
19b4dca
Use type inference
ascjones Apr 22, 2024
53eb64d
Try to use new API...
ascjones Apr 22, 2024
d9ed700
Add storage deposit limit
ascjones Apr 23, 2024
cf1b94f
Add sandbox err message
ascjones Apr 23, 2024
bf06c85
Revert "Add sandbox err message"
ascjones Apr 23, 2024
9174a14
message_builder!
ascjones Apr 23, 2024
d198e6b
Invoker Error type
ascjones Apr 23, 2024
1a09074
Invoker -> Executor
ascjones Apr 23, 2024
e0a6d5e
Extract executor to separate file
ascjones Apr 24, 2024
ce6cbbe
Merge branch 'master' into aj/hybrid-ink-api
ascjones Apr 24, 2024
80d5f27
Access TraitCallBuilder from as-dependency call builder
ascjones Apr 24, 2024
a3f21ba
docs
ascjones Apr 24, 2024
054d415
executor ref and move message_builder to own file + docs
ascjones Apr 25, 2024
ae430f7
executor ref and move message_builder to own file + docs
ascjones Apr 25, 2024
574c253
remove message_builder
ascjones Apr 25, 2024
35e633d
message_builder docs
ascjones Apr 25, 2024
6f4022a
fix message_builder doc tests
ascjones Apr 25, 2024
2bacee0
remove conflicting message builder impl
ascjones Apr 25, 2024
0c9480b
fmt
ascjones Apr 25, 2024
75811af
UI tests
ascjones Apr 25, 2024
8753ded
docs
ascjones Apr 25, 2024
12e01c1
Merge branch 'master' into aj/hybrid-ink-api
ascjones Apr 25, 2024
caa0fce
update copypasta comments
ascjones Apr 25, 2024
0aea636
Merge branch 'master' into aj/hybrid-ink-api
ascjones Apr 26, 2024
a34849c
license headers
ascjones Apr 26, 2024
aa9e29f
CHANGELOG.md
ascjones Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP add info trait
ascjones committed Apr 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 081d7185dc1f900215f510cb498587f168ea21c2
11 changes: 11 additions & 0 deletions crates/env/src/call/invocation.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,17 @@
use crate::Environment;
use super::{ExecutionInput, utils::ReturnType};

/// todo: docs
pub trait InvokableMessage {
const SELECTOR: [u8; 4];
type Input: codec::Encode;
type Args;
type Output: codec::Decode;

/// todo: docs
fn exec_input(input: Self::Input) -> ExecutionInput<Self::Args>;
}

/// todo: create a new generated type a la ContractBuilder which produces an instance of this per message.
/// `ink::invoke!(Flip)::flip()` // returns Invoke instance
pub struct Invoke<Args, Output> {
2 changes: 1 addition & 1 deletion crates/env/src/call/mod.rs
Original file line number Diff line number Diff line change
@@ -60,6 +60,6 @@ pub use self::{
LimitParamsV2,
},
execution_input::ExecutionInput,
invocation::{Invoke, Invoker},
invocation::{InvokableMessage, Invoke, Invoker},
selector::Selector,
};
10 changes: 10 additions & 0 deletions crates/ink/codegen/src/generator/trait_def/trait_registry.rs
Original file line number Diff line number Diff line change
@@ -327,12 +327,22 @@ impl TraitRegistry<'_> {
let local_id = message.local_id();
let selector_bytes = selector.hex_lits();
let is_payable = message.ink_attrs().is_payable();
let input_types = generator::input_types(message.inputs());
let arg_list = generator::generate_argument_list(input_types.iter().cloned());
let output_type =
message.output().map_or_else(|| quote! { () }, |output| quote! { #output });
quote_spanned!(span=>
impl<E> ::ink::reflect::TraitMessageInfo<#local_id> for #trait_info_ident<E> {
const PAYABLE: ::core::primitive::bool = #is_payable;

const SELECTOR: [::core::primitive::u8; 4usize] = [ #( #selector_bytes ),* ];
}

impl<E> ::ink::reflect::InvokableMessageInfo<#local_id> for #trait_info_ident<E> {
const SELECTOR: [::core::primitive::u8; 4usize] = [ #( #selector_bytes ),* ];
type Input: ::ink::env::call::ExecutionInput<#arg_list>;
type Output: #output_type;
}
)
}
}
20 changes: 20 additions & 0 deletions crates/ink/src/reflect/invoke.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/// todo: docs
pub trait InvokableMessageInfo<const ID: u32> {
const SELECTOR: [u8; 4];
type Input: codec::Encode;
type Output: codec::Decode;
}
2 changes: 2 additions & 0 deletions crates/ink/src/reflect/mod.rs
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
mod contract;
mod dispatch;
mod trait_def;
mod invoke;

pub use self::{
contract::ContractName,
@@ -40,6 +41,7 @@ pub use self::{
DispatchableMessageInfo,
ExecuteDispatchable,
},
invoke::InvokableMessageInfo,
trait_def::{
TraitDefinitionRegistry,
TraitInfo,
Original file line number Diff line number Diff line change
@@ -68,6 +68,8 @@ pub mod pallet {
marker: Default::default()
};

// flipper.flip().invoke(invoker);

let call = call_builder.flip().params();

let invoke = Invoke::<EmptyArgumentList, ()>::new(call.exec_input().clone());
@@ -90,12 +92,14 @@ struct PalletContractsInvoker<E: Environment, Runtime: pallet_contracts::Config>
marker: core::marker::PhantomData<E>,
}

impl<E, R> Invoker<E> for PalletContractsInvoker<E, R>
use ink::reflect::InvokableMessageInfo;

impl<E, R> PalletContractsInvoker<E, R>
where
E: Environment,
R: pallet_contracts::Config,
{
fn invoke<Args, Output>(self, input: &ExecutionInput<Args>) -> Result<ink::MessageResult<Output>, ()>
fn invoke<<MessageInfo: >>(self, input: &ExecutionInput<Args>) -> Result<ink::MessageResult<Output>, ()>
where
Args: codec::Encode,
Output: codec::Decode,