Skip to content

Commit

Permalink
add support for extensions, refactor into subcommands, and support da…
Browse files Browse the repository at this point in the history
…ta fees
  • Loading branch information
rachel-bousfield committed May 3, 2024
1 parent 12ba211 commit 07a5c95
Show file tree
Hide file tree
Showing 34 changed files with 541 additions and 320 deletions.
134 changes: 91 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["main", "replay", "util"]
members = ["cgen", "check", "example", "main", "replay", "util"]
resolver = "2"

[workspace.package]
Expand All @@ -11,12 +11,15 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/OffchainLabs/cargo-stylus"

[workspace.dependencies]
alloy-primitives = "0.4.0"
clap = { version = "4.4.5", features = [ "derive" ] }
alloy-primitives = "0.7.2"
alloy-json-abi = "0.7.2"
clap = { version = "4.5.4", features = [ "derive", "color" ] }
ethers = "2.0.10"
eyre = "0.6.8"
hex = "0.4.3"
rustc-host = "0.1.7"
serde_json = "1.0.103"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread" ] }

# replay tool
Expand Down
15 changes: 15 additions & 0 deletions cgen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "cargo-stylus-cgen"
authors.workspace = true
version.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
alloy-json-abi.workspace = true
clap.workspace = true
eyre.workspace = true
serde_json.workspace = true
tiny-keccak.workspace = true
19 changes: 10 additions & 9 deletions main/src/c/gen.rs → cgen/src/gen.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// Copyright 2023, Offchain Labs, Inc.
// Copyright 2023-2024, Offchain Labs, Inc.
// For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md

use alloy_json_abi::{Function, JsonAbi, StateMutability};
use eyre::bail;
use eyre::{bail, Result};
use serde_json::Value;
use std::fs;
use std::io::BufReader;
use std::{collections::HashMap, fmt::Write};
use std::{collections::HashMap, fmt::Write, fs, io::BufReader, path::Path};
use tiny_keccak::{Hasher, Keccak};

fn c_bytearray_initializer(val: &[u8]) -> String {
let inner: Vec<_> = val.iter().map(|byte| format!("0x{byte:02x}")).collect();
format!("{{{}}}", inner.join(", "))
}

pub fn c_gen(in_path: String, out_path: String) -> eyre::Result<()> {
let f = fs::File::open(&in_path)?;
pub fn c_gen(in_path: &Path, out_path: &Path) -> Result<()> {
let f = fs::File::open(in_path)?;

let input: Value = serde_json::from_reader(BufReader::new(f))?;

let Some(input_contracts) = input["contracts"].as_object() else {
bail!("did not find top-level contracts object in {}", in_path)
bail!(
"did not find top-level contracts object in {}",
in_path.to_string_lossy()
)
};

let mut pathbuf = std::path::PathBuf::new();
Expand Down Expand Up @@ -70,7 +71,7 @@ pub fn c_gen(in_path: String, out_path: String) -> eyre::Result<()> {
0 => simple_name.clone(),
x => format!("{simple_name}_{x}"),
};
let selector = u32::from_be_bytes(overload.selector());
let selector = u32::from_be_bytes(*overload.selector());

let (hdr_params, call_params, payable) = match overload.state_mutability {
StateMutability::Pure => {
Expand Down
Loading

0 comments on commit 07a5c95

Please sign in to comment.