Skip to content

Commit

Permalink
feat: add doc strings getter to FullABIFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e committed May 24, 2024
1 parent c80a52c commit 857534d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/abi/full_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};

use crate::{
error::{error, Result},
error::{error, Error, Result},
utils::TypePath,
};

Expand Down Expand Up @@ -121,6 +121,25 @@ impl FullABIFunction {
self.attributes.iter().any(|attr| attr.name == "payable")
}

pub fn doc_strings(&self) -> Result<Vec<String>> {
self.attributes
.iter()
.filter_map(|attr| {
if attr.name == "doc-comment" {
let doc = <[String; 1]>::try_from(attr.arguments.clone())
.map(|[doc]| doc)
.map_err(|_| {
Error("`doc-comment` attribute has more then one argument".to_string())
});

Some(doc)
} else {
None
}
})
.collect::<Result<Vec<String>>>()
}

pub fn from_counterpart(
abi_function: &ABIFunction,
types: &HashMap<usize, TypeDeclaration>,
Expand Down

0 comments on commit 857534d

Please sign in to comment.