Skip to content

Commit

Permalink
rename result maps to versionmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
LimpidCrypto committed Dec 21, 2024
1 parent 001781d commit 7eb651e
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 50 deletions.
5 changes: 3 additions & 2 deletions src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::{
exceptions::XRPLHelperResult,
},
models::{
ledger::objects::account_root::AccountRoot, results::account_tx::AccountTxMap, XRPAmount,
ledger::objects::account_root::AccountRoot, results::account_tx::AccountTxVersionMap,
XRPAmount,
},
};

Expand Down Expand Up @@ -69,7 +70,7 @@ where
pub fn get_latest_transaction<'a: 'b, 'b, C>(
address: Cow<'a, str>,
client: &C,
) -> XRPLHelperResult<AccountTxMap<'b>>
) -> XRPLHelperResult<AccountTxVersionMap<'b>>
where
C: XRPLClient,
{
Expand Down
6 changes: 3 additions & 3 deletions src/asynch/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ where
)
.into();
let response = client.request(request).await?;
let account_info = results::account_info::AccountInfoMap::try_from(response)?;
let account_info = results::account_info::AccountInfoVersionMap::try_from(response)?;
let account_root = account_info.get_account_root().to_owned();

Ok(account_root)
Expand All @@ -84,7 +84,7 @@ where
pub async fn get_latest_transaction<'a: 'b, 'b, C>(
mut address: Cow<'a, str>,
client: &C,
) -> XRPLHelperResult<crate::models::results::account_tx::AccountTxMap<'b>>
) -> XRPLHelperResult<crate::models::results::account_tx::AccountTxVersionMap<'b>>
where
C: XRPLAsyncClient,
{
Expand All @@ -103,7 +103,7 @@ where
Some(1),
None,
);
let response: results::account_tx::AccountTxMap =
let response: results::account_tx::AccountTxVersionMap =
client.request(account_tx.into()).await?.try_into()?;

Ok(response)
Expand Down
18 changes: 9 additions & 9 deletions src/asynch/transaction/submit_and_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
},
models::{
requests::{self},
results::tx::{TxMap, TxMetaV1, TxV1},
results::tx::{TxMetaV1, TxV1, TxVersionMap},
transactions::Transaction,
Model,
},
Expand All @@ -32,7 +32,7 @@ pub async fn submit_and_wait<'a: 'b, 'b, T, F, C>(
wallet: Option<&Wallet>,
check_fee: Option<bool>,
autofill: Option<bool>,
) -> XRPLHelperResult<TxMap<'b>>
) -> XRPLHelperResult<TxVersionMap<'b>>
where
T: Transaction<'a, F> + Model + Clone + DeserializeOwned + Debug,
F: IntoEnumIterator + Serialize + Debug + PartialEq + Debug + Clone + 'a,
Expand All @@ -45,7 +45,7 @@ where
async fn send_reliable_submission<'a: 'b, 'b, T, F, C>(
transaction: &'b mut T,
client: &C,
) -> XRPLHelperResult<TxMap<'b>>
) -> XRPLHelperResult<TxVersionMap<'b>>
where
T: Transaction<'a, F> + Model + Clone + DeserializeOwned + Debug,
F: IntoEnumIterator + Serialize + Debug + PartialEq + Debug + Clone + 'a,
Expand Down Expand Up @@ -77,7 +77,7 @@ async fn wait_for_final_transaction_result<'a: 'b, 'b, C>(
tx_hash: Cow<'a, str>,
client: &C,
last_ledger_sequence: u32,
) -> XRPLHelperResult<TxMap<'b>>
) -> XRPLHelperResult<TxVersionMap<'b>>
where
C: XRPLAsyncClient,
{
Expand Down Expand Up @@ -112,16 +112,16 @@ where
.into());
}
} else {
let result: TxMap = response.try_into()?;
let result: TxVersionMap = response.try_into()?;
let base = match &result {
TxMap::Default(tx) => tx.base.clone(),
TxMap::V1(tx) => tx.base.clone(),
TxVersionMap::Default(tx) => tx.base.clone(),
TxVersionMap::V1(tx) => tx.base.clone(),
};
let validated = base.validated.unwrap_or(false);
if validated {
let meta = match result {
TxMap::Default(ref tx) => tx.meta.clone(),
TxMap::V1(TxV1 {
TxVersionMap::Default(ref tx) => tx.meta.clone(),
TxVersionMap::V1(TxV1 {
meta: Some(TxMetaV1::Json(ref meta)),
..
}) => Some(meta.clone()),
Expand Down
16 changes: 8 additions & 8 deletions src/models/results/account_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{exceptions::XRPLResultException, XRPLResponse, XRPLResult};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum AccountInfoMap<'a> {
pub enum AccountInfoVersionMap<'a> {
Default(AccountInfo<'a>),
V1(AccountInfoV1<'a>),
}
Expand Down Expand Up @@ -112,16 +112,16 @@ pub struct QueueDataTransaction<'a> {
pub seq: u32,
}

impl<'a> AccountInfoMap<'a> {
impl<'a> AccountInfoVersionMap<'a> {
pub fn get_account_root(&self) -> &AccountRoot<'a> {
match self {
AccountInfoMap::Default(account_info) => &account_info.base.account_data,
AccountInfoMap::V1(account_info) => &account_info.base.account_data,
AccountInfoVersionMap::Default(account_info) => &account_info.base.account_data,
AccountInfoVersionMap::V1(account_info) => &account_info.base.account_data,
}
}
}

impl<'a> TryFrom<XRPLResult<'a>> for AccountInfoMap<'a> {
impl<'a> TryFrom<XRPLResult<'a>> for AccountInfoVersionMap<'a> {
type Error = XRPLModelException;

fn try_from(result: XRPLResult<'a>) -> XRPLModelResult<Self> {
Expand All @@ -136,12 +136,12 @@ impl<'a> TryFrom<XRPLResult<'a>> for AccountInfoMap<'a> {
}
}

impl<'a> TryFrom<XRPLResponse<'a>> for AccountInfoMap<'a> {
impl<'a> TryFrom<XRPLResponse<'a>> for AccountInfoVersionMap<'a> {
type Error = XRPLModelException;

fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
match response.result {
Some(result) => AccountInfoMap::try_from(result),
Some(result) => AccountInfoVersionMap::try_from(result),
None => Err(XRPLModelException::MissingField("result".to_string())),
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ mod test_serde {

#[test]
fn test_deserialize_account_info<'a>() -> XRPLModelResult<()> {
let _: AccountInfoMap = serde_json::from_str(RESPONSE)?;
let _: AccountInfoVersionMap = serde_json::from_str(RESPONSE)?;

Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/models/results/account_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{XRPLResponse, XRPLResult};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum AccountTxMap<'a> {
pub enum AccountTxVersionMap<'a> {
Default(AccountTx<'a>),
V1(AccountTxV1<'a>),
}
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct AccountTxTransactionV1<'a> {
pub tx: Cow<'a, str>,
}

impl<'a> TryFrom<XRPLResult<'a>> for AccountTxMap<'a> {
impl<'a> TryFrom<XRPLResult<'a>> for AccountTxVersionMap<'a> {
type Error = XRPLModelException;

fn try_from(result: XRPLResult<'a>) -> XRPLModelResult<Self> {
Expand All @@ -109,12 +109,12 @@ impl<'a> TryFrom<XRPLResult<'a>> for AccountTxMap<'a> {
}
}

impl<'a> TryFrom<XRPLResponse<'a>> for AccountTxMap<'a> {
impl<'a> TryFrom<XRPLResponse<'a>> for AccountTxVersionMap<'a> {
type Error = XRPLModelException;

fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
match response.result {
Some(result) => AccountTxMap::try_from(result),
Some(result) => AccountTxVersionMap::try_from(result),
None => Err(XRPLModelException::MissingField("result".to_string())),
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ mod test_serde {

#[test]
fn test_deserialize_account_tx() -> XRPLModelResult<()> {
let _: AccountTxMap = serde_json::from_str(RESPONSE)?;
let _: AccountTxVersionMap = serde_json::from_str(RESPONSE)?;

Ok(())
}
Expand Down
30 changes: 15 additions & 15 deletions src/models/results/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ impl XRPLOtherResult {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum XRPLResult<'a> {
AccountInfo(account_info::AccountInfoMap<'a>),
AccountTx(account_tx::AccountTxMap<'a>),
AccountInfo(account_info::AccountInfoVersionMap<'a>),
AccountTx(account_tx::AccountTxVersionMap<'a>),
Fee(fee::Fee<'a>),
Ledger(ledger::Ledger<'a>),
NFTBuyOffer(nft_buy_offer::NFTBuyOffer<'a>),
Expand All @@ -97,43 +97,43 @@ pub enum XRPLResult<'a> {
NFTsByIssuer(nfts_by_issuer::NFTsByIssuer<'a>),
ServerState(Box<server_state::ServerState<'a>>), // Boxed because ServerState is large
Submit(submit::Submit<'a>),
Tx(tx::TxMap<'a>),
Tx(tx::TxVersionMap<'a>),
/// A fallback for any other result type
Other(XRPLOtherResult),
}

impl<'a> From<account_info::AccountInfo<'a>> for XRPLResult<'a> {
fn from(account_info: account_info::AccountInfo<'a>) -> Self {
XRPLResult::AccountInfo(account_info::AccountInfoMap::Default(account_info))
XRPLResult::AccountInfo(account_info::AccountInfoVersionMap::Default(account_info))
}
}

impl<'a> From<account_info::AccountInfoV1<'a>> for XRPLResult<'a> {
fn from(account_info: account_info::AccountInfoV1<'a>) -> Self {
XRPLResult::AccountInfo(account_info::AccountInfoMap::V1(account_info))
XRPLResult::AccountInfo(account_info::AccountInfoVersionMap::V1(account_info))
}
}

impl<'a> From<account_info::AccountInfoMap<'a>> for XRPLResult<'a> {
fn from(account_info: account_info::AccountInfoMap<'a>) -> Self {
impl<'a> From<account_info::AccountInfoVersionMap<'a>> for XRPLResult<'a> {
fn from(account_info: account_info::AccountInfoVersionMap<'a>) -> Self {
XRPLResult::AccountInfo(account_info)
}
}

impl<'a> From<account_tx::AccountTx<'a>> for XRPLResult<'a> {
fn from(account_tx: account_tx::AccountTx<'a>) -> Self {
XRPLResult::AccountTx(account_tx::AccountTxMap::Default(account_tx))
XRPLResult::AccountTx(account_tx::AccountTxVersionMap::Default(account_tx))
}
}

impl<'a> From<account_tx::AccountTxV1<'a>> for XRPLResult<'a> {
fn from(account_tx: account_tx::AccountTxV1<'a>) -> Self {
XRPLResult::AccountTx(account_tx::AccountTxMap::V1(account_tx))
XRPLResult::AccountTx(account_tx::AccountTxVersionMap::V1(account_tx))
}
}

impl<'a> From<account_tx::AccountTxMap<'a>> for XRPLResult<'a> {
fn from(account_tx: account_tx::AccountTxMap<'a>) -> Self {
impl<'a> From<account_tx::AccountTxVersionMap<'a>> for XRPLResult<'a> {
fn from(account_tx: account_tx::AccountTxVersionMap<'a>) -> Self {
XRPLResult::AccountTx(account_tx)
}
}
Expand Down Expand Up @@ -164,18 +164,18 @@ impl<'a> From<submit::Submit<'a>> for XRPLResult<'a> {

impl<'a> From<tx::Tx<'a>> for XRPLResult<'a> {
fn from(tx: tx::Tx<'a>) -> Self {
XRPLResult::Tx(tx::TxMap::Default(tx))
XRPLResult::Tx(tx::TxVersionMap::Default(tx))
}
}

impl<'a> From<tx::TxV1<'a>> for XRPLResult<'a> {
fn from(tx: tx::TxV1<'a>) -> Self {
XRPLResult::Tx(tx::TxMap::V1(tx))
XRPLResult::Tx(tx::TxVersionMap::V1(tx))
}
}

impl<'a> From<tx::TxMap<'a>> for XRPLResult<'a> {
fn from(tx: tx::TxMap<'a>) -> Self {
impl<'a> From<tx::TxVersionMap<'a>> for XRPLResult<'a> {
fn from(tx: tx::TxVersionMap<'a>) -> Self {
XRPLResult::Tx(tx)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/models/results/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{XRPLResponse, XRPLResult};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum TxMap<'a> {
pub enum TxVersionMap<'a> {
Default(Tx<'a>),
V1(TxV1<'a>),
}
Expand Down Expand Up @@ -68,7 +68,7 @@ pub enum TxMetaV1<'a> {
Blob(Cow<'a, str>),
}

impl<'a> TryFrom<XRPLResult<'a>> for TxMap<'a> {
impl<'a> TryFrom<XRPLResult<'a>> for TxVersionMap<'a> {
type Error = XRPLModelException;

fn try_from(result: XRPLResult<'a>) -> XRPLModelResult<Self> {
Expand All @@ -81,12 +81,12 @@ impl<'a> TryFrom<XRPLResult<'a>> for TxMap<'a> {
}
}

impl<'a> TryFrom<XRPLResponse<'a>> for TxMap<'a> {
impl<'a> TryFrom<XRPLResponse<'a>> for TxVersionMap<'a> {
type Error = XRPLModelException;

fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
match response.result {
Some(result) => TxMap::try_from(result),
Some(result) => TxVersionMap::try_from(result),
None => Err(XRPLModelException::MissingField("result".to_string())),
}
}
Expand All @@ -98,7 +98,7 @@ impl<'a> TryFrom<XRPLResponse<'a>> for Tx<'a> {
fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
match response.result {
Some(result) => match result {
XRPLResult::Tx(TxMap::Default(tx)) => Ok(tx),
XRPLResult::Tx(TxVersionMap::Default(tx)) => Ok(tx),
res => Err(XRPLResultException::UnexpectedResultType(
"Tx (v2)".to_string(),
res.get_name(),
Expand All @@ -116,7 +116,7 @@ impl<'a> TryFrom<XRPLResponse<'a>> for TxV1<'a> {
fn try_from(response: XRPLResponse<'a>) -> XRPLModelResult<Self> {
match response.result {
Some(result) => match result {
XRPLResult::Tx(TxMap::V1(tx)) => Ok(tx),
XRPLResult::Tx(TxVersionMap::V1(tx)) => Ok(tx),
res => Err(XRPLResultException::UnexpectedResultType(
"Tx (v1)".to_string(),
res.get_name(),
Expand Down
4 changes: 2 additions & 2 deletions src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
},
},
models::{
results::{submit::Submit, tx::TxMap},
results::{submit::Submit, tx::TxVersionMap},
transactions::Transaction,
Model, XRPAmount,
},
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn submit_and_wait<'a: 'b, 'b, T, F, C>(
wallet: Option<&Wallet>,
check_fee: Option<bool>,
autofill: Option<bool>,
) -> XRPLHelperResult<TxMap<'b>>
) -> XRPLHelperResult<TxVersionMap<'b>>
where
T: Transaction<'a, F> + Model + Clone + DeserializeOwned + Debug,
F: IntoEnumIterator + Serialize + Debug + PartialEq + Debug + Clone + 'a,
Expand Down

0 comments on commit 7eb651e

Please sign in to comment.