Skip to content

Commit 5352d62

Browse files
authored
Merge branch 'main' into drew/slashing-updates
2 parents 94c83fc + 400985b commit 5352d62

File tree

7 files changed

+129
-156
lines changed

7 files changed

+129
-156
lines changed

.github/workflows/foundry.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Install Foundry
3232
uses: foundry-rs/foundry-toolchain@v1
3333
with:
34-
version: nightly
34+
version: v0.3.0
3535

3636
- name: Install Solidity Dependencies
3737
run: forge soldeer update -d
@@ -59,7 +59,7 @@ jobs:
5959
- name: Install Foundry
6060
uses: foundry-rs/foundry-toolchain@v1
6161
with:
62-
version: nightly
62+
version: v0.3.0
6363

6464
- name: Install Solidity Dependencies
6565
run: forge soldeer update -d

bytecode/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bytecode/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tnt-core-bytecode"
3-
version = "0.1.0"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "Bytecode exports for TNT Core Solidity contracts"
66
license = "MIT"

bytecode/build.rs

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,83 +23,86 @@ fn to_screaming_snake_case(name: &str) -> String {
2323

2424
fn main() {
2525
// Only run the build script if the build-script feature is enabled
26-
if env::var("CARGO_FEATURE_BUILD_SCRIPT").is_ok() {
27-
// Your existing build script logic here
28-
println!("cargo:rerun-if-changed=build.rs");
29-
println!("cargo:rerun-if-changed=../src");
30-
31-
// Run forge build
32-
let status = Command::new("forge")
33-
.arg("build")
34-
.current_dir("..")
35-
.status()
36-
.expect("Failed to build contracts");
37-
38-
if !status.success() {
39-
panic!("Failed to build contracts");
40-
}
26+
if env::var("CARGO_FEATURE_BUILD_SCRIPT").is_err() {
27+
return;
28+
}
29+
30+
// Your existing build script logic here
31+
println!("cargo:rerun-if-changed=build.rs");
32+
println!("cargo:rerun-if-changed=../src");
4133

42-
// List of contracts to generate bytecode for
43-
let contracts = vec!["MasterBlueprintServiceManager"];
34+
// Run forge build
35+
let status = Command::new("forge")
36+
.arg("build")
37+
.current_dir("..")
38+
.status()
39+
.expect("Failed to build contracts");
40+
41+
if !status.success() {
42+
panic!("Failed to build contracts");
43+
}
4444

45-
let mut rust_code = String::from(
46-
r#"//! TNT Core contract bytecode exports
47-
//!
45+
// List of contracts to generate bytecode for
46+
let contracts = vec!["MasterBlueprintServiceManager"];
47+
48+
let mut rust_code = String::from(
49+
r#"//! TNT Core contract bytecode exports
50+
//!
4851
//! This crate exports the bytecode of TNT Core contracts as constant byte vectors
4952
//! that can be easily imported and used in other Rust projects.
5053
5154
/// Module containing all contract bytecodes
55+
#[rustfmt::skip]
5256
pub mod bytecode {
5357
"#,
54-
);
55-
56-
for contract in contracts {
57-
let json_path = Path::new("..")
58-
.join("out")
59-
.join(format!("{}.sol", contract))
60-
.join(format!("{}.json", contract));
61-
62-
let json_str = fs::read_to_string(&json_path)
63-
.unwrap_or_else(|_| panic!("Failed to read {}", json_path.display()));
64-
65-
let json: serde_json::Value =
66-
serde_json::from_str(&json_str).expect("Failed to parse JSON");
67-
68-
let bytecode = json["bytecode"]
69-
.as_object()
70-
.and_then(|obj| obj.get("object"))
71-
.and_then(|obj| obj.as_str())
72-
.unwrap_or_else(|| json["bytecode"].as_str().expect("Failed to get bytecode"));
73-
74-
let bytecode = bytecode.strip_prefix("0x").unwrap_or(bytecode);
75-
let bytes: Vec<String> = bytecode
76-
.as_bytes()
77-
.chunks(2)
78-
.map(|chunk| {
79-
let hex = std::str::from_utf8(chunk).unwrap();
80-
format!("0x{}", hex)
81-
})
82-
.collect();
83-
84-
let const_name = to_screaming_snake_case(contract);
85-
86-
rust_code.push_str(&format!(
87-
r#" /// Bytecode for the {} contract
58+
);
59+
60+
for contract in contracts {
61+
let json_path = Path::new("..")
62+
.join("out")
63+
.join(format!("{}.sol", contract))
64+
.join(format!("{}.json", contract));
65+
66+
let json_str = fs::read_to_string(&json_path)
67+
.unwrap_or_else(|_| panic!("Failed to read {}", json_path.display()));
68+
69+
let json: serde_json::Value =
70+
serde_json::from_str(&json_str).expect("Failed to parse JSON");
71+
72+
let bytecode = json["bytecode"]
73+
.as_object()
74+
.and_then(|obj| obj.get("object"))
75+
.and_then(|obj| obj.as_str())
76+
.unwrap_or_else(|| json["bytecode"].as_str().expect("Failed to get bytecode"));
77+
78+
let bytecode = bytecode.strip_prefix("0x").unwrap_or(bytecode);
79+
let bytes: Vec<String> = bytecode
80+
.as_bytes()
81+
.chunks(2)
82+
.map(|chunk| {
83+
let hex = std::str::from_utf8(chunk).unwrap();
84+
format!("0x{}", hex)
85+
})
86+
.collect();
87+
88+
let const_name = to_screaming_snake_case(contract);
89+
90+
rust_code.push_str(&format!(
91+
r#" /// Bytecode for the {} contract
8892
pub const {}: &[u8] = &[{}];
8993
9094
"#,
91-
contract,
92-
const_name,
93-
bytes.join(", ")
94-
));
95-
}
95+
contract,
96+
const_name,
97+
bytes.join(", ")
98+
));
99+
}
96100

97-
rust_code.push_str(
98-
r#"}
101+
rust_code.push_str(
102+
r#"}
99103
"#,
100-
);
104+
);
101105

102-
// Write directly to lib.rs
103-
fs::write(Path::new("src").join("lib.rs"), rust_code).expect("Failed to write to lib.rs");
104-
}
106+
// Write directly to lib.rs
107+
fs::write(Path::new("src").join("lib.rs"), rust_code).expect("Failed to write to lib.rs");
105108
}

bytecode/src/lib.rs

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)