Unify fallible and non fallible instantiate methods#1591
Conversation
crates/env/src/api.rs
Outdated
| Salt: AsRef<[u8]>, | ||
| ContractError: scale::Decode, | ||
| R: InstantiateResult<R>, | ||
| ContractRef: FromAccountId<E>, |
There was a problem hiding this comment.
Why not use the E::AccountId type directly?
There was a problem hiding this comment.
I did start with that, but would have had to implement some map capability that does id e.g. AccountId -> AccountId and AccountId -> Result<(), AccountId> and it was slightly tricky. Maybe possible but thought it was easier just to call FromAccountId in place to get the thing working.
crates/env/src/engine/mod.rs
Outdated
| let contract_err = <<R as InstantiateResult<ContractStorage>>::Error | ||
| as scale::Decode>::decode(out_return_value)?; | ||
| let err = <R as InstantiateResult<ContractStorage>>::err(contract_err); | ||
| Ok(Ok(err)) |
There was a problem hiding this comment.
nit: I'd use the typedefs here to make it more clear as to which Result is which
| Ok(Ok(err)) | |
| EnvResult::Ok(ConstructorResult::Ok(err)) |
crates/env/src/engine/mod.rs
Outdated
| 1 => { | ||
| let contract_err = <<R as InstantiateResult<ContractStorage>>::Error | ||
| as scale::Decode>::decode(out_return_value)?; | ||
| let err = <R as InstantiateResult<ContractStorage>>::err(contract_err); |
There was a problem hiding this comment.
| let err = <R as InstantiateResult<ContractStorage>>::err(contract_err); | |
| let contract_err = <R as InstantiateResult<ContractStorage>>::err(contract_err); |
Codecov Report
@@ Coverage Diff @@
## hc-get-lang-error-from-create-builder #1591 +/- ##
=========================================================================
- Coverage 65.86% 65.45% -0.41%
=========================================================================
Files 205 205
Lines 6330 6285 -45
=========================================================================
- Hits 4169 4114 -55
- Misses 2161 2171 +10
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
ccf61eb to
a7a2f7a
Compare
| /// | ||
| /// fn main() {} | ||
| /// ``` | ||
| pub trait ContractEnv { |
There was a problem hiding this comment.
These traits have just been copied from ink::reflect so we can use them here in ink_env
HCastano
left a comment
There was a problem hiding this comment.
There's still a couple things I want to review, but in general it's looking good 👍
| } | ||
|
|
||
| /// A constructor which reverts and fills the output buffer with an erronenously encoded | ||
| /// A constructor which reverts and fills the output buffer with an erroneously encoded |
There was a problem hiding this comment.
Lol, awkward that this was spelt erroneously 😅
| /// | ||
| /// fn main() {} | ||
| /// ``` | ||
| pub trait ContractEnv { |
There was a problem hiding this comment.
Not related to this PR, but I don't really understand why we don't use the Environment trait directly. E.g why not have T: Environment instead of going through this extra wrapper?
Fixes some inconsistent errors between Clippy and `rustc`
4dd4a3f to
a9c0223
Compare
HCastano
left a comment
There was a problem hiding this comment.
Thanks for cleaning up the API, looks much better now!
![]()
Context: #1512 (comment)
Since #1512
CreateBuilderhas 4 differentinstantiatemethods:instantiateinstantiate_fallibletry_instantiatetry_instantiate_faillbleThe use case for this is when we have a "fallible" constructor which returns a
Resulte.g.In order to invoke this from another contract, the following is required:
Some issues with this approach:
instantiateto call based on the return type of the constructor. Granted it should not compile with the wrong one, but still will cause some friction.instantiatemethod.This PR unifies the
instantaiteandinstantiate_fallibleversions of each method call, such that the user only needs to callinstantiateorinstantiate_fallible, and theCreateBuildermethod will return eitherResult<ContranctRef>or plainContractRef, depending on the actual return type of the constructor.See this UI test for the variations of constructor return types.