Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
8796a62
Handle `LangError` from instantiate (fails for success case)
HCastano Nov 19, 2022
95b80c4
Change generic in `CreateBuilder` to be more consistent
HCastano Nov 25, 2022
a49fcb7
Remove extra generic parameter
HCastano Nov 25, 2022
8312fa8
Remove generic return type parameter from `CreateBuidler` codegen
HCastano Nov 25, 2022
6e70be0
Hardcode assumption that `instantiate` returns a `ConstructorResult`
HCastano Nov 25, 2022
2fd4a82
Update `CreateBuilder` codegen to just return `Self`
HCastano Nov 25, 2022
4d1f2bf
Remove generic usage to fix formatting
HCastano Nov 28, 2022
f107cb1
Unwrap `ConstructorResult` in `contract-ref` E2E test
HCastano Nov 28, 2022
b6de9fc
Clean up some comments
HCastano Nov 28, 2022
5d221c3
Bring back the assumption that we expect an `AccountId`
HCastano Nov 28, 2022
7d94f75
Remove unused method
HCastano Nov 28, 2022
798f946
Update doc tests for new builder pattern
HCastano Nov 28, 2022
18d0922
Clean up some comments
HCastano Nov 28, 2022
06bba81
Fix Clippy warning
HCastano Nov 28, 2022
612537e
Fix typo
HCastano Nov 28, 2022
2175174
Add `try_instantiate` method to `CreateBuilder`
HCastano Nov 28, 2022
44a8324
Remove unneeded `unwrap`
HCastano Nov 29, 2022
84d257d
Remove debug logging
HCastano Nov 29, 2022
ffcca2c
Update doc test
HCastano Nov 29, 2022
91cd98f
Fix some typos
HCastano Nov 29, 2022
e701230
Mention panicking behaviour of `instantiate` methods
HCastano Nov 29, 2022
f2d85dd
Improve error messages from wrong `returns()` type
HCastano Nov 29, 2022
addcda2
Actually check return values from `call_instantiate`
HCastano Nov 29, 2022
4c99daf
Add test showing a reverting constructor with `Ok` in error buffer
HCastano Nov 29, 2022
99c859b
Check that we're only returning `LangError`s if the contract reverted
HCastano Nov 29, 2022
323ed2d
Clean up the manual encoding test a bit
HCastano Nov 30, 2022
b6fc625
Add test for constructors which return a contract level error
HCastano Dec 1, 2022
ac6b197
Add `CreateBuilder` message which calls a fallible constructor
HCastano Dec 3, 2022
b06a9f8
Add test which calls falliable constructor for success case
HCastano Dec 5, 2022
7d664a0
Get verbose `instantiate_contract_with_result` decoding past typechecker
HCastano Dec 5, 2022
f874c97
Add `try_instantiate_with_result` to `CreateBuilder`
HCastano Dec 5, 2022
c29895a
Clean up decoding logic for output from `seal_instatiate`
HCastano Dec 5, 2022
dbb079e
Small cleanups in `call-builder` E2E tests
HCastano Dec 5, 2022
6125690
RustFmt `env_access`
HCastano Dec 5, 2022
aa4f897
Remove unused import
HCastano Dec 5, 2022
053218f
Flip decoding logic so that it's more strict initially
HCastano Dec 6, 2022
77c790f
Add test which revert a fallible constructor
HCastano Dec 6, 2022
713ad1e
Remove note about removing `assert` statement
HCastano Dec 6, 2022
64a711c
Check return value from fallible constructor tests
HCastano Dec 6, 2022
54fcf90
Merge branch 'master' into hc-get-lang-error-from-create-builder
HCastano Dec 6, 2022
c17fc3b
Update E2E Builder typedef to match changes
HCastano Dec 6, 2022
32f4a75
Update E2E test for new call syntax
HCastano Dec 6, 2022
a3cfbb8
Use `selector_bytes!` macro in more places
HCastano Dec 6, 2022
283e182
Change order to accounts used in tests
HCastano Dec 6, 2022
cc98baf
Update function names to use `fallible`
HCastano Dec 6, 2022
f01b5ca
Add note about docs
HCastano Dec 6, 2022
c794ec9
Merge branch 'master' into hc-get-lang-error-from-create-builder
HCastano Dec 7, 2022
b4290cb
Update `ContractRef` codegen to use fallible constructor return types
HCastano Dec 7, 2022
d47bf8f
Stop returning an `AccountId` directly from `CreateBuilder::try_insta…
HCastano Dec 7, 2022
b720ede
Add panicking version of `try_instantiate_fallible`
HCastano Dec 7, 2022
75cad9e
Add test for using fallible constructors through ContractRefs
HCastano Dec 7, 2022
cf2516f
Add test for instantiation failure too
HCastano Dec 7, 2022
f9b3004
Add `instantiate_fallible` to `CreateParams`
HCastano Dec 7, 2022
d511b3f
Add a couple of missing docs
HCastano Dec 7, 2022
550b728
Convert `call-builder` test return type to `AccountId`
HCastano Dec 7, 2022
1668ae0
Extract reverted fallible constructor fn for testing
ascjones Dec 8, 2022
acf23b9
Fmt
ascjones Dec 8, 2022
e69e7ce
Add fallible_constructor_reverted_lang_error FAILs
ascjones Dec 8, 2022
f084763
Rename tests
ascjones Dec 8, 2022
74f2392
Add test for a decode error
ascjones Dec 8, 2022
e3a99f9
Rename some tests
ascjones Dec 8, 2022
56e8d52
Make `Result` types more explicit
HCastano Dec 8, 2022
50c227b
Add another test
HCastano Dec 8, 2022
8ce1d92
Clean up decoding match statement
HCastano Dec 8, 2022
c291b3c
Andrew was right
HCastano Dec 9, 2022
f0561e5
Small cleanups to naming and imports
HCastano Dec 11, 2022
1742a01
Couple more import and comment fixes
HCastano Dec 11, 2022
25d8326
Use decode trait method directly
HCastano Dec 11, 2022
24e9424
Fix `call-builder` E2E tests
HCastano Dec 11, 2022
e7bba67
Remove leading colons from non-codegen contexts
HCastano Dec 11, 2022
ebd42f3
Add doc test for `instantiate_fallible_contract`
HCastano Dec 11, 2022
0a99f16
Add doc test to `build_create` function
HCastano Dec 11, 2022
6cf60e6
Remove leftover trait bound
HCastano Dec 11, 2022
581291b
Remove a few more leading colons
HCastano Dec 11, 2022
95f9e6e
Panic in case where we get `Ok` encoded into error buffer
HCastano Dec 12, 2022
0d40825
Add some links to env docs
HCastano Dec 12, 2022
c8e5cfa
Add more docs to `call-builder` E2E tests
HCastano Dec 12, 2022
1e323f4
Use correct path in `call-builder` docs
HCastano Dec 12, 2022
0b31392
Merge branch 'master' into hc-get-lang-error-from-create-builder
ascjones Jan 18, 2023
9a14e21
Use return_value() method in e2e test
ascjones Jan 18, 2023
69946de
Merge branch 'master' into hc-get-lang-error-from-create-builder
HCastano Jan 20, 2023
37d8e80
Fix `call-builder` E2E test compilation
HCastano Jan 20, 2023
0c568b5
Fix `contract-ref` E2E test compilation
HCastano Jan 20, 2023
7d20051
Fix some of the comment links
HCastano Jan 21, 2023
eeb7b85
Unwrap errors from default `instantiate_fallible` codepath
HCastano Jan 21, 2023
658fed1
Fix `contract-ref` E2E test
HCastano Jan 21, 2023
aac62db
Wrap long line
HCastano Jan 21, 2023
619cc71
Remove TODO
HCastano Jan 21, 2023
dd41485
Fix instatiation doc test
HCastano Jan 21, 2023
b41ca87
Merge branch 'master' into hc-get-lang-error-from-create-builder
HCastano Jan 21, 2023
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
Remove leading colons from non-codegen contexts
  • Loading branch information
HCastano committed Dec 11, 2022
commit e7bba67fd8ba92a3923095556bc2bbcbef297992
6 changes: 2 additions & 4 deletions crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ where
/// - If the returned account ID failed to decode properly.
pub fn instantiate_contract<E, Args, Salt, R>(
params: &CreateParams<E, Args, Salt, R>,
) -> Result<::ink_primitives::ConstructorResult<E::AccountId>>
) -> Result<ink_primitives::ConstructorResult<E::AccountId>>
where
E: Environment,
Args: scale::Encode,
Expand Down Expand Up @@ -351,9 +351,7 @@ where
pub fn instantiate_fallible_contract<E, Args, Salt, R, ContractError>(
params: &CreateParams<E, Args, Salt, R>,
) -> Result<
::ink_primitives::ConstructorResult<
::core::result::Result<E::AccountId, ContractError>,
>,
ink_primitives::ConstructorResult<core::result::Result<E::AccountId, ContractError>>,
>
where
E: Environment,
Expand Down
6 changes: 3 additions & 3 deletions crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub trait TypedEnvBackend: EnvBackend {
fn instantiate_contract<E, Args, Salt, R>(
&mut self,
params: &CreateParams<E, Args, Salt, R>,
) -> Result<::ink_primitives::ConstructorResult<E::AccountId>>
) -> Result<ink_primitives::ConstructorResult<E::AccountId>>
where
E: Environment,
Args: scale::Encode,
Expand All @@ -458,8 +458,8 @@ pub trait TypedEnvBackend: EnvBackend {
&mut self,
params: &CreateParams<E, Args, Salt, R>,
) -> Result<
::ink_primitives::ConstructorResult<
::core::result::Result<E::AccountId, ContractError>,
ink_primitives::ConstructorResult<
core::result::Result<E::AccountId, ContractError>,
>,
>
where
Expand Down
20 changes: 7 additions & 13 deletions crates/env/src/call/create_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
#[inline]
pub fn try_instantiate(
&self,
) -> Result<::ink_primitives::ConstructorResult<R>, crate::Error> {
) -> Result<ink_primitives::ConstructorResult<R>, crate::Error> {
crate::instantiate_contract(self)
.map(|inner| inner.map(FromAccountId::from_account_id))
}
Expand Down Expand Up @@ -183,7 +183,7 @@ where
#[inline]
pub fn try_instantiate_fallible(
&self,
) -> Result<::ink_primitives::ConstructorResult<Result<R, ContractError>>, crate::Error>
) -> Result<ink_primitives::ConstructorResult<Result<R, ContractError>>, crate::Error>
{
crate::instantiate_fallible_contract(self).map(|constructor_result| {
constructor_result.map(|contract_result| {
Expand Down Expand Up @@ -511,7 +511,7 @@ where
#[inline]
pub fn try_instantiate(
self,
) -> Result<::ink_primitives::ConstructorResult<RetType>, Error> {
) -> Result<ink_primitives::ConstructorResult<RetType>, Error> {
self.params().try_instantiate()
}
}
Expand All @@ -524,7 +524,7 @@ impl<E, GasLimit, Args, Salt, RetType, ContractError>
Set<E::Balance>,
Set<ExecutionInput<Args>>,
Set<Salt>,
Set<ReturnType<::core::result::Result<RetType, ContractError>>>,
Set<ReturnType<Result<RetType, ContractError>>>,
>
where
E: Environment,
Expand All @@ -541,9 +541,7 @@ where
/// This method panics if it encounters an [`ink_primitives::LangError`]. If you want to handle
/// those use the [`try_instantiate_fallible`][`CreateParams::try_instantiate_fallible`] method instead.
#[inline]
pub fn instantiate_fallible(
self,
) -> Result<::core::result::Result<RetType, ContractError>, Error> {
pub fn instantiate_fallible(self) -> Result<Result<RetType, ContractError>, Error> {
self.params().instantiate_fallible()
}

Expand All @@ -555,12 +553,8 @@ where
#[inline]
pub fn try_instantiate_fallible(
Copy link
Contributor Author

@HCastano HCastano Dec 6, 2022

Choose a reason for hiding this comment

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

Ideally we don't have this as part of the CreateBuilder, and instead we allow the implementation to dispatch the correct method based off the concrete types used (so whatever is set with returns::<T>().

This is tricky because we eventually do need to know the types involved in order to decode them from the seal_instantiate output buffer correctly.

I haven't been able to figure out a way to do this yet, @ascjones you got any ideas?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I might have an idea for how to handle this, currently verifying whether it will work or not

Copy link
Collaborator

Choose a reason for hiding this comment

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

WIP here: #1591

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok the PR for my idea basically works now: #1591. So please have a look and let me know what you think.

self,
) -> Result<
::ink_primitives::ConstructorResult<
::core::result::Result<RetType, ContractError>,
>,
Error,
> {
) -> Result<ink_primitives::ConstructorResult<Result<RetType, ContractError>>, Error>
{
self.params().try_instantiate_fallible()
}
}
4 changes: 2 additions & 2 deletions crates/env/src/engine/off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ impl TypedEnvBackend for EnvInstance {
&mut self,
params: &CreateParams<E, Args, Salt, R>,
) -> Result<
::ink_primitives::ConstructorResult<
::core::result::Result<E::AccountId, ContractError>,
ink_primitives::ConstructorResult<
core::result::Result<E::AccountId, ContractError>,
>,
>
where
Expand Down
6 changes: 3 additions & 3 deletions crates/env/src/engine/on_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl TypedEnvBackend for EnvInstance {
fn instantiate_contract<E, Args, Salt, R>(
&mut self,
params: &CreateParams<E, Args, Salt, R>,
) -> Result<::ink_primitives::ConstructorResult<E::AccountId>>
) -> Result<ink_primitives::ConstructorResult<E::AccountId>>
where
E: Environment,
Args: scale::Encode,
Expand Down Expand Up @@ -533,8 +533,8 @@ impl TypedEnvBackend for EnvInstance {
&mut self,
params: &CreateParams<E, Args, Salt, R>,
) -> Result<
::ink_primitives::ConstructorResult<
::core::result::Result<E::AccountId, ContractError>,
ink_primitives::ConstructorResult<
core::result::Result<E::AccountId, ContractError>,
>,
>
where
Expand Down
8 changes: 4 additions & 4 deletions examples/lang-err-integration-tests/call-builder/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ mod call_builder {
&mut self,
address: AccountId,
selector: [u8; 4],
) -> Option<::ink::LangError> {
) -> Option<ink::LangError> {
use ink::env::call::build_call;

let result = build_call::<DefaultEnvironment>()
.call_type(Call::new().callee(address))
.exec_input(ExecutionInput::new(Selector::new(selector)))
.returns::<Result<(), ::ink::LangError>>()
.returns::<Result<(), ink::LangError>>()
.fire()
.expect("Error from the Contracts pallet.");

Expand All @@ -62,7 +62,7 @@ mod call_builder {
code_hash: Hash,
selector: [u8; 4],
init_value: bool,
) -> Option<::ink::LangError> {
) -> Option<ink::LangError> {
use ink::env::call::build_create;

let result = build_create::<DefaultEnvironment>()
Expand Down Expand Up @@ -183,7 +183,7 @@ mod call_builder {

assert!(matches!(
flipper_result,
Some(::ink::LangError::CouldNotReadInput)
Some(ink::LangError::CouldNotReadInput)
));

let flipper_get = build_message::<FlipperRef>(flipper_acc_id)
Expand Down