Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion rhoast_functions/src/rholang/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use handlebars::Handlebars;
use serde_json::json;
use std::{error::Error, fs};
use std::{collections::BTreeMap, error::Error, fs};

pub fn parse_simple_deploy(text: &String) -> Result<String, Box<dyn Error>> {
let reg = Handlebars::new();
Expand All @@ -9,6 +9,24 @@ pub fn parse_simple_deploy(text: &String) -> Result<String, Box<dyn Error>> {
Ok(compiled)
}

fn parse_simple(rholang: &String, arg: &String, text: &String) -> Result<String, Box<dyn Error>> {
let reg = Handlebars::new();
let compiled = reg.render_template(&rholang, &json!({ arg: &text }))?;
Ok(compiled)
}

pub fn parse_multiple_args(
rholang: &String,
args: &BTreeMap<String, String>,
) -> Result<String, Box<dyn Error>> {
let mut rtc: String = rholang.to_string();
for a in args.keys() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the iter-map-collect property here

eg

a.iter().map(|(key, value)| {
//use key value here
}).collect::<String>();

let val = args.get(a).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return the error here instead?

rtc = parse_simple(&rtc, a, val).unwrap().to_string();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}
Ok(rtc.to_string())
}

pub fn get_rholang(path: &str) -> String {
let path = format!("src/rholang/{}", path);
fs::read_to_string(path).expect("Unable to read file")
Expand Down