Skip to content

Commit

Permalink
Merge pull request #72 from sephynox/revise-models
Browse files Browse the repository at this point in the history
Revise models
  • Loading branch information
LimpidCrypto authored Sep 18, 2023
2 parents d7fb5e6 + ea44169 commit 095f5c4
Show file tree
Hide file tree
Showing 72 changed files with 1,184 additions and 1,071 deletions.
16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ serde_json = { version = "1.0.68", default-features = false, features = [
serde_with = "3.2.0"
serde_repr = "0.1"
zeroize = "1.5.7"
hashbrown = { version = "0.14.0", default-features = false, features = ["serde"] }
hashbrown = { version = "0.14.0", default-features = false, features = [
"serde",
] }
fnv = { version = "1.0.7", default-features = false }
derive-new = { version = "0.5.9", default-features = false }
thiserror-no-std = "2.0.2"
anyhow = { version ="1.0.69", default-features = false }
anyhow = { version = "1.0.69", default-features = false }
tokio = { version = "1.28.0", default-features = false, optional = true }
url = { version = "2.2.2", default-features = false, optional = true }
futures = { version = "0.3.28", default-features = false, optional = true }
Expand Down Expand Up @@ -86,7 +88,15 @@ name = "benchmarks"
harness = false

[features]
default = ["std", "core", "models", "utils", "net", "tungstenite", "embedded-websocket"]
default = [
"std",
"core",
"models",
"utils",
"net",
"tungstenite",
"embedded-websocket",
]
models = ["core", "transactions", "requests", "ledger"]
transactions = ["core", "amounts", "currencies"]
requests = ["core", "amounts", "currencies"]
Expand Down
17 changes: 8 additions & 9 deletions src/models/ledger/objects/amendments.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::models::ledger::LedgerEntryType;
use crate::models::Model;
use alloc::borrow::Cow;
use alloc::vec::Vec;
use alloc::{borrow::Cow, string::String};
use derive_new::new;
use serde::{ser::SerializeMap, Deserialize, Serialize};

Expand All @@ -11,9 +11,9 @@ use serde_with::skip_serializing_none;
serde_with_tag! {
/// `<https://xrpl.org/amendments-object.html#amendments-fields>`
#[derive(Debug, PartialEq, Eq, Clone, new, Default)]
pub struct Majority<'a> {
pub struct Majority {
/// The Amendment ID of the pending amendment.
pub amendment: Cow<'a, str>,
pub amendment: String,
/// The `close_time` field of the ledger version where this amendment most recently gained a
/// majority.
pub close_time: u32,
Expand Down Expand Up @@ -43,8 +43,7 @@ pub struct Amendments<'a> {
pub amendments: Option<Vec<Cow<'a, str>>>,
/// Array of objects describing the status of amendments that have majority support but are not
/// yet enabled. If omitted, there are no pending amendments with majority support.
#[serde(borrow = "'a")]
pub majorities: Option<Vec<Majority<'a>>>,
pub majorities: Option<Vec<Majority>>,
}

impl<'a> Model for Amendments<'a> {}
Expand All @@ -65,7 +64,7 @@ impl<'a> Amendments<'a> {
pub fn new(
index: Cow<'a, str>,
amendments: Option<Vec<Cow<'a, str>>>,
majorities: Option<Vec<Majority<'a>>>,
majorities: Option<Vec<Majority>>,
) -> Self {
Self {
ledger_entry_type: LedgerEntryType::Amendments,
Expand All @@ -81,6 +80,7 @@ impl<'a> Amendments<'a> {
mod test_serde {
use crate::models::ledger::{Amendments, Majority};
use alloc::borrow::Cow;
use alloc::string::ToString;
use alloc::vec;

#[test]
Expand All @@ -94,9 +94,8 @@ mod test_serde {
Cow::from("740352F2412A9909880C23A559FCECEDA3BE2126FED62FC7660D628A06927F11"),
]),
Some(vec![Majority {
amendment: Cow::from(
"1562511F573A19AE9BD103B5D6B9E01B3B46805AEC5D3C4805C902B514399146",
),
amendment: "1562511F573A19AE9BD103B5D6B9E01B3B46805AEC5D3C4805C902B514399146"
.to_string(),
close_time: 535589001,
}]),
);
Expand Down
23 changes: 12 additions & 11 deletions src/models/ledger/objects/amm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::models::ledger::LedgerEntryType;
use crate::models::{amount::Amount, Currency, Model};
use alloc::borrow::Cow;
use alloc::string::String;
use alloc::vec::Vec;
use derive_new::new;
use serde::{ser::SerializeMap, Deserialize, Serialize};
Expand All @@ -10,8 +11,8 @@ use serde_with::skip_serializing_none;

serde_with_tag! {
#[derive(Debug, PartialEq, Eq, Clone, new, Default)]
pub struct AuthAccount<'a> {
pub account: Cow<'a, str>,
pub struct AuthAccount {
pub account: String,
}
}

Expand All @@ -31,14 +32,13 @@ pub struct AuctionSlot<'a> {
pub price: Amount<'a>,
/// A list of at most 4 additional accounts that are authorized to trade at the discounted fee
/// for this AMM instance.
#[serde(borrow = "'a")]
pub auth_accounts: Option<Vec<AuthAccount<'a>>>,
pub auth_accounts: Option<Vec<AuthAccount>>,
}

serde_with_tag! {
#[derive(Debug, PartialEq, Eq, Clone, new, Default)]
pub struct VoteEntry<'a> {
pub account: Cow<'a, str>,
pub struct VoteEntry {
pub account: String,
pub trading_fee: u16,
pub vote_weight: u32,
}
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct AMM<'a> {
#[serde(borrow = "'a")]
pub auction_slot: Option<AuctionSlot<'a>>,
/// A list of vote objects, representing votes on the pool's trading fee.
pub vote_slots: Option<Vec<VoteEntry<'a>>>,
pub vote_slots: Option<Vec<VoteEntry>>,
}

impl<'a> Default for AMM<'a> {
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<'a> AMM<'a> {
lptoken_balance: Amount<'a>,
trading_fee: u16,
auction_slot: Option<AuctionSlot<'a>>,
vote_slots: Option<Vec<VoteEntry<'a>>>,
vote_slots: Option<Vec<VoteEntry>>,
) -> Self {

Check warning on line 116 in src/models/ledger/objects/amm.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> src/models/ledger/objects/amm.rs:107:5 | 107 | / pub fn new( 108 | | index: Cow<'a, str>, 109 | | amm_account: Cow<'a, str>, 110 | | asset: Currency<'a>, ... | 115 | | vote_slots: Option<Vec<VoteEntry>>, 116 | | ) -> Self { | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
Self {
ledger_entry_type: LedgerEntryType::AMM,
Expand All @@ -135,6 +135,7 @@ mod test_serde {
use crate::models::currency::{Currency, IssuedCurrency, XRP};
use crate::models::ledger::amm::{AuctionSlot, AuthAccount, VoteEntry, AMM};
use alloc::borrow::Cow;
use alloc::string::ToString;
use alloc::vec;

#[test]
Expand Down Expand Up @@ -163,12 +164,12 @@ mod test_serde {
"0.8696263565463045".into(),
)),
Some(vec![
AuthAccount::new(Cow::from("rMKXGCbJ5d8LbrqthdG46q3f969MVK2Qeg")),
AuthAccount::new(Cow::from("rBepJuTLFJt3WmtLXYAxSjtBWAeQxVbncv")),
AuthAccount::new("rMKXGCbJ5d8LbrqthdG46q3f969MVK2Qeg".to_string()),
AuthAccount::new("rBepJuTLFJt3WmtLXYAxSjtBWAeQxVbncv".to_string()),
]),
)),
Some(vec![VoteEntry::new(
Cow::from("rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm"),
"rJVUeRqDFNs2xqA7ncVE6ZoAhPUoaJJSQm".to_string(),
600,
100000,
)]),
Expand Down
14 changes: 7 additions & 7 deletions src/models/ledger/objects/negative_unl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::models::ledger::LedgerEntryType;
use crate::models::Model;
use alloc::borrow::Cow;

use alloc::string::String;
use alloc::vec::Vec;
use derive_new::new;
use serde::{ser::SerializeMap, Deserialize, Serialize};
Expand All @@ -12,11 +12,11 @@ use serde_with::skip_serializing_none;
serde_with_tag! {
/// Each `DisabledValidator` object represents one disabled validator.
#[derive(Debug, PartialEq, Eq, Clone, new, Default)]
pub struct DisabledValidator<'a> {
pub struct DisabledValidator {
/// The ledger index when the validator was added to the Negative UNL.
pub first_ledger_sequence: u32,
/// The master public key of the validator, in hexadecimal.
pub public_key: Cow<'a, str>,
pub public_key: String,
}
}

Expand All @@ -40,8 +40,7 @@ pub struct NegativeUNL<'a> {
pub index: Cow<'a, str>,
/// A list of `DisabledValidator` objects (see below), each representing a trusted validator
/// that is currently disabled.
#[serde(borrow = "'a")]
pub disabled_validators: Option<Vec<DisabledValidator<'a>>>,
pub disabled_validators: Option<Vec<DisabledValidator>>,
/// The public key of a trusted validator that is scheduled to be disabled in the
/// next flag ledger.
pub validator_to_disable: Option<Cow<'a, str>>,
Expand All @@ -68,7 +67,7 @@ impl<'a> Model for NegativeUNL<'a> {}
impl<'a> NegativeUNL<'a> {
pub fn new(
index: Cow<'a, str>,
disabled_validators: Option<Vec<DisabledValidator<'a>>>,
disabled_validators: Option<Vec<DisabledValidator>>,
validator_to_disable: Option<Cow<'a, str>>,
validator_to_re_enable: Option<Cow<'a, str>>,
) -> Self {
Expand All @@ -86,6 +85,7 @@ impl<'a> NegativeUNL<'a> {
#[cfg(test)]
mod test_serde {
use super::*;
use alloc::string::ToString;
use alloc::vec;

#[test]
Expand All @@ -94,7 +94,7 @@ mod test_serde {
Cow::from("2E8A59AA9D3B5B186B0B9E0F62E6C02587CA74A4D778938E957B6357D364B244"),
Some(vec![DisabledValidator::new(
1609728,
Cow::from("ED6629D456285AE3613B285F65BBFF168D695BA3921F309949AFCD2CA7AFEC16FE"),
"ED6629D456285AE3613B285F65BBFF168D695BA3921F309949AFCD2CA7AFEC16FE".to_string(),
)]),
None,
None,
Expand Down
20 changes: 10 additions & 10 deletions src/models/ledger/objects/signer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::_serde::lgr_obj_flags;
use crate::models::ledger::LedgerEntryType;
use crate::models::Model;
use alloc::borrow::Cow;

use alloc::string::String;
use alloc::vec::Vec;
use derive_new::new;
use serde::{ser::SerializeMap, Deserialize, Serialize};
Expand All @@ -26,14 +26,14 @@ serde_with_tag! {
///
/// `<https://xrpl.org/signerlist.html#signer-entry-object>`
#[derive(Debug, PartialEq, Eq, Clone, new, Default)]
pub struct SignerEntry<'a>{
pub struct SignerEntry {
/// An XRP Ledger address whose signature contributes to the multi-signature.
pub account: Cow<'a, str>,
pub account: String,
/// The weight of a signature from this signer.
pub signer_weight: u16,
/// Arbitrary hexadecimal data. This can be used to identify the signer or for
/// other, related purposes.
pub wallet_locator: Option<Cow<'a, str>>,
pub wallet_locator: Option<String>,
}
}

Expand Down Expand Up @@ -66,8 +66,7 @@ pub struct SignerList<'a> {
pub previous_txn_lgr_seq: u32,
/// An array of Signer Entry objects representing the parties who are part of this
/// signer list.
#[serde(borrow = "'a")]
pub signer_entries: Vec<SignerEntry<'a>>,
pub signer_entries: Vec<SignerEntry>,
/// An ID for this signer list. Currently always set to 0.
#[serde(rename = "SignerListID")]
pub signer_list_id: u32,
Expand Down Expand Up @@ -102,7 +101,7 @@ impl<'a> SignerList<'a> {
owner_node: Cow<'a, str>,
previous_txn_id: Cow<'a, str>,
previous_txn_lgr_seq: u32,
signer_entries: Vec<SignerEntry<'a>>,
signer_entries: Vec<SignerEntry>,
signer_list_id: u32,
signer_quorum: u32,
) -> Self {

Check warning on line 107 in src/models/ledger/objects/signer_list.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> src/models/ledger/objects/signer_list.rs:98:5 | 98 | / pub fn new( 99 | | flags: Vec<SignerListFlag>, 100 | | index: Cow<'a, str>, 101 | | owner_node: Cow<'a, str>, ... | 106 | | signer_quorum: u32, 107 | | ) -> Self { | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
Expand All @@ -123,6 +122,7 @@ impl<'a> SignerList<'a> {
#[cfg(test)]
mod test_serde {
use super::*;
use alloc::string::ToString;
use alloc::vec;

#[test]
Expand All @@ -134,9 +134,9 @@ mod test_serde {
Cow::from("5904C0DC72C58A83AEFED2FFC5386356AA83FCA6A88C89D00646E51E687CDBE4"),
16061435,
vec![
SignerEntry::new(Cow::from("rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW"), 2, None),
SignerEntry::new(Cow::from("raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n"), 1, None),
SignerEntry::new(Cow::from("rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v"), 1, None),
SignerEntry::new("rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW".to_string(), 2, None),
SignerEntry::new("raKEEVSGnKSD9Zyvxu4z6Pqpm4ABH8FS6n".to_string(), 1, None),
SignerEntry::new("rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v".to_string(), 1, None),
],
0,
3,
Expand Down
9 changes: 5 additions & 4 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use derive_new::new;
pub use model::Model;

use crate::models::currency::{Currency, XRP};
use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
use strum_macros::Display;

Expand All @@ -52,11 +53,11 @@ pub enum AccountObjectType {
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default, Clone, new)]
#[serde(rename_all = "PascalCase")]
pub struct PathStep<'a> {
account: Option<&'a str>,
currency: Option<&'a str>,
issuer: Option<&'a str>,
account: Option<Cow<'a, str>>,
currency: Option<Cow<'a, str>>,
issuer: Option<Cow<'a, str>>,
r#type: Option<u8>,
type_hex: Option<&'a str>,
type_hex: Option<Cow<'a, str>>,
}

/// Returns a Currency as XRP for the currency, without a value.
Expand Down
23 changes: 12 additions & 11 deletions src/models/requests/account_channels.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::borrow::Cow;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

Expand Down Expand Up @@ -35,21 +36,21 @@ pub struct AccountChannels<'a> {
/// The unique identifier of an account, typically the
/// account's Address. The request returns channels where
/// this account is the channel's owner/source.
pub account: &'a str,
pub account: Cow<'a, str>,
/// The unique request id.
pub id: Option<&'a str>,
pub id: Option<Cow<'a, str>>,
/// A 20-byte hex string for the ledger version to use.
pub ledger_hash: Option<&'a str>,
pub ledger_hash: Option<Cow<'a, str>>,
/// The ledger index of the ledger to use, or a shortcut
/// string to choose a ledger automatically.
pub ledger_index: Option<&'a str>,
pub ledger_index: Option<Cow<'a, str>>,
/// Limit the number of transactions to retrieve. Cannot
/// be less than 10 or more than 400. The default is 200.
pub limit: Option<u16>,
/// The unique identifier of an account, typically the
/// account's Address. If provided, filter results to
/// payment channels whose destination is this account.
pub destination_account: Option<&'a str>,
pub destination_account: Option<Cow<'a, str>>,
/// Value from a previous paginated response.
/// Resume retrieving data where that response left off.
pub marker: Option<u32>,
Expand All @@ -61,7 +62,7 @@ pub struct AccountChannels<'a> {
impl<'a> Default for AccountChannels<'a> {
fn default() -> Self {
AccountChannels {
account: "",
account: "".into(),
id: None,
ledger_hash: None,
ledger_index: None,
Expand All @@ -77,12 +78,12 @@ impl<'a> Model for AccountChannels<'a> {}

impl<'a> AccountChannels<'a> {
pub fn new(
account: &'a str,
id: Option<&'a str>,
ledger_hash: Option<&'a str>,
ledger_index: Option<&'a str>,
account: Cow<'a, str>,
id: Option<Cow<'a, str>>,
ledger_hash: Option<Cow<'a, str>>,
ledger_index: Option<Cow<'a, str>>,
limit: Option<u16>,
destination_account: Option<&'a str>,
destination_account: Option<Cow<'a, str>>,
marker: Option<u32>,
) -> Self {
Self {
Expand Down
Loading

0 comments on commit 095f5c4

Please sign in to comment.