Skip to content

Commit 4c286c2

Browse files
kariyclaude
andcommitted
feat(contracts): add VRF contracts and support multiple scarb versions
- Update build.rs to use asdf for scarb version management, allowing different scarb versions per directory via .tool-versions files - Add VRF contracts compilation and artifact copying to build script - Add doc comments with full hex strings for HASH and CASM_HASH constants in the contract! macro - Add vrf module with CartridgeVrfProvider, CartridgeVrfConsumer, and CartridgeVrfAccount contracts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 38d29a2 commit 4c286c2

File tree

16 files changed

+81
-2376
lines changed

16 files changed

+81
-2376
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
path = crates/explorer/ui
1313
url = https://github.com/cartridge-gg/explorer
1414
branch = main
15-
[submodule "contracts/vrf"]
16-
path = contracts/vrf
17-
url = https://github.com/cartridge-gg/vrf
1815
[submodule "crates/cartridge/controller"]
1916
path = crates/cartridge/controller
2017
url = https://github.com/cartridge-gg/controller-rs.git
18+
[submodule "crates/contracts/contracts/vrf"]
19+
path = crates/contracts/contracts/vrf
20+
url = https://github.com/cartridge-gg/vrf.git

crates/contracts/build.rs

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ fn main() {
1717
let target_dir = contracts_dir.join("target/dev");
1818
let build_dir = Path::new("build");
1919

20-
// Check if scarb is available
21-
let scarb_available = Command::new("scarb")
22-
.arg("--version")
20+
// Check if asdf is available (used to manage scarb versions)
21+
let asdf_available = Command::new("asdf")
22+
.args(["exec", "scarb", "--version"])
2323
.output()
2424
.map(|output| output.status.success())
2525
.unwrap_or(false);
2626

27-
if !scarb_available {
28-
println!("cargo:warning=scarb not found in PATH, skipping contract compilation");
27+
if !asdf_available {
28+
println!("cargo:warning=asdf or scarb not found, skipping contract compilation");
2929
return;
3030
}
3131

@@ -34,11 +34,11 @@ fn main() {
3434
return;
3535
}
3636

37-
println!("cargo:warning=Building contracts with scarb...");
37+
println!("cargo:warning=Building main contracts with scarb...");
3838

39-
// Run scarb build in the contracts directory
40-
let output = Command::new("scarb")
41-
.arg("build")
39+
// Run scarb build in the contracts directory (uses asdf to pick correct scarb version)
40+
let output = Command::new("asdf")
41+
.args(["exec", "scarb", "build"])
4242
.current_dir(contracts_dir)
4343
.output()
4444
.expect("Failed to execute scarb build");
@@ -56,24 +56,39 @@ fn main() {
5656
.join("\n");
5757

5858
panic!(
59-
"Contract compilation build script failed. Below are the last 50 lines of `scarb \
60-
build` output:\n\n{last_n_lines}"
59+
"Main contracts compilation failed. Below are the last 50 lines of `scarb build` \
60+
output:\n\n{last_n_lines}"
6161
);
6262
}
6363

64+
// Build VRF contracts (uses different scarb version via asdf)
65+
let vrf_dir = contracts_dir.join("vrf");
66+
build_vrf_contracts(&vrf_dir);
67+
6468
// Create build directory if it doesn't exist
6569
if let Err(e) = fs::create_dir_all(build_dir) {
6670
panic!("Failed to create build directory: {e}");
6771
}
6872

69-
// Copy artifacts from target/dev to build directory
73+
// Copy main contract artifacts from target/dev to build directory
7074
if target_dir.exists() {
7175
if let Err(e) = copy_dir_contents(&target_dir, build_dir) {
72-
panic!("Failed to copy contract artifacts: {e}");
76+
panic!("Failed to copy main contract artifacts: {e}");
7377
}
74-
println!("cargo:warning=Contract artifacts copied to build directory");
78+
println!("cargo:warning=Main contract artifacts copied to build directory");
7579
} else {
76-
println!("cargo:warning=No contract artifacts found in target/dev");
80+
println!("cargo:warning=No main contract artifacts found in target/dev");
81+
}
82+
83+
// Copy VRF contract artifacts from vrf/target/dev to build directory
84+
let vrf_target_dir = vrf_dir.join("target/dev");
85+
if vrf_target_dir.exists() {
86+
if let Err(e) = copy_dir_contents(&vrf_target_dir, build_dir) {
87+
panic!("Failed to copy VRF contract artifacts: {e}");
88+
}
89+
println!("cargo:warning=VRF contract artifacts copied to build directory");
90+
} else {
91+
println!("cargo:warning=No VRF contract artifacts found in vrf/target/dev");
7792
}
7893
}
7994

@@ -89,3 +104,31 @@ fn copy_dir_contents(src: &Path, dst: &Path) -> std::io::Result<()> {
89104
}
90105
Ok(())
91106
}
107+
108+
fn build_vrf_contracts(vrf_dir: &Path) {
109+
println!("cargo:warning=Building VRF contracts with scarb...");
110+
111+
let output = Command::new("asdf")
112+
.args(["exec", "scarb", "build"])
113+
.current_dir(vrf_dir)
114+
.output()
115+
.expect("Failed to execute scarb build for VRF contracts");
116+
117+
if !output.status.success() {
118+
let logs = String::from_utf8_lossy(&output.stdout);
119+
let last_n_lines = logs
120+
.split('\n')
121+
.rev()
122+
.take(50)
123+
.collect::<Vec<&str>>()
124+
.into_iter()
125+
.rev()
126+
.collect::<Vec<&str>>()
127+
.join("\n");
128+
129+
panic!(
130+
"VRF contracts compilation failed. Below are the last 50 lines of `scarb build` \
131+
output:\n\n{last_n_lines}"
132+
);
133+
}
134+
}

crates/contracts/contracts/vrf

Submodule vrf added at 6d1c0f6

crates/contracts/contracts/vrf/.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

crates/contracts/contracts/vrf/.github/workflows/ci.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

crates/contracts/contracts/vrf/.github/workflows/publish.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

crates/contracts/contracts/vrf/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)