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

initial commit #1

Closed
wants to merge 11 commits into from
Closed

initial commit #1

wants to merge 11 commits into from

Conversation

josojo
Copy link
Contributor

@josojo josojo commented Jan 14, 2019

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.

Copy link
Contributor

@fleupold fleupold left a 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.

src/bin/database_setup.rs Outdated Show resolved Hide resolved
src/bin/database_setup.rs Outdated Show resolved Hide resolved
src/bin/database_setup.rs Outdated Show resolved Hide resolved
src/bin/database_setup.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@bh2smith bh2smith self-requested a review January 14, 2019 08:52
@fleupold
Copy link
Contributor

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.

src/bin/database_setup.rs Outdated Show resolved Hide resolved
src/bin/database_setup.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bh2smith bh2smith left a 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.

@josojo
Copy link
Contributor Author

josojo commented Jan 15, 2019

Currently, I am hanging on 3 points:

  • how to deserialize strings,
  • how to make a mongodb::bson::document from a string or another variable
  • how to deserialize arrays of different size: ie. [i32, 32] is implemented, but [i32, 64] is not

@fleupold
Copy link
Contributor

@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.

driver/Cargo.toml Outdated Show resolved Hide resolved
driver/src/bin/global_helpers.rs Outdated Show resolved Hide resolved
driver/src/bin/global_helpers.rs Outdated Show resolved Hide resolved
@josojo
Copy link
Contributor Author

josojo commented Jan 16, 2019

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.

It's really just my internal testing... I am fine with doing it in python etc...

@josojo
Copy link
Contributor Author

josojo commented Jan 17, 2019

I think this very first basic PR is ready to merge. What do you guys think?
If you have more feedback, shoot!

Only remaining issue is that the struct State works with Vec instead of Vec. I will dig deeper into that later.

driver/src/bin/models.rs Outdated Show resolved Hide resolved
driver/src/bin/models.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@fleupold fleupold left a 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 Show resolved Hide resolved
driver/src/bin/database_setup.rs Outdated Show resolved Hide resolved
let coll = client.db("dfusion").collection("State");


let state = models::State {
Copy link
Contributor

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/database_setup.rs Outdated Show resolved Hide resolved
driver/src/bin/database_setup.rs Outdated Show resolved Hide resolved
driver/src/bin/fetch_db.rs Outdated Show resolved Hide resolved
driver/src/bin/fetch_db.rs Outdated Show resolved Hide resolved
let client = Client::connect("localhost", 27017)
.expect("Failed to initialize standalone client.");

let mut query=String::from(r#" { "slot": "#);
Copy link
Contributor

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/

Copy link
Contributor Author

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.


fn get_current_balances() -> Result<models::State, io::Error>{

let client = Client::connect("localhost", 27017)
Copy link
Contributor

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

use mongodb::{Client, ThreadedClient};
use mongodb::db::ThreadedDatabase;

fn get_current_balances() -> Result<models::State, io::Error>{
Copy link
Contributor

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.

@fleupold
Copy link
Contributor

Turns out rust has support for uint128 (https://doc.rust-lang.org/book/print.html#integer-types)

@bh2smith
Copy link
Contributor

Is this still an active branch? Or is this equivalent to the apply Deposits PR?

@josojo
Copy link
Contributor Author

josojo commented Jan 19, 2019

Yes, it is! apply deposits also merges into this branch :) I will figure out what to merge on Monday

@fleupold
Copy link
Contributor

No longer relevant.

@fleupold fleupold closed this Jan 31, 2019
@fleupold fleupold deleted the rustSQL branch February 13, 2019 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants