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

Add support for language level errors (LangError) #1450

Merged
merged 111 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
c62ea25
Add example cross-chain contract
HCastano Oct 22, 2022
5e8cd1e
Update `CallBuilder`'s return type to a `Result`
HCastano Oct 24, 2022
728c45c
Write to output buffer on dispatch error
HCastano Oct 25, 2022
810ea54
Whoops, reduce value of `u8`
HCastano Oct 25, 2022
980f6a7
Add some `cargo-contract` automation helpers
HCastano Oct 25, 2022
6181d9c
Set default if no input is given
HCastano Oct 25, 2022
63fc94c
Return type expected by call builder after succesful dispatch
HCastano Oct 25, 2022
4280d37
Fix typo
HCastano Oct 25, 2022
474133a
Return an actual `DispatchError` back to the caller
HCastano Oct 26, 2022
e3f67ea
Temporarily stop generating contract ref code
HCastano Oct 31, 2022
6a04bd1
Manually change message return type to Result
HCastano Oct 31, 2022
5c9d250
Transform message return type in the IR
HCastano Oct 31, 2022
a989be6
Change message return type when generating contract reference
HCastano Oct 31, 2022
a9cae76
Return message output directly in the codegen
HCastano Nov 1, 2022
b3e0141
Add error type for handling language errors
HCastano Nov 1, 2022
cf332b7
Clean up some things
HCastano Nov 1, 2022
845b009
Merge branch 'master' into hc-add-ink-level-errors
HCastano Nov 1, 2022
dc1b7a3
Remove some unused code
HCastano Nov 1, 2022
2ad4633
Add DispatchError type metadata
ascjones Nov 2, 2022
5421a0c
Merge branch 'master' into hc-add-ink-level-errors
ascjones Nov 2, 2022
14b5875
Use language error over dispatch error
HCastano Nov 2, 2022
a38a395
Change message body's visibility based on message signature
HCastano Nov 2, 2022
a4d653b
Fix unreachable code warning
HCastano Nov 2, 2022
fc42d66
Appease Clippy
HCastano Nov 2, 2022
9705ff3
Rustfmt cross-contract example
HCastano Nov 2, 2022
fc7f374
align for runtime metadata compatibility
xermicus Nov 4, 2022
7869558
Merge branch 'master' into hc-add-ink-level-errors
xermicus Nov 4, 2022
a668018
Fix formatting
HCastano Nov 7, 2022
89d2cf5
Write `lang_error` into metadata using spec builder
HCastano Nov 7, 2022
68417b7
Use `parse_quote` macro over the `syn::parse` function
HCastano Nov 7, 2022
f2ef955
Use correct span in call builder
HCastano Nov 7, 2022
183dc11
Always return `Type` instead of `Option` from `wrapped_output`
HCastano Nov 7, 2022
26e1170
Merge branch 'master' into hc-add-ink-level-errors
HCastano Nov 7, 2022
ae11633
Temporarily appease Clippy
HCastano Nov 7, 2022
1630b3d
Another temporary Clippy fix
HCastano Nov 7, 2022
2e7b5bc
Generate checked and unchecked versions of contract messages
HCastano Nov 7, 2022
87ca721
Use non-checked message as checked message implementation
HCastano Nov 7, 2022
66dd9d1
Remove error handling from test
HCastano Nov 7, 2022
517d408
Add method for generating checked message idents
HCastano Nov 8, 2022
1b6cacc
Merge branch 'master' into hc-add-ink-level-errors
HCastano Nov 8, 2022
150e4d3
Fix UI tests related to `no_implicit_prelude`
HCastano Nov 9, 2022
e59f53e
Merge branch 'master' into hc-add-ink-level-errors
HCastano Nov 9, 2022
d68777e
Remove unneccessary import
HCastano Nov 9, 2022
4f2caad
Add `Default` implementation for `cross_chain_test`
HCastano Nov 9, 2022
f617a0c
Bless some UI tests
HCastano Nov 9, 2022
105fe23
Update `Output` type for doc test
HCastano Nov 9, 2022
90cf477
Update `cross_chain_test` to appease Clippy
HCastano Nov 9, 2022
3774d29
Generate `*_checked` functions for `ContractRef` calls
HCastano Nov 10, 2022
13d7a42
Implement `Debug` for Multisig Wasm builds
HCastano Nov 10, 2022
8929234
Add another `Debug` impl
HCastano Nov 10, 2022
bb6c445
Add `lang_error` to metadata tests
HCastano Nov 10, 2022
10c9e7d
Add example which uses ContractRefs
HCastano Nov 10, 2022
57ddec7
Handle dispatch error in example
HCastano Nov 10, 2022
077d15b
Add UI test for checking that messages now return `Result`s
HCastano Nov 10, 2022
816f312
Add test for message hygiene (or lack thereof)
HCastano Nov 10, 2022
636e7c9
Add test to check that `*_checked` messages are generated
HCastano Nov 10, 2022
e2d8194
Remove debug logging from macro code
HCastano Nov 10, 2022
94449dd
Appease Clippy
HCastano Nov 10, 2022
f1137a7
Remove `--skip-linting` from scripts
HCastano Nov 11, 2022
2afef50
Fix fallible constructor revert, make `Ok` explicit
ascjones Nov 11, 2022
ed1aeec
Hack together E2E test example for `LangError`
HCastano Nov 11, 2022
ed60df8
Add a couple of type aliases to E2E test
HCastano Nov 13, 2022
8cea958
Add E2E test which demonstrates write-on-err bug
HCastano Nov 13, 2022
2488761
Split out E2E tests into seperate functions
HCastano Nov 13, 2022
3670755
Merge branch 'aj/add-ink-level-errors' into hc-add-ink-level-errors
HCastano Nov 13, 2022
412c9ac
Tweak E2E tests to make them pass given Andrew's fixes
HCastano Nov 13, 2022
59bde0e
Remove outdated UI test
HCastano Nov 13, 2022
6eea67e
Fix a couple more tests
HCastano Nov 13, 2022
a78b042
Unify output type and arrow in codegen
HCastano Nov 14, 2022
96c9c42
Allow `result_unit_err` Clippy lint
HCastano Nov 14, 2022
f113dc2
Move `Flipper` functionality into integration example
HCastano Nov 14, 2022
f6b4c10
Rename `cross_chain_test` to indicate that its an integration test
HCastano Nov 15, 2022
8b8eec8
Remove test helper scripts
HCastano Nov 15, 2022
6c24543
Remove `ContractRef` example/compile test
HCastano Nov 15, 2022
ce67e87
Appease Clippy
HCastano Nov 15, 2022
f5b5ae4
Add `MessageResult` type alias
HCastano Nov 15, 2022
0fbbae1
Remove `Ref` re-export from Flipper
HCastano Nov 15, 2022
894e898
Remove TODOs related to E2E issues
HCastano Nov 15, 2022
fa9d57b
Work around `additional_contracts` bug by moving tests
HCastano Nov 15, 2022
51dec24
Clean up `lang_err_integration_tests` a bit
HCastano Nov 15, 2022
cee90d7
Fix spellcheck lint
HCastano Nov 15, 2022
b1cfc9f
Merge branch 'master' into hc-add-ink-level-errors
HCastano Nov 15, 2022
1870988
Place E2E tests behind feature flag
HCastano Nov 15, 2022
476ed65
Apply suggestions from code review
HCastano Nov 15, 2022
2ce3677
Unwrap message result in delegator E2E tests
HCastano Nov 15, 2022
3410224
Revert "Remove `ContractRef` example/compile test"
HCastano Nov 15, 2022
98aa04f
Move `LangError` integration tests into single workspace
HCastano Nov 15, 2022
0164c01
Move flip related E2E tests to `integration_flipper`
HCastano Nov 15, 2022
3ed6521
Move `integration_flipper` into its own folder
HCastano Nov 15, 2022
a82346e
Update `call_builder` test to use `integration_flipper`
HCastano Nov 15, 2022
50c5f4e
Get `contract_ref` E2E test working again
HCastano Nov 15, 2022
d63cae1
Fill out author and version metadata
HCastano Nov 15, 2022
55c4f3c
Add integration tests to CI
HCastano Nov 15, 2022
671377e
Remove leftover .gitignore
HCastano Nov 15, 2022
c7b8b07
Skip default checks if it's a lang error integration test
HCastano Nov 15, 2022
ed6a6d6
Fix UI test
HCastano Nov 15, 2022
1a74375
Skip a few CI stages
HCastano Nov 15, 2022
dff5ada
Add back Clippy stage
HCastano Nov 15, 2022
26e2e37
Revert "Skip a few CI stages"
HCastano Nov 15, 2022
49d2ee4
Run `LangError` E2E tests in CI
HCastano Nov 15, 2022
5785eb0
Rename tests using kabob-case instead of snake_case
HCastano Nov 15, 2022
7d57f8c
Try running with `staging` image
HCastano Nov 16, 2022
2b05e59
Change image back to `production`
HCastano Nov 16, 2022
80a27a7
Try cleaning some things
HCastano Nov 16, 2022
0212c90
Guess there was no lockfile
HCastano Nov 16, 2022
12bc824
Clean up the cleanup
HCastano Nov 16, 2022
55b4e4f
Clean em up again
HCastano Nov 16, 2022
1644343
Use `MessageResult` typedef in one more place
HCastano Nov 16, 2022
f1211ba
Poke CI
HCastano Nov 16, 2022
9a1e41f
Move comment location
HCastano Nov 16, 2022
4057790
Update contract name
HCastano Nov 16, 2022
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
27 changes: 27 additions & 0 deletions call-contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -ex

F="${1:-pass}"
CROSS_CONTRACT_ADDR=$2
FLIPPER_ADDR=$3

SELECTOR="0x633aa551"
BAD_SELECTOR="0x00000000"

args=()
args+=( --contract ${CROSS_CONTRACT_ADDR} )
args+=( --message call )
args+=( --suri //Alice )
args+=( --manifest-path ./examples/cross_chain_test/Cargo.toml )
args+=( --verbose )
args+=( --skip-confirm )

case $F in
'--fail')
args+=( --args $FLIPPER_ADDR $BAD_SELECTOR ) ;;
*)
args+=( --args $FLIPPER_ADDR $SELECTOR ) ;;
esac

cargo contract call "${args[@]}"
1 change: 1 addition & 0 deletions crates/env/src/engine/on_chain/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ macro_rules! define_error_codes {
) => {
/// Every error that can be returned to a contract when it calls any of the host functions.
#[repr(u32)]
#[derive(::core::fmt::Debug)]
pub enum Error {
$(
$( #[$attr] )*
Expand Down
20 changes: 17 additions & 3 deletions crates/env/src/engine/on_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,23 @@ impl TypedEnvBackend for EnvInstance {
output,
);
match call_result {
Ok(()) | Err(ext::Error::CalleeReverted) => {
let decoded = scale::Decode::decode(&mut &output[..])?;
Ok(decoded)
Ok(()) => {
// let decoded = scale::Decode::decode(&mut &output[..])?;
// Ok(decoded)
if let Ok(decoded) = scale::Decode::decode(&mut &output[..]) {
Ok(decoded)
} else {
::core::panic!("failed to decode successful message output");
}
}
Err(ext::Error::CalleeReverted) => {
// let decoded = scale::Decode::decode(&mut &output[..])?;
// Ok(decoded)
if let Ok(decoded) = scale::Decode::decode(&mut &output[..]) {
Ok(decoded)
} else {
::core::panic!("failed to decode reverted message output");
}
ascjones marked this conversation as resolved.
Show resolved Hide resolved
}
Err(actual_error) => Err(actual_error.into()),
}
Expand Down
10 changes: 6 additions & 4 deletions crates/ink/codegen/src/generator/as_dependency/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,12 @@ impl CallBuilder<'_> {
let input_types = generator::input_types(message.inputs());
let arg_list = generator::generate_argument_list(input_types.iter().cloned());
let mut_tok = callable.receiver().is_ref_mut().then(|| quote! { mut });
let output = message.output();
let return_type =
output.map_or_else(|| quote! { () }, |output| quote! { #output });
let output_span = output.span();

let return_type = message
.wrapped_output()
.expect("TODO: Always returns Some atm");

let output_span = message.output().span();
HCastano marked this conversation as resolved.
Show resolved Hide resolved
let output_type = quote_spanned!(output_span=>
::ink::env::call::CallBuilder<
Environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,16 @@ impl ContractRef<'_> {
let mut_token = message.receiver().is_ref_mut().then(|| quote! { mut });
let input_bindings = message.inputs().map(|input| &input.pat).collect::<Vec<_>>();
let input_types = message.inputs().map(|input| &input.ty).collect::<Vec<_>>();
let output_type = message.output().map(|ty| quote! { -> #ty });
let output_type = message
.wrapped_output()
.expect("TODO: This always returns Some atm");
quote_spanned!(span=>
#( #attrs )*
#[inline]
pub fn #message_ident(
& #mut_token self
#( , #input_bindings : #input_types )*
) #output_type {
) -> #output_type {
<Self as ::ink::codegen::TraitCallBuilder>::#call_operator(self)
.#message_ident( #( #input_bindings ),* )
.fire()
Expand Down
64 changes: 42 additions & 22 deletions crates/ink/codegen/src/generator/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,11 @@ impl Dispatch<'_> {
let mutates = message.receiver().is_ref_mut();
let selector_id = message.composed_selector().into_be_u32().hex_padded_suffixed();
let selector_bytes = message.composed_selector().hex_lits();
let output_tuple_type = message
.output()
.map(quote::ToTokens::to_token_stream)
.unwrap_or_else(|| quote! { () });

let output_tuple_type = message.wrapped_output()
.map(|ty| quote::ToTokens::to_token_stream(&ty))
.expect("TODO: Always returns Some atm");

let input_bindings = generator::input_bindings(message.inputs());
let input_tuple_type = generator::input_types_tuple(message.inputs());
let input_tuple_bindings = generator::input_bindings_tuple(message.inputs());
Expand Down Expand Up @@ -435,16 +436,38 @@ impl Dispatch<'_> {
.unwrap_or_else(|error| ::core::panic!("{}", error))
}

::ink::env::decode_input::<
<#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type>()
.map_err(|_| ::ink::reflect::DispatchError::CouldNotReadInput)
.and_then(|decoder| {
<<#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type
as ::ink::reflect::ExecuteDispatchable>::execute_dispatchable(decoder)
})
.unwrap_or_else(|error| {
::core::panic!("dispatching ink! message failed: {}", error)
})
let dispatchable = match ::ink::env::decode_input::<
<#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type>() {
Ok(decoded_dispatchable) => {
::ink::env::debug_println!("Result from `decode_input` {:?}", &decoded_dispatchable);
decoded_dispatchable
},
Err(_decoding_error) => {
::ink::env::debug_println!("Result from `decode_input` {:?}", &_decoding_error);

// TODO: Here will pick out the `Dispatch` error we're interested in telling the
ascjones marked this conversation as resolved.
Show resolved Hide resolved
// user about and encode it correctly
let error = ::core::result::Result::Err(
::ink::LangError::CouldNotReadInput
);

// At this point we're unable to set the `Ok` variant to be the any "real"
// message output since we were unable to figure out what the caller wanted
// to dispatch in the first place, so we set it to `()`.
//
// This is okay since we're going to only be encoding the `Err` variant
// into the output buffer anyways.
::ink::env::return_value::<::core::result::Result<(), ::ink::LangError>>(
::ink::env::ReturnFlags::default().set_reverted(true), &error
);
}
};

<<#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type
as ::ink::reflect::ExecuteDispatchable>::execute_dispatchable(dispatchable)
ascjones marked this conversation as resolved.
Show resolved Hide resolved
.unwrap_or_else(|error| {
::core::panic!("dispatching ink! message failed: {}", error)
})
}
)
}
Expand Down Expand Up @@ -772,19 +795,18 @@ impl Dispatch<'_> {

push_contract(contract, #mutates_storage);

if ::core::any::TypeId::of::<#message_output>() != ::core::any::TypeId::of::<()>() {
// In case the return type is `()` we do not return a value.
::ink::env::return_value::<#message_output>(
::ink::env::ReturnFlags::default(), &result
)
}
::ink::env::return_value::<#message_output>(
::ink::env::ReturnFlags::default(), &result
)
ascjones marked this conversation as resolved.
Show resolved Hide resolved

}
)
});

quote_spanned!(span=>
const _: () = {
#[allow(non_camel_case_types)]
#[derive(::core::fmt::Debug)]
pub enum __ink_MessageDecoder {
#( #message_variants ),*
}
Expand Down Expand Up @@ -848,8 +870,6 @@ impl Dispatch<'_> {
match self {
#( #message_execute ),*
};

::core::result::Result::Ok(())
}
}

Expand Down
13 changes: 9 additions & 4 deletions crates/ink/codegen/src/generator/item_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,20 @@ impl ItemImpls<'_> {
let attrs = message.attrs();
let vis = message.visibility();
let receiver = message.receiver();
let mut_token = message.receiver().is_ref_mut().then(|| quote! { mut });
let ident = message.ident();
let inputs = message.inputs();
let output_arrow = message.output().map(|_| quote! { -> });
let output = message.output();
let output = message
.wrapped_output()
.map(|ty| quote::ToTokens::to_token_stream(&ty))
.expect("This should always be Some atm");
let statements = message.statements();
quote_spanned!(span =>
#( #attrs )*
#vis fn #ident(#receiver #( , #inputs )* ) #output_arrow #output {
#( #statements )*
#vis fn #ident(#receiver #( , #inputs )* ) -> #output {
let #mut_token message_body = || { #( #statements )* };
ascjones marked this conversation as resolved.
Show resolved Hide resolved
::core::result::Result::Ok(message_body())

}
)
}
Expand Down
4 changes: 3 additions & 1 deletion crates/ink/codegen/src/generator/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl Metadata<'_> {
fn without_display_name(ty: &syn::Type) -> TokenStream2 {
quote! { ::ink::metadata::TypeSpec::new::<#ty>() }
}

if let syn::Type::Path(type_path) = ty {
if type_path.qself.is_some() {
return without_display_name(ty)
Expand Down Expand Up @@ -219,7 +220,8 @@ impl Metadata<'_> {
let mutates = message.receiver().is_ref_mut();
let ident = message.ident();
let args = message.inputs().map(Self::generate_dispatch_argument);
let ret_ty = Self::generate_return_type(message.output());
let ret_ty =
Self::generate_return_type(message.wrapped_output().as_ref());
quote_spanned!(span =>
::ink::metadata::MessageSpec::from_label(::core::stringify!(#ident))
.selector([
Expand Down
19 changes: 19 additions & 0 deletions crates/ink/ir/src/ir/item_impl/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,25 @@ impl Message {
}
}

// TODO: Maybe get rid of `Option` here, only keeping for initial compatibility
ascjones marked this conversation as resolved.
Show resolved Hide resolved
pub fn wrapped_output(&self) -> Option<syn::Type> {
let return_type = match &self.item.sig.output {
syn::ReturnType::Default => None,
syn::ReturnType::Type(_, return_type) => Some(return_type),
}
.map(quote::ToTokens::to_token_stream)
.unwrap_or_else(|| quote::quote! { () });

let wrapped_return = quote::quote! {
::core::result::Result<#return_type, ::ink::LangError>
ascjones marked this conversation as resolved.
Show resolved Hide resolved
};

let wrapped_return = syn::parse2::<syn::Type>(wrapped_return)
.expect("TODO: Failed to parse into Type");
ascjones marked this conversation as resolved.
Show resolved Hide resolved

Some(wrapped_return)
}

/// Returns a local ID unique to the ink! message with respect to its implementation block.
///
/// # Note
Expand Down
1 change: 1 addition & 0 deletions crates/ink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ pub use ink_macro::{
test,
trait_definition,
};
pub use ink_primitives::LangError;
2 changes: 1 addition & 1 deletion crates/ink/src/reflect/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ pub trait ExecuteDispatchable {
}

/// An error that can occur during dispatch of ink! dispatchables.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, ::scale::Encode, ::scale::Decode)]
pub enum DispatchError {
ascjones marked this conversation as resolved.
Show resolved Hide resolved
/// Failed to decode into a valid dispatch selector.
InvalidSelector,
Expand Down
2 changes: 2 additions & 0 deletions crates/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub mod layout;
mod specs;
mod utils;

pub use ink_primitives::LangError;
ascjones marked this conversation as resolved.
Show resolved Hide resolved

pub use self::specs::{
ConstructorSpec,
ConstructorSpecBuilder,
Expand Down
4 changes: 4 additions & 0 deletions crates/metadata/src/specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct ContractSpec<F: Form = MetaForm> {
events: Vec<EventSpec<F>>,
/// The contract documentation.
docs: Vec<F::String>,
/// The language specific error type.
lang_error: F::Type,
}

impl IntoPortable for ContractSpec {
Expand All @@ -80,6 +82,7 @@ impl IntoPortable for ContractSpec {
.map(|event| event.into_portable(registry))
.collect::<Vec<_>>(),
docs: registry.map_into_portable(self.docs),
lang_error: registry.register_type(&self.lang_error),
}
}
}
Expand Down Expand Up @@ -211,6 +214,7 @@ impl ContractSpec {
messages: Vec::new(),
events: Vec::new(),
docs: Vec::new(),
lang_error: meta_type::<ink_primitives::LangError>(),
ascjones marked this conversation as resolved.
Show resolved Hide resolved
},
marker: PhantomData,
}
Expand Down
11 changes: 11 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ pub use self::{
Hash,
},
};

/// An error that comes from the smart contracting language, but not necessarily the smart contract
/// itself nor the underlying execution environment.
#[non_exhaustive]
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, ::scale::Encode, ::scale::Decode)]
#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))]
pub enum LangError {
/// Failed to read execution input for the dispatchable.
CouldNotReadInput = 1u32,
}
Comment on lines +54 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we missing UnknownSelector here? The one that green initially requested this feature for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda. I mentioned this in one of the TODO points:

Refactor dispatch logic to bubble up specific dispatch error (we can maybe do this
later, at the expense of always having an extra error variant in LangError)

So tl;dr, we can't easily pull out UnknownSelector atm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the expense of always having an extra error variant in LangError

Which extra error are you talking about specifically?

But in general that is fine. We that we can add new errors to LangError without breaking ABI as no one is allowed to exhaustively match on it.

Another thing: Didn't we agree to move this enum to the metadata crate so it is unified across all languages? Or is this TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which extra error are you talking about specifically?

We'd have LangError::CouldNotReadInput as a potential error that doesn't get used if we start exposing more specific errors.

Another thing: Didn't we agree to move this enum to the metadata crate so it is unified across all languages? Or is this TODO.

We re-export it in the metadata crate. See this conversation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ha, now I understand why this is tricky because UnknownSelector is raised in decode_dispatch and then just swallowed into a ::scale::Error`. So a bigger refactoring to access that error required.

impl ::scale::Decode for __ink_ConstructorDecoder {
            fn decode<I>(input: &mut I) -> ::core::result::Result<Self, ::scale::Error>
            where
                I: ::scale::Input,
            {
                <Self as ::ink::reflect::DecodeDispatch>::decode_dispatch(input)
                    .map_err(::core::convert::Into::into)
            }
        }

28 changes: 28 additions & 0 deletions deploy-contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -ex

F="${1:-pass}"

cargo contract build --manifest-path examples/flipper/Cargo.toml --skip-linting
ascjones marked this conversation as resolved.
Show resolved Hide resolved
cargo contract instantiate \
--manifest-path examples/flipper/Cargo.toml \
--suri //Alice --output-json \
--constructor default \
--salt $(date +%s) \
--skip-confirm > /tmp/deployment-output.json

FLIPPER_ADDRESS=$(tail -n +2 /tmp/deployment-output.json | jq --raw-output .contract)
echo $FLIPPER_ADDRESS

cargo contract build --manifest-path examples/cross_chain_test/Cargo.toml --skip-linting
cargo contract instantiate \
--manifest-path examples/cross_chain_test/Cargo.toml \
--suri //Alice --output-json \
--salt $(date +%s) \
--skip-confirm > /tmp/deployment-output.json

CROSS_ADDRESS=$(tail -n +2 /tmp/deployment-output.json | jq --raw-output .contract)
echo $CROSS_ADDRESS

./call-contract.sh $F $CROSS_ADDRESS $FLIPPER_ADDRESS
9 changes: 9 additions & 0 deletions examples/cross_chain_test/.gitignore
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
28 changes: 28 additions & 0 deletions examples/cross_chain_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "cross_chain_test"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2021"

[dependencies]
ink = { path = "../../crates/ink", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

[lib]
name = "cross_chain_test"
path = "lib.rs"
crate-type = [
# Used for normal contract Wasm blobs.
"cdylib",
]

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
]
ink-as-dependency = []
Loading