diff --git a/Cargo.lock b/Cargo.lock index b1177ab..0c7ed38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3348,7 +3348,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vyper-rs" -version = "1.0.0" +version = "2.0.0" dependencies = [ "hex", "serde", diff --git a/Cargo.toml b/Cargo.toml index 1bdf9da..db7fe65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ [package] name = "vyper-rs" -version = "1.0.0" +version = "2.0.0" edition = "2021" authors = ["Crypdoughdoteth"] license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 9c599e4..6bece02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(); } diff --git a/src/macros.rs b/src/macros.rs index 5f4f7f5..f043675 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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. +/// 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] @@ -26,19 +24,19 @@ macro_rules! vyper { }; ($($p1: expr),+) => { { - let mut contracts: Vec = vec![]; + let mut contracts: Vec = 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. /// @@ -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] @@ -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) = abi!(venv "./multisig.vy", "./abi.json"); -/// let _: (Vyper, Value, Venv) = abi!(venv get "./multisig.vy", "./abi.json"); -/// let _: (Vyper, Value, Venv) = abi!(venv get paris "./multisig.vy", "./abi.json"); -/// let _: Vypers = abi!("./multisig.vy", "./abi.json", "./multisig.vy", "./abi.json"); -/// let _: (Vypers, Vec, Venv) = 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 = abi!("./multisig.vy", "./multisig.vy"); +/// let _: Vec = abi!(venv "./multisig.vy", "./multisig.vy"); +/// Ok(()) /// } /// ``` #[macro_export] @@ -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 @@ -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 @@ -183,9 +177,12 @@ macro_rules! abi { /// /// use vyper_rs::venv::*; /// use vyper_rs::*; -/// fn try_me() { -/// let _: Venv = venv!(); +/// use vyper_rs::vyper_errors::VyperErrors; +/// +/// fn try_me() -> Result<(), VyperErrors> { +/// let _: Venv = venv!(); /// let _: Venv = venv!("0.3.10"); +/// Ok(()) /// } /// ///``` @@ -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))? }}; } diff --git a/src/utils.rs b/src/utils.rs index 135a9dc..83e1212 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -69,6 +69,8 @@ pub fn parse_blueprint(bytecode: &[u8]) -> Result { } } +/// 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, Error> { let cwd = root.clone(); let h1 = tokio::spawn(async move { get_contracts_in_dir(cwd) }); @@ -87,6 +89,8 @@ pub async fn scan_workspace(root: PathBuf) -> Result, Error> { Ok(res.into_iter().flatten().collect::>()) } +/// 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, Error> { let files = read_dir(dir)?; let contracts = files.into_iter().try_fold( diff --git a/src/vyper.rs b/src/vyper.rs index cec70d7..0f8bc2e 100644 --- a/src/vyper.rs +++ b/src/vyper.rs @@ -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 { @@ -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() { @@ -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() { @@ -440,10 +440,11 @@ impl Vypers { } pub fn new(paths: Vec) -> 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, } } diff --git a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%Cargo.toml b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%Cargo.toml index 1a37ae9..389750f 100644 Binary files a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%Cargo.toml and b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%Cargo.toml differ diff --git a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%compile.rs b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%compile.rs index 762293c..45ab620 100644 Binary files a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%compile.rs and b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%compile.rs differ diff --git a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%deploy.rs b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%deploy.rs index 4a276da..f09c73c 100644 Binary files a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%deploy.rs and b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%deploy.rs differ diff --git a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%venv.rs b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%venv.rs index a191360..e695afc 100644 Binary files a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%venv.rs and b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%examples%contracts%src%venv.rs differ diff --git a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%macros.rs b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%macros.rs index 51e4110..57db621 100644 Binary files a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%macros.rs and b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%macros.rs differ diff --git a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper.rs b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper.rs index cfe55f7..fc24d6b 100644 Binary files a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper.rs and b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper.rs differ diff --git a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper_errors.rs b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper_errors.rs index a3072e9..b756190 100644 Binary files a/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper_errors.rs and b/~/.config/nvim-data/undodir/%Users%crypdoughdoteth%dev%active%vyper-rs%src%vyper_errors.rs differ