lib.rs 1.89 KB
Newer Older
Hero Bird's avatar
Hero Bird committed
1
2
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
//
3
4
5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Hero Bird's avatar
Hero Bird committed
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
Hero Bird's avatar
Hero Bird committed
8
//
9
10
11
12
13
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Hero Bird's avatar
Hero Bird committed
14
15
16
17
18
19

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
extern crate alloc;

Andrew Jones's avatar
Andrew Jones committed
20
21
22
#[cfg(test)]
mod tests;

23
pub mod layout2;
Hero Bird's avatar
Hero Bird committed
24
mod specs;
25
mod utils;
Hero Bird's avatar
Hero Bird committed
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pub use self::specs::{
    ConstructorSpec,
    ConstructorSpecBuilder,
    ContractSpec,
    ContractSpecBuilder,
    DisplayName,
    EventParamSpec,
    EventParamSpecBuilder,
    EventSpec,
    EventSpecBuilder,
    MessageParamSpec,
    MessageParamSpecBuilder,
    MessageSpec,
    MessageSpecBuilder,
    ReturnTypeSpec,
    TypeSpec,
Hero Bird's avatar
Hero Bird committed
43
};
44
#[cfg(feature = "derive")]
Andrew Jones's avatar
Andrew Jones committed
45
use scale_info::{
Hero Bird's avatar
Hero Bird committed
46
47
48
49
    form::CompactForm,
    IntoCompact as _,
    Registry,
};
50
use serde::Serialize;
Hero Bird's avatar
Hero Bird committed
51

Hero Bird's avatar
Hero Bird committed
52
/// An entire ink! project for ABI file generation purposes.
Hero Bird's avatar
Hero Bird committed
53
54
55
56
#[derive(Debug, Serialize)]
pub struct InkProject {
    registry: Registry,
    #[serde(rename = "storage")]
57
    layout: layout2::Layout<CompactForm>,
Hero Bird's avatar
Hero Bird committed
58
59
60
61
62
    #[serde(rename = "contract")]
    spec: ContractSpec<CompactForm>,
}

impl InkProject {
Hero Bird's avatar
Hero Bird committed
63
    /// Creates a new ink! project.
Hero Bird's avatar
Hero Bird committed
64
65
    pub fn new<L, S>(layout: L, spec: S) -> Self
    where
66
        L: Into<layout2::Layout>,
Hero Bird's avatar
Hero Bird committed
67
68
69
70
71
72
73
74
75
76
        S: Into<ContractSpec>,
    {
        let mut registry = Registry::new();
        Self {
            layout: layout.into().into_compact(&mut registry),
            spec: spec.into().into_compact(&mut registry),
            registry,
        }
    }
}