Skip to content

Commit

Permalink
schema updates, added basic models.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kriptikz committed Aug 12, 2024
1 parent 35c4ea7 commit 7e6f640
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
1 change: 1 addition & 0 deletions migrations/2024-08-11-235837_create_pools/up.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CREATE TABLE pools (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
proof_pubkey VARCHAR(44) NOT NULL,
authority_pubkey VARCHAR(44) NOT NULL,
total_rewards BIGINT UNSIGNED DEFAULT 0,
claimed_rewards BIGINT UNSIGNED DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
Expand Down
4 changes: 2 additions & 2 deletions migrations/2024-08-12-003544_create_txns/up.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE txns (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
txn_type ENUM('mine', 'claim') NOT NULL,
txn_type VARCHAR(15) NOT NULL,
signature VARCHAR(200) NOT NULL,
priority_fee INT UNSIGNED DEFAULT 0,
priority_fee INT UNSIGNED DEFAULT 0 NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL
)
66 changes: 66 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use diesel::prelude::*;
use serde::{Serialize, Deserialize};
use chrono::NaiveDateTime;

#[derive(Debug, Serialize, Deserialize, Queryable, Selectable, QueryableByName)]
#[diesel(table_name = crate::schema::challenges)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Challenge {
pub id: i32,
pub pool_id: i32,
pub submission_id: Option<i32>,
pub challenge: Vec<u8>,
pub rewards_earned: Option<u64>,
}

#[derive(Debug, Serialize, Deserialize, Queryable, Selectable, QueryableByName)]
#[diesel(table_name = crate::schema::claims)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Claim {
pub id: i32,
pub miner_id: i32,
pub pool_id: i32,
pub txn_id: i32,
pub amount: u64,
}

#[derive(Debug, Serialize, Deserialize, Queryable, Selectable, QueryableByName)]
#[diesel(table_name = crate::schema::miners)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Miner {
pub id: i32,
pub pubkey: String,
pub enabled: bool,
}

#[derive(Debug, Serialize, Deserialize, Queryable, Selectable, QueryableByName)]
#[diesel(table_name = crate::schema::pools)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Pool {
pub id: i32,
pub proof_pubkey: String,
pub authority_pubkey: String,
pub total_rewards: Option<u64>,
pub claimed_rewards: Option<u64>,
}

#[derive(Debug, Serialize, Deserialize, Queryable, Selectable, QueryableByName)]
#[diesel(table_name = crate::schema::submissions)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Submission {
pub id: i32,
pub miner_id: i32,
pub challenge_id: i32,
pub difficulty: i8,
pub created_at: NaiveDateTime,
}

#[derive(Debug, Serialize, Deserialize, Queryable, Selectable, QueryableByName)]
#[diesel(table_name = crate::schema::txns)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Txn {
pub id: i32,
pub txn_type: String,
pub signature: String,
pub priority_fee: u32,
}
17 changes: 5 additions & 12 deletions src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// @generated automatically by Diesel CLI.

pub mod sql_types {
#[derive(diesel::query_builder::QueryId, Clone, diesel::sql_types::SqlType)]
#[diesel(mysql_type(name = "Enum"))]
pub struct TxnsTxnTypeEnum;
}

diesel::table! {
challenges (id) {
id -> Integer,
Expand Down Expand Up @@ -47,6 +41,8 @@ diesel::table! {
id -> Integer,
#[max_length = 44]
proof_pubkey -> Varchar,
#[max_length = 44]
authority_pubkey -> Varchar,
total_rewards -> Nullable<Unsigned<Bigint>>,
claimed_rewards -> Nullable<Unsigned<Bigint>>,
created_at -> Timestamp,
Expand All @@ -67,16 +63,13 @@ diesel::table! {
}

diesel::table! {
use diesel::sql_types::*;
use super::sql_types::TxnsTxnTypeEnum;

txns (id) {
id -> Integer,
#[max_length = 5]
txn_type -> TxnsTxnTypeEnum,
#[max_length = 15]
txn_type -> Varchar,
#[max_length = 200]
signature -> Varchar,
priority_fee -> Nullable<Unsigned<Integer>>,
priority_fee -> Unsigned<Integer>,
created_at -> Timestamp,
updated_at -> Timestamp,
}
Expand Down

0 comments on commit 7e6f640

Please sign in to comment.