use crate::utils::json::Json;
use crate::utils::sign::goldilocks::Fp;
use crate::utils::sign::tx::{Tx, TxType};
#[cfg(feature = "sign")]
use crate::{
account::keys::ApiKey,
client::{Client, Http, SendError, Sent},
utils::sign::{BadTx, SignTxError},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct CreateSubAccount;
impl Tx for CreateSubAccount {
fn tx_type(&self) -> TxType {
TxType::CreateSubAccount
}
fn hash_fields(&self) -> Vec<Fp> {
Vec::new()
}
fn info_fields(&self) -> Vec<(&'static str, Json)> {
Vec::new()
}
}
#[cfg(feature = "sign")]
pub async fn create_sub_account<H: Http>(client: &Client<H, ApiKey>) -> Result<Sent, SendError> {
if !client.key().account().is_master() {
let why = format!("account {} is not a master: only a master opens sub-accounts", client.key().account());
return Err(SendError::Sign(SignTxError::Bad(BadTx::new("AccountIndex", why))));
}
client.send(&CreateSubAccount).await
}
#[cfg(test)]
#[cfg(feature = "sign")]
#[path = "tests/subaccounts.rs"]
mod tests;