Lines
100 %
Functions
Branches
//! Account commands over the client-form natives.
use forms::{ACCOUNT_MERGE, FormValues, write_payload};
use nomiscript::Value;
use rpc::Session;
use crate::CommandError;
use crate::eval::{escape_str, plist_field};
use crate::forms::map_references;
use crate::transaction::{eval_text, submit_call};
/// Merge the `from` account of `values` into its `into` account; the id of
/// the account that remains.
///
/// # Errors
/// [`CommandError::Argument`] for an unknown or ambiguous pick, or the
/// server's refusal.
pub async fn merge(session: &mut Session, values: &FormValues) -> Result<String, CommandError> {
let mapped = map_references(session, &ACCOUNT_MERGE, values).await?;
eval_text(session, &submit_call(&ACCOUNT_MERGE, &mapped)).await
}
/// The `(merge-preview …)` call for the merge `values` describe.
#[must_use]
pub fn merge_preview_call(values: &FormValues) -> String {
format!(
"(merge-preview {})",
escape_str(&write_payload(&ACCOUNT_MERGE, values))
)
/// The count of splits a `merge-preview` reply says would move.
pub fn merge_preview_splits(preview: &Value) -> Option<u64> {
plist_field(preview, ":splits")?.parse().ok()
#[cfg(test)]
mod tests;