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 parity scale codec #547

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
27c62bc
Add parity scale codec
Gauthamastro Sep 6, 2022
394d8f8
Add scale-info too
Gauthamastro Sep 6, 2022
204d127
Add scale-info too
Gauthamastro Sep 6, 2022
610096f
Make from_parts_raw
Gauthamastro Sep 14, 2022
b896337
Merge branch 'master' into master
Gauthamastro Jun 22, 2023
25f0849
Make deps in alphabetical order
Gauthamastro Jun 22, 2023
031d203
Clippy/fix ruleset (#598)
mkatychev Jul 16, 2023
deeb242
Fixes issue with truncating implicitly rounding in some cases (#600)
paupino Jul 17, 2023
091d715
added new rkyv (#597)
mkatychev Jul 17, 2023
67efda9
Version 1.31.0 (#601)
paupino Jul 29, 2023
29d3e2e
Specify version on macro dependency
paupino Jul 29, 2023
a6d5caf
Drop unnecessary byteorder dependency (#603)
psychon Aug 18, 2023
951512d
Fixes issue with is_integer failing on decimal bounds (#605)
paupino Aug 23, 2023
03ce442
Version 1.32 (#606)
paupino Aug 23, 2023
f18e57c
Introduce breaking change check (#608)
paupino Sep 9, 2023
aacdefd
Remove semver checks from build and put into makefile (#609)
paupino Sep 9, 2023
1686b69
Fixes issue whereby scale 29 is required however is optimized away (#…
paupino Nov 10, 2023
ede308d
Upgrade Borsh to resolve vulnerability (#621)
paupino Nov 13, 2023
6cfccf3
deserializes empty string into None Option (#607)
gai6948 Nov 14, 2023
1c80137
Version 1.33.0 (#622)
paupino Nov 14, 2023
c3802db
Fixes precision issue with to_f64 with some numbers without fractions…
paupino Nov 16, 2023
c4d4d3e
Version 1.33.1 (#626)
paupino Nov 16, 2023
829355a
Introduces `macros` feature and cleans up serde documentation a littl…
paupino Dec 1, 2023
f02f5ac
Update readme to add comparisons (#630)
paupino Dec 22, 2023
d323dd4
Remove cargo-edit reference from README (#633)
robjtede Jan 9, 2024
10ee2ee
Auto-document feature guarded items (#634)
robjtede Jan 9, 2024
80e9f08
Reimplement pow function for integer exponent. (#638)
schungx Jan 13, 2024
aa2c3d3
Fixes error handling when second decimal place at tail position (#636)
paupino Jan 13, 2024
bacc60b
Version 1.34 (#640)
paupino Jan 31, 2024
999bb02
Force version number during macro resolution (#642)
paupino Feb 1, 2024
179039a
Rollback macros feature flag due to dependency resolution issues (#643)
paupino Feb 1, 2024
d72e787
Bump macros version
paupino Feb 1, 2024
4666555
Add parity scale codec
Gauthamastro Sep 6, 2022
65ec77a
Add scale-info too
Gauthamastro Sep 6, 2022
e7511dc
Add scale-info too
Gauthamastro Sep 6, 2022
62cf912
Make from_parts_raw
Gauthamastro Sep 14, 2022
d778de7
Make deps in alphabetical order
Gauthamastro Jun 22, 2023
bbcc77a
Merge remote-tracking branch 'origin/master'
Gauthamastro Feb 8, 2024
e1b54cd
Update hashbrown
Gauthamastro Feb 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ diesel1 = { default-features = false, optional = true, package = "diesel", versi
diesel2 = { default-features = false, optional = true, package = "diesel", version = "2.0" }
ndarray = { default-features = false, optional = true, version = "0.15.6" }
num-traits = { default-features = false, features = ["i128"], version = "0.2" }
parity-scale-codec = { optional = true, version = "3.1.5", features = ["max-encoded-len"], default-features = false}
parity-scale-codec-derive = { optional = true, version = "3.1.3",default-features = false}
postgres = { default-features = false, optional = true, version = "0.19" }
proptest = { default-features = false, optional = true, features = ["std"], version = "1.0" }
rand = { default-features = false, optional = true, version = "0.8" }
rkyv = { default-features = false, features = ["size_32", "std"], optional = true, version = "0.7" }
rocket = { default-features = false, optional = true, version = "0.5.0-rc.1" }
scale-info = {optional=true, version = "2.1.2", features = ["derive"], default-features = false}
serde = { default-features = false, optional = true, version = "1.0" }
serde_json = { default-features = false, optional = true, version = "1.0" }
tokio-postgres = { default-features = false, optional = true, version = "0.7" }
Expand Down Expand Up @@ -78,6 +81,7 @@ rkyv = ["dep:rkyv"]
rkyv-safe = ["dep:bytecheck", "rkyv/validation"]
rocket-traits = ["dep:rocket"]
rust-fuzz = ["dep:arbitrary"]
scale-codec = ["parity-scale-codec-derive","parity-scale-codec","scale-info"]
Copy link
Owner

Choose a reason for hiding this comment

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

We're starting to use the updated format for feature dependencies:

Suggested change
scale-codec = ["parity-scale-codec-derive","parity-scale-codec","scale-info"]
scale-codec = ["dep:parity-scale-codec-derive","dep:parity-scale-codec","dep:scale-info"]

serde = ["dep:serde"]
serde-arbitrary-precision = ["serde-with-arbitrary-precision"]
serde-bincode = ["serde-str"] # Backwards compatability
Expand All @@ -86,7 +90,7 @@ serde-str = ["serde-with-str"]
serde-with-arbitrary-precision = ["serde", "serde_json/arbitrary_precision", "serde_json/std"]
serde-with-float = ["serde"]
serde-with-str = ["serde"]
std = ["arrayvec/std", "borsh?/std", "bytecheck?/std", "byteorder?/std", "bytes?/std", "rand?/std", "rkyv?/std", "serde?/std", "serde_json?/std"]
std = ["arrayvec/std", "borsh?/std", "bytecheck?/std", "byteorder?/std", "bytes?/std", "rand?/std", "rkyv?/std", "serde?/std", "serde_json?/std", "parity-scale-codec?/std","scale-info?/std"]
Copy link
Owner

Choose a reason for hiding this comment

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

Just a simple reordering of inclusions:

Suggested change
std = ["arrayvec/std", "borsh?/std", "bytecheck?/std", "byteorder?/std", "bytes?/std", "rand?/std", "rkyv?/std", "serde?/std", "serde_json?/std", "parity-scale-codec?/std","scale-info?/std"]
std = ["arrayvec/std", "borsh?/std", "bytecheck?/std", "byteorder?/std", "bytes?/std", "parity-scale-codec?/std", "rand?/std", "rkyv?/std", "scale-info?/std", "serde?/std", "serde_json?/std"]

tokio-pg = ["db-tokio-postgres"] # Backwards compatability

[workspace]
Expand Down
11 changes: 10 additions & 1 deletion src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ use num_traits::float::FloatCore;
use num_traits::{FromPrimitive, Num, One, Signed, ToPrimitive, Zero};
#[cfg(feature = "rkyv")]
use rkyv::{Archive, Deserialize, Serialize};
#[cfg(feature = "scale-codec")]
use parity_scale_codec_derive::{Decode,Encode, MaxEncodedLen};
#[cfg(feature = "scale-codec")]
use scale_info::TypeInfo;

/// The smallest value that can be represented by this decimal type.
const MIN: Decimal = Decimal {
Expand Down Expand Up @@ -120,6 +124,11 @@ pub struct UnpackedDecimal {
archive(compare(PartialEq)),
archive_attr(derive(Clone, Copy, Debug))
)]
#[cfg_attr(feature = "rkyv-safe", archive_attr(derive(CheckBytes)))]
Copy link
Owner

Choose a reason for hiding this comment

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

This is duplicated below

Suggested change
#[cfg_attr(feature = "rkyv-safe", archive_attr(derive(CheckBytes)))]

#[cfg_attr(
feature = "scale-codec",
derive(Decode, Encode, TypeInfo, MaxEncodedLen),
Copy link
Owner

Choose a reason for hiding this comment

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

Side note (no change required): these derive attributes are causing a bit of code bloat. I want to rethink how we do this in v2. It may be by exposing a wrapper struct and aliasing it however all in all, this current approach isn't entirely scalable.

)]
Comment on lines +128 to +131
Copy link
Owner

Choose a reason for hiding this comment

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

This will fix the code formatting error in the build:

Suggested change
#[cfg_attr(
feature = "scale-codec",
derive(Decode, Encode, TypeInfo, MaxEncodedLen),
)]
#[cfg_attr(feature = "scale-codec", derive(Decode, Encode, TypeInfo, MaxEncodedLen))]

#[cfg_attr(feature = "rkyv-safe", archive_attr(derive(bytecheck::CheckBytes)))]
pub struct Decimal {
// Bits 0-15: unused
Expand Down Expand Up @@ -548,7 +557,7 @@ impl Decimal {
}

#[must_use]
pub(crate) const fn from_parts_raw(lo: u32, mid: u32, hi: u32, flags: u32) -> Decimal {
pub const fn from_parts_raw(lo: u32, mid: u32, hi: u32, flags: u32) -> Decimal {
Gauthamastro marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

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

Reverting this line:

Suggested change
pub const fn from_parts_raw(lo: u32, mid: u32, hi: u32, flags: u32) -> Decimal {
pub(crate) const fn from_parts_raw(lo: u32, mid: u32, hi: u32, flags: u32) -> Decimal {

if lo == 0 && mid == 0 && hi == 0 {
Decimal {
lo,
Expand Down