1
use crate::render::{WireValue, parse_wire};
2
use nomiscript::Value;
3

            
4
use super::escape_str;
5

            
6
/// Build the nomiscript form for `(convert-amount num/denom from-uuid to-uuid)`.
7
16
pub fn build_convert_amount_form(amount_num_denom: &str, from: &str, to: &str) -> String {
8
16
    format!(
9
        "(convert-amount {} {} {})",
10
16
        escape_str(amount_num_denom),
11
16
        escape_str(from),
12
16
        escape_str(to)
13
    )
14
16
}
15

            
16
/// Parse a wire reply and return the value formatted as a string.
17
///
18
/// Used to surface query results (e.g. `convert-amount`) on the status line
19
/// without exposing `nomiscript::Value` to calling crates.
20
13
pub fn parse_scalar_reply(wire: &str) -> Result<String, String> {
21
13
    let value = parse_wire(wire).map_err(|e| e.to_string())?;
22
    let WireValue::Value(v) = value;
23
    Ok(match v {
24
        Value::String(s) => s,
25
        other => nomiscript::format_value(&other),
26
    })
27
13
}