1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use anyhow::{anyhow, Error};
use ckb_tool::{ckb_jsonrpc_types::Script, ckb_types::H256};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::str::FromStr;
#[derive(PartialEq, Eq, Hash, Serialize, Deserialize, Clone, Copy)]
pub enum TemplateType {
Rust,
C,
CSharedLib,
}
impl FromStr for TemplateType {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let template_type = match s.to_lowercase().as_str() {
"rust" => TemplateType::Rust,
"c" => TemplateType::C,
"c-sharedlib" => TemplateType::CSharedLib,
_ => {
return Err(anyhow!("Unexpected template type '{}'", s));
}
};
Ok(template_type)
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Contract {
pub name: String,
pub template_type: TemplateType,
}
#[derive(Default, Clone, Serialize, Deserialize)]
pub struct RustConfig {
pub workspace_dir: Option<PathBuf>,
pub toolchain: Option<String>,
pub docker_image: Option<String>,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct Config {
#[serde(default)]
pub version: String,
#[serde(default)]
pub contracts: Vec<Contract>,
pub deployment: PathBuf,
#[serde(default)]
pub rust: RustConfig,
}
#[derive(Clone, Default, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct Deployment {
pub lock: Script,
pub cells: Vec<Cell>,
#[serde(default)]
pub dep_groups: Vec<DepGroup>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CellLocation {
OutPoint { tx_hash: H256, index: u32 },
File { file: String },
}
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct Cell {
pub name: String,
pub location: CellLocation,
pub enable_type_id: bool,
}
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
pub struct DepGroup {
pub name: String,
pub cells: Vec<String>,
}