-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.rs
38 lines (30 loc) · 1.15 KB
/
build.rs
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
use ethers::contract::Abigen;
use std::env;
use std::path::Path;
/// Path to Depositor contract's JSON ABI. If it is absent use `npm run install && npm run compile`
/// in `repository/contracts` to compile it.
const DEPOSITOR_ABI_ARTIFACTS_PATH: &str =
"contracts/artifacts/contracts/Depositor.sol/Depositor.json";
const DEPOSITOR_RUST_BINDINGS_PATH: &str = "src/depositor_contract.rs";
fn main() {
let cargo_manifest_path = env::var("CARGO_MANIFEST_DIR").unwrap();
compile_depositor_bindings(cargo_manifest_path)
}
fn compile_depositor_bindings(cargo_manifest_path: String) {
let depositor_bindings_path =
format!("{}/{}", cargo_manifest_path, DEPOSITOR_RUST_BINDINGS_PATH);
if Path::new(&depositor_bindings_path).exists() {
return;
}
let abi_src_path = format!("{}/{}", cargo_manifest_path, DEPOSITOR_ABI_ARTIFACTS_PATH);
// Check if JSON ABI file of the Depositor contract is exists.
if !Path::new(&abi_src_path).exists() {
return;
}
Abigen::new("Depositor", abi_src_path)
.unwrap()
.generate()
.unwrap()
.write_to_file(depositor_bindings_path)
.unwrap();
}