Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ledger object models #58

Merged

Conversation

LimpidCrypto
Copy link
Collaborator

@LimpidCrypto LimpidCrypto commented Mar 17, 2023

This is the follow up to #57

High Level Overview of Change

Ledger object models

Adds ledger object models including the AMM object model.

Models in general

It is also an attempt to implement a general order for fields (models/mod.rs):

//! Order of models:
//! 1. Type of model
//! 2. Required common fields in alphabetical order
//! 3. Required specific fields in alphabetical order
//! 4. Optional common fields in alphabetical order
//! 5. Optional specific fields in alphabetical order

If agreed on the order:

  • open a new issue for refactoring the other models

serde_with_tag

Moved the Helper to fn serialize and fn deserialize to avoid defining it multiple times in a file.

Context of Change

#27

Type of Change

  • New feature (non-breaking change which adds functionality)

Test Plan

  • serialization tests
  • deserialization tests

Future Tasks

Keep an eye on the XRPFees amendment. It could change how some fields are typed and/or named.

@LimpidCrypto LimpidCrypto self-assigned this Mar 17, 2023
@LimpidCrypto LimpidCrypto added enhancement New feature or request 1st month Planned to be worked on in the first month. Estimate budget: 13,333 $ 2nd month Planned to be worked on in the second month. Estimate budget: 6,666 $ XRPL Grants This issue is planned to get resoled as part of the XRPL Grants program (within 8 months) labels Mar 17, 2023
@LimpidCrypto LimpidCrypto added this to the Add models milestone Mar 17, 2023
@LimpidCrypto LimpidCrypto linked an issue Mar 17, 2023 that may be closed by this pull request
22 tasks
src/_serde/mod.rs Outdated Show resolved Hide resolved
src/_serde/mod.rs Outdated Show resolved Hide resolved
src/_serde/mod.rs Outdated Show resolved Hide resolved
src/_serde/mod.rs Outdated Show resolved Hide resolved
src/_serde/mod.rs Outdated Show resolved Hide resolved
src/_serde/mod.rs Show resolved Hide resolved
Comment on lines +20 to +35
match flags_value_result {
Ok(flags_as_value) => {
let flag_vec_result: Result<Vec<u32>, serde_json::Error> =
serde_json::from_value(flags_as_value);
match flag_vec_result {
Ok(flags_vec) => s.serialize_u32(flags_vec.iter().sum()),
Err(_) => {
// TODO: Find a way to use custom errors
Err(ser::Error::custom("SerdeIntermediateStepError: Failed to turn flags into `Vec<u32>` during serialization"))
}
}
}
Err(_) => Err(ser::Error::custom(
"SerdeIntermediateStepError: Failed to turn flags into `Value` during serialization",
)),
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an if let or pattern binding might make this a bit cleaner.

Comment on lines +102 to 112
let flags_vec_result: Result<Vec<F>, D::Error> = deserialize_flags(d);
match flags_vec_result {
Ok(flags_vec) => {
if flags_vec.is_empty() {
Ok(None)
} else {
Ok(Some(flags_vec))
}
}
Err(error) => Err(error),
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An if/else would be simpler here.

@LimpidCrypto LimpidCrypto merged commit 83e745e into sephynox:develop Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1st month Planned to be worked on in the first month. Estimate budget: 13,333 $ 2nd month Planned to be worked on in the second month. Estimate budget: 6,666 $ enhancement New feature or request XRPL Grants This issue is planned to get resoled as part of the XRPL Grants program (within 8 months)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add Ledger objects
2 participants