use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use crate::models::Model;
use super::{CommonFields, LedgerIndex, LookupByLedgerRequest, Marker, Request, RequestMethod};
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct NFTsByIssuer<'a> {
#[serde(flatten)]
pub common_fields: CommonFields<'a>,
#[serde(flatten)]
pub ledger_lookup: Option<LookupByLedgerRequest<'a>>,
pub issuer: Cow<'a, str>,
pub limit: Option<u32>,
pub marker: Option<Marker<'a>>,
pub nft_taxon: Option<u64>,
}
impl Model for NFTsByIssuer<'_> {}
impl<'a> Request<'a> for NFTsByIssuer<'a> {
fn get_common_fields(&self) -> &CommonFields<'a> {
&self.common_fields
}
fn get_common_fields_mut(&mut self) -> &mut CommonFields<'a> {
&mut self.common_fields
}
}
impl<'a> NFTsByIssuer<'a> {
pub fn new(
id: Option<Cow<'a, str>>,
issuer: Cow<'a, str>,
ledger_hash: Option<Cow<'a, str>>,
ledger_index: Option<LedgerIndex<'a>>,
limit: Option<u32>,
marker: Option<Marker<'a>>,
nft_taxon: Option<u64>,
) -> Self {
Self {
common_fields: CommonFields {
command: RequestMethod::NFTsByIssuer,
id,
},
ledger_lookup: Some(LookupByLedgerRequest {
ledger_hash,
ledger_index,
}),
issuer,
limit,
marker,
nft_taxon,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serde_round_trip() {
let req = NFTsByIssuer::new(
Some("nbi-1".into()),
"rIssuer11111111111111111111111111".into(),
None,
None,
Some(100),
Some(Marker::Int(1)),
Some(42),
);
let serialized = serde_json::to_string(&req).unwrap();
let deserialized: NFTsByIssuer = serde_json::from_str(&serialized).unwrap();
assert_eq!(req, deserialized);
assert!(serialized.contains("\"command\":\"nfts_by_issuer\""));
}
}