-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c4f8d9
commit b4698d7
Showing
8 changed files
with
106 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::str::FromStr; | ||
|
||
use bigdecimal::BigDecimal; | ||
use diesel::{Insertable, Queryable, Selectable}; | ||
use shared::token::Token; | ||
|
||
use crate::schema::token; | ||
|
||
pub type DenominationDb = i16; | ||
|
||
#[derive(Clone, Queryable, Selectable, Insertable)] | ||
#[diesel(table_name = token)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct TokenDb { | ||
pub address: String, | ||
pub denomination: i16, | ||
pub gas_price: BigDecimal, | ||
} | ||
|
||
#[derive(Clone, Queryable, Selectable)] | ||
#[diesel(table_name = token)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct GasPriceDb { | ||
#[diesel(column_name = "address")] | ||
pub token: String, | ||
#[diesel(column_name = "gas_price")] | ||
pub raw_amount: BigDecimal, | ||
pub denomination: DenominationDb, | ||
} | ||
|
||
impl From<Token> for TokenDb { | ||
fn from(value: Token) -> Self { | ||
Self { | ||
address: value.address, | ||
denomination: value.denomination as i16, | ||
gas_price: BigDecimal::from_str(&value.gas_price.to_string()) | ||
.expect("Invalid gas_price amount"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters