Skip to content

Commit

Permalink
Update docs, small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
crypdoughdoteth committed Feb 26, 2024
1 parent fd47c36 commit 01f7a11
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [

[package]
name = "vyper-rs"
version = "1.0.0"
version = "2.0.0"
edition = "2021"
authors = ["Crypdoughdoteth"]
license = "MIT"
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mod test {
fn basic() {
let path = PathBuf::from("./multisig.vy");
let mut vyper_contract = Vyper::new(&path);
println!("\n{:#?}\n", vyper_contract.abi);
vyper_contract.compile().unwrap();
vyper_contract.gen_abi().unwrap();
}
Expand Down
73 changes: 34 additions & 39 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
//! The Macro module contains powerful macros used to enhance the developer experience. Some of
//! these macros are structural in the sense that they construct essential types. The
//! vyper!, vypers!, and venv! macros fall into this category. Furthermore, there are
//! macros such as compile! and abi! that make common tasks simple. Both compile! and abi! have
//! numerous match arms and some shared keywords.
//! The Macro module contains powerful macros used to enhance the developer experience.
/// The `vyper!` macro is used to construct the Vyper type without the boilerplate. If there is
/// more than one pair of literals passed into the macro, the macro will return a Vec<Vyper>.
/// more than one pair of literals passed into the macro, the macro will return a Vypers.
///
/// Input: any length sequence of paired string literals (one for the contract, one for the abi (or desired path)).
/// Input: any length sequence of expressions that evaluate to a Path.
///
/// ```rust
/// use vyper_rs::vyper::*;
/// use vyper_rs::*;
/// use std::path::PathBuf;
/// fn try_me() {
/// use std::path::{PathBuf, Path};
/// use vyper_rs::vyper_errors::VyperErrors;
/// fn try_me() -> Result<(), VyperErrors> {
/// let _: Vyper = vyper!("./multisig.vy");
/// let _: Vypers = vyper!("./multisig.vy", "./multisig.vy");
/// Ok(())
/// }
/// ```
#[macro_export]
Expand All @@ -26,19 +24,19 @@ macro_rules! vyper {
};
($($p1: expr),+) => {
{
let mut contracts: Vec<Vyper> = vec![];
let mut contracts: Vec<PathBuf> = vec![];
$(
let v = vyper!($p1);
let v = PathBuf::from($p1);
contracts.push(v);
)+
Vypers::from(contracts)
Vypers::new(contracts)
}
};
}

/// The `compile!` macro is used to compile one more more Vyper contracts.
///
/// Input: any length sequence of paired string literals (one for the contract, one for the abi (or desired path)).
/// Input: any length sequence of expressions that evaluate to a Path.
///
/// Keywords: venv.
///
Expand All @@ -48,12 +46,14 @@ macro_rules! vyper {
/// use vyper_rs::venv::*;
/// use vyper_rs::vyper::*;
/// use vyper_rs::*;
/// use std::path::PathBuf;
/// async fn try_me() {
/// use std::path::{Path, PathBuf};
/// use vyper_rs::vyper_errors::VyperErrors;
/// async fn try_me() -> Result<(), VyperErrors> {
/// let _: Vyper = compile!(venv "./multisig.vy");
/// let _: Vyper = compile!("./multisig.vy");
/// let _: Vypers = compile!(venv "./multisig.vy", "./multisig.vy");
/// let _: Vypers = compile!("./multisig.vy", "./multisig.vy");
/// Ok(())
/// }
/// ```
#[macro_export]
Expand Down Expand Up @@ -98,40 +98,34 @@ macro_rules! compile {
let v = PathBuf::from($p1);
paths.push(v);
)+
let mut contracts = Venv::default().init()?.ivyper_venv(None)?.vypers(contracts);
let mut contracts = Venv::default().init()?.ivyper_venv(None)?.vypers(paths);
contracts.compile_many().await?;
contracts
contracts
}
};
}

/// The `abi!` macro is used to compile one more more Vyper contracts and get or generate the ABI.
///
/// Input: any length sequence of paired string literals (one for the contract, one for the abi (or desired path)).
/// Input: any length sequence of expressions that evaluate to a Path.
///
/// Keywords: paris, venv, get.
///
/// paris - compile contract for the Paris version of the EVM.
///
/// venv - compile contract using an instance of the Vyper compiler inside a venv.
///
/// get - instead of generating the ABI as a file, return it as JSON.
///
/// These keywords can be combined with one another just like with `compile!`.
/// ```rust
/// use vyper_rs::venv::*;
/// use vyper_rs::vyper::*;
/// use vyper_rs::*;
/// use std::path::PathBuf;
/// use vyper_rs::vyper_errors::VyperErrors;
/// use std::path::{PathBuf, Path};
/// use serde_json::Value;
/// async fn try_me() {
/// let _: Vyper = abi!("./multisig.vy", "./abi.json");
/// let _: (Vyper, Value) = abi!(get "./multisig.vy", "./abi.json");
/// let _: (Vyper, Venv<Ready>) = abi!(venv "./multisig.vy", "./abi.json");
/// let _: (Vyper, Value, Venv<Ready>) = abi!(venv get "./multisig.vy", "./abi.json");
/// let _: (Vyper, Value, Venv<Ready>) = abi!(venv get paris "./multisig.vy", "./abi.json");
/// let _: Vypers = abi!("./multisig.vy", "./abi.json", "./multisig.vy", "./abi.json");
/// let _: (Vypers, Vec<Value>, Venv<Ready>) = abi!(venv get "./multisig.vy", "./abi.json", "./multisig.vy", "./abi.json");
/// async fn try_me() -> Result<(), VyperErrors> {
/// let _: Value = abi!("./multisig.vy");
/// let _: Value = abi!(venv "./multisig.vy");
/// let _: Vec<Value> = abi!("./multisig.vy", "./multisig.vy");
/// let _: Vec<Value> = abi!(venv "./multisig.vy", "./multisig.vy");
/// Ok(())
/// }
/// ```
#[macro_export]
Expand All @@ -148,7 +142,7 @@ macro_rules! abi {
(venv $p1: expr) => {
{
let mut c: Vyper = compile!(venv $p1);
c.get_abi()?
c.get_abi()?
}
};
// return many ABIs as json
Expand All @@ -160,7 +154,7 @@ macro_rules! abi {
paths.push(v);
)+
let cs: Vypers = Vypers::new(paths);
cs.get_abi_many().await?
cs.get_abi_many().await?
}
};
// venv version of many
Expand All @@ -183,9 +177,12 @@ macro_rules! abi {
///
/// use vyper_rs::venv::*;
/// use vyper_rs::*;
/// fn try_me() {
/// let _: Venv<Ready> = venv!();
/// use vyper_rs::vyper_errors::VyperErrors;
///
/// fn try_me() -> Result<(), VyperErrors> {
/// let _: Venv<Ready> = venv!();
/// let _: Venv<Ready> = venv!("0.3.10");
/// Ok(())
/// }
///
///```
Expand All @@ -196,8 +193,6 @@ macro_rules! venv {
}};
($ver: literal) => {{
let version: &str = $ver;
Venv::default()
.init()?
.ivyper_venv(Some(version))?
Venv::default().init()?.ivyper_venv(Some(version))?
}};
}
4 changes: 4 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub fn parse_blueprint(bytecode: &[u8]) -> Result<Blueprint, VyperErrors> {
}
}

/// Scans current directory, looks for /contracts or /src folder and searches them too if they
/// exist. Returns a Vec of PathBufs to any Vyper contract found.
pub async fn scan_workspace(root: PathBuf) -> Result<Vec<PathBuf>, Error> {
let cwd = root.clone();
let h1 = tokio::spawn(async move { get_contracts_in_dir(cwd) });
Expand All @@ -87,6 +89,8 @@ pub async fn scan_workspace(root: PathBuf) -> Result<Vec<PathBuf>, Error> {
Ok(res.into_iter().flatten().collect::<Vec<PathBuf>>())
}

/// Scans current directory, looks for any vyper contracts and returns a Vec of PathBufs to any
/// contracts found.
pub fn get_contracts_in_dir(dir: PathBuf) -> Result<Vec<PathBuf>, Error> {
let files = read_dir(dir)?;
let contracts = files.into_iter().try_fold(
Expand Down
11 changes: 6 additions & 5 deletions src/vyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a> Display for Vyper<'a> {
}

impl<'a> Vyper<'a> {
/// Constructor function that takes in the path to your vyper contract and the _desired path/{name}.json_ for your ABI
/// Constructor function that takes in the path to your vyper contract
pub fn new(path: &'a Path) -> Self {
let np = path.with_extension("json");
Self {
Expand Down Expand Up @@ -193,7 +193,7 @@ impl<'a> Vyper<'a> {
let compiler_output = Command::new(self.get_vyper())
.arg("-f")
.arg("abi")
.arg(&self.path_to_code)
.arg(self.path_to_code)
.output()?;

if compiler_output.status.success() {
Expand All @@ -217,7 +217,7 @@ impl<'a> Vyper<'a> {
let compiler_output = Command::new(self.get_vyper())
.arg("-f")
.arg("abi")
.arg(&self.path_to_code)
.arg(self.path_to_code)
.output()?;

if compiler_output.status.success() {
Expand Down Expand Up @@ -440,10 +440,11 @@ impl Vypers {
}

pub fn new(paths: Vec<PathBuf>) -> Self {
let np = paths.iter().map(|e| e.with_extension("json")).collect();
Self {
path_to_code: paths.clone(),
path_to_code: paths,
bytecode: None,
abi: paths.iter().map(|e| e.with_extension("json")).collect(),
abi: np,
venv: None,
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 01f7a11

Please sign in to comment.