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
84
85
86
87
88
89
90
91
92
93
94
95
use crate::bytecode::Bytecode;
use crate::errors::ArtifactError;
use ethabi::Contract as Abi;
use serde::Deserialize;
use std::collections::HashMap;
use std::fs::File;
use std::path::Path;
use web3::types::Address;
#[derive(Clone, Debug, Deserialize)]
pub struct Artifact {
#[serde(rename = "contractName")]
pub contract_name: String,
pub abi: Abi,
pub bytecode: Bytecode,
pub networks: HashMap<String, Network>,
pub devdoc: Documentation,
pub userdoc: Documentation,
}
impl Artifact {
pub fn empty() -> Self {
Artifact {
contract_name: String::new(),
abi: Abi {
constructor: None,
functions: HashMap::new(),
events: HashMap::new(),
fallback: false,
},
bytecode: Default::default(),
networks: HashMap::new(),
devdoc: Default::default(),
userdoc: Default::default(),
}
}
pub fn from_json<S>(json: S) -> Result<Self, ArtifactError>
where
S: AsRef<str>,
{
let artifact = serde_json::from_str(json.as_ref())?;
Ok(artifact)
}
pub fn load<P>(path: P) -> Result<Self, ArtifactError>
where
P: AsRef<Path>,
{
let json = File::open(path)?;
let artifact = serde_json::from_reader(json)?;
Ok(artifact)
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct Network {
pub address: Address,
}
#[derive(Clone, Debug, Default, Deserialize)]
pub struct Documentation {
pub details: Option<String>,
pub methods: HashMap<String, DocEntry>,
}
#[derive(Clone, Debug, Default, Deserialize)]
pub struct DocEntry {
pub details: Option<String>,
}
#[cfg(test)]
mod tests {
#[test]
fn parse() {}
}