-
Notifications
You must be signed in to change notification settings - Fork 9
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
initial commit #1
Conversation
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.
Is there a reason why we setup the db in rust? I was expecting the python code to do the setup, since it will always be the first part of the system to write into the db.
Would it make sense to move the rust code in a subdirectory (something like driver?). I was hoping that in this repository we could have a few tools (django app, rust driver) and all connected with one docker-compose file. |
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.
We are off to a good start!
Please note that accountID and tokenID start at 1 (since they involve a "bijective" mapping whose inverse's default value is 0).
I would also like to refer to these "indexes" as IDs since they are essentially primary keys in a database. I am not strictly stuck to this idea if you don't like it.
Currently, I am hanging on 3 points:
|
@josojo the following works for me to create a Document from a string: let json: serde_json::Value = serde_json::from_str(&document_str).expect("Failed to parse json");
let bson = json.into();
let temp: Document = mongodb::from_bson(bson).expect("Failed to convert bson to document"); Regarding serialization of arrays, could you use a vector for now instead of an array? Otherwise, you probably have to implement your own serialize/deserialize method (cf. serde-rs/serde#573 (comment) for an example). I'm not sure what exactly you mean by "deserialize strings". Serializing a string should already be supported by serde and deserializing from a string would mean parsing json? Maybe you can elaborate a bit more on the exact problem. |
It's really just my internal testing... I am fine with doing it in python etc... |
I think this very first basic PR is ready to merge. What do you guys think? Only remaining issue is that the struct State works with Vec instead of Vec. I will dig deeper into that later. |
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.
If we want to include the test data setup, let's move this file into something like tests and call it: create_fake_data or something.
Some comments about the db fetching. Looks good overall, but could use a bit more polish.
Also, I think we should find a reason for 100bit numbers. If serialisation of PrimeFiled is an issue, you should be able to add your own implementation of that. But feel free to push that into a separate PR.
driver/src/bin/database_setup.rs
Outdated
let coll = client.db("dfusion").collection("State"); | ||
|
||
|
||
let state = models::State { |
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.
nit: still something wrong with indentation here.
driver/src/bin/fetch_db.rs
Outdated
let client = Client::connect("localhost", 27017) | ||
.expect("Failed to initialize standalone client."); | ||
|
||
let mut query=String::from(r#" { "slot": "#); |
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.
Creating the query should be a one-liner with format strings: https://doc.rust-lang.org/std/fmt/
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, I could still not figure this one out. The issue is that I have to work with raw... or represent the " somehow else.
I will come to it back later.
driver/src/bin/fetch_db.rs
Outdated
|
||
fn get_current_balances() -> Result<models::State, io::Error>{ | ||
|
||
let client = Client::connect("localhost", 27017) |
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.
You probably want to read the hose/port from some configuration file somewhere
driver/src/bin/fetch_db.rs
Outdated
use mongodb::{Client, ThreadedClient}; | ||
use mongodb::db::ThreadedDatabase; | ||
|
||
fn get_current_balances() -> Result<models::State, io::Error>{ |
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.
In order to unit test the components that use these methods later, you might have to put these methods into a trait that can be mocked.
Turns out rust has support for uint128 (https://doc.rust-lang.org/book/print.html#integer-types) |
Is this still an active branch? Or is this equivalent to the apply Deposits PR? |
Yes, it is! apply deposits also merges into this branch :) I will figure out what to merge on Monday |
No longer relevant. |
Very first intital commit.
it allows us to load mock data into the mongodb database
it allows us to fetch the data again out of it.