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::{
29 AbiEncodeWith,
30 ScaleEncoding,
31};
32
33/// The type returned from `ContractRef` constructors, partially initialized with the
34/// execution input arguments.
35pub type CreateBuilderPartial<E, ContractRef, Args, R> = CreateBuilder<
36 E,
37 ContractRef,
38 Set<LimitParamsV2>,
39 Set<ExecutionInput<Args, ScaleEncoding>>,
40 Set<ReturnType<R>>,
41>;
42
43/// Get the encoded constructor arguments from the partially initialized `CreateBuilder`
44pub fn constructor_exec_input<E, ContractRef, Args: AbiEncodeWith<ScaleEncoding>, R>(
45 builder: CreateBuilderPartial<E, ContractRef, Args, R>,
46) -> Vec<u8>
47where
48 E: Environment,
49{
50 // set all the other properties to default values, we only require the `exec_input`.
51 builder
52 .endowment(0u32.into())
53 .code_hash(H256::zero())
54 .salt_bytes(None)
55 .params()
56 .exec_input()
57 .encode()
58}