-
Notifications
You must be signed in to change notification settings - Fork 49
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
Database Macro #408
Database Macro #408
Conversation
common/db/src/create_db.rs
Outdated
@@ -22,7 +22,7 @@ pub fn db_key(db_dst: &'static [u8], item_dst: &'static [u8], key: impl AsRef<[u | |||
/// | |||
/// # Example | |||
/// | |||
/// ``` | |||
/// ```no_run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply correct the missing import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the doc test is compiled in the current scope, but those types I use aren't going to be available, as is the case with the bincode
dependency - so correcting the missing import would just lead to more errors 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry if I was spamming CI 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, don't worry. We're not on any paid plan.
6f375b2
to
576057c
Compare
Description
This pull request closes #364. The Serai code-base is full of repetitive database code used to namespace keys. The provided macro generates the database and item DSTs necessary for a new key. The macro supports zero or more
scale
encodable arguments in the generation of the key and will likewise automaticallybincode
serialize/de-serialize the database value resulting in better DX and hopefully less bugs.Considerations
impl
blockbincode
was chosen over scale because it supports a wider range of types. It's still possible to storescale
bytes in the form of aVec<u8>
and transform later as is the case nowNetwork
) which can't be auto generated by the macro. Moving forward, helper methods should receive those generic arguments instead.Example
In this case 3 databases are created, but let's focus on
ParamsDB
.ParamsDB
gets a "KeyGenDB" database DST and a "ParamsDB" item DST, whoseget
andset
become:Future Work
The pull request is being opened now so that future work builds off of this macro while we convert old databases and pass tests.