ink_e2e/builders.rs
1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::H256;
16use ink_env::{
17 call::{
18 utils::{
19 ReturnType,
20 Set,
21 },
22 CreateBuilder,
23 ExecutionInput,
24 LimitParamsV2,
25 },
26 Environment,
27};
28use ink_primitives::reflect::AbiEncodeWith;
29
30/// The type returned from `ContractRef` constructors, partially initialized with the
31/// execution input arguments.
32pub type CreateBuilderPartial<E, ContractRef, Args, R, Abi> = CreateBuilder<
33 E,
34 ContractRef,
35 Set<LimitParamsV2>,
36 Set<ExecutionInput<Args, Abi>>,
37 Set<ReturnType<R>>,
38>;
39
40/// Get the encoded constructor arguments from the partially initialized `CreateBuilder`
41pub fn constructor_exec_input<E, ContractRef, Args: AbiEncodeWith<Abi>, R, Abi>(
42 builder: CreateBuilderPartial<E, ContractRef, Args, R, Abi>,
43) -> Vec<u8>
44where
45 E: Environment,
46{
47 // set all the other properties to default values, we only require the `exec_input`.
48 builder
49 .endowment(0u32.into())
50 .code_hash(H256::zero())
51 .salt_bytes(None)
52 .params()
53 .exec_input()
54 .encode()
55}