use alloc::borrow::Cow;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use serde_with::skip_serializing_none;
use strum_macros::{AsRefStr, Display, EnumIter};
use crate::models::amount::XRPAmount;
use crate::models::transactions::{CommonFields, FlagCollection, Memo, Signer};
use crate::models::{
transactions::{Transaction, TransactionType},
Model,
};
#[derive(
Debug, Eq, PartialEq, Clone, Serialize_repr, Deserialize_repr, Display, AsRefStr, EnumIter,
)]
#[repr(u32)]
pub enum EnableAmendmentFlag {
TfGotMajority = 0x00010000,
TfLostMajority = 0x00020000,
}
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct EnableAmendment<'a> {
#[serde(flatten)]
pub common_fields: CommonFields<'a, EnableAmendmentFlag>,
pub amendment: Cow<'a, str>,
pub ledger_sequence: u32,
}
impl<'a> Model for EnableAmendment<'a> {}
impl<'a> Transaction<'a, EnableAmendmentFlag> for EnableAmendment<'a> {
fn has_flag(&self, flag: &EnableAmendmentFlag) -> bool {
self.common_fields.has_flag(flag)
}
fn get_transaction_type(&self) -> &TransactionType {
self.common_fields.get_transaction_type()
}
fn get_common_fields(&self) -> &CommonFields<'_, EnableAmendmentFlag> {
self.common_fields.get_common_fields()
}
fn get_mut_common_fields(&mut self) -> &mut CommonFields<'a, EnableAmendmentFlag> {
self.common_fields.get_mut_common_fields()
}
}
impl<'a> EnableAmendment<'a> {
pub fn new(
account: Cow<'a, str>,
account_txn_id: Option<Cow<'a, str>>,
fee: Option<XRPAmount<'a>>,
flags: Option<FlagCollection<EnableAmendmentFlag>>,
last_ledger_sequence: Option<u32>,
memos: Option<Vec<Memo>>,
sequence: Option<u32>,
signers: Option<Vec<Signer>>,
source_tag: Option<u32>,
ticket_sequence: Option<u32>,
amendment: Cow<'a, str>,
ledger_sequence: u32,
) -> Self {
Self {
common_fields: CommonFields::new(
account,
TransactionType::EnableAmendment,
account_txn_id,
fee,
Some(flags.unwrap_or_default()),
last_ledger_sequence,
memos,
None,
sequence,
signers,
None,
source_tag,
ticket_sequence,
None,
),
amendment,
ledger_sequence,
}
}
}