-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat: add total reward for epoch #204
base: main
Are you sure you want to change the base?
Changes from 8 commits
a3040ff
523a368
5030f97
3540112
90fecd6
2146524
59726d0
149ed55
92e0aa7
c61a2e6
0957a4a
1244bab
fae5e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE pos_rewards DROP COLUMN epoch; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- Alters the pos_rewards table to add a fourth column: | ||
-- epoch: INTEGER, representing the epoch number | ||
-- Populate existing records with epoch = 0 | ||
ALTER TABLE pos_rewards ADD COLUMN epoch INTEGER NOT NULL DEFAULT 0; | ||
-- Now we can safely drop the default | ||
ALTER TABLE pos_rewards ALTER COLUMN epoch DROP DEFAULT; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
use std::str::FromStr; | ||
|
||
use bigdecimal::BigDecimal; | ||
use diesel::{Insertable, Queryable, Selectable}; | ||
use shared::rewards::Reward; | ||
|
||
use crate::schema::pos_rewards; | ||
use shared::rewards::Reward; | ||
|
||
#[derive(Insertable, Clone, Queryable, Selectable)] | ||
#[derive(Insertable, Queryable, Selectable, Clone)] | ||
#[diesel(table_name = pos_rewards)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct PosRewardInsertDb { | ||
pub owner: String, | ||
pub validator_id: i32, | ||
pub raw_amount: BigDecimal, | ||
pub epoch: i32, | ||
} | ||
|
||
pub type PoSRewardDb = PosRewardInsertDb; | ||
|
||
impl PosRewardInsertDb { | ||
pub fn from_reward(reward: Reward, validator_id: i32) -> Self { | ||
Self { | ||
pub fn from_reward(reward: Reward, validator_id: i32, epoch: i32) -> Self { | ||
PosRewardInsertDb { | ||
owner: reward.delegation_pair.delegator_address.to_string(), | ||
raw_amount: BigDecimal::from_str(&reward.amount.to_string()) | ||
.expect("Invalid amount"), | ||
validator_id, | ||
raw_amount: BigDecimal::from(reward.amount), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note - this is assigning to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
epoch, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,47 @@ | ||
// @generated automatically by Diesel CLI. | ||
|
||
pub mod sql_types { | ||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "crawler_name"))] | ||
pub struct CrawlerName; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "governance_kind"))] | ||
pub struct GovernanceKind; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "governance_result"))] | ||
pub struct GovernanceResult; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "governance_tally_type"))] | ||
pub struct GovernanceTallyType; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "payment_kind"))] | ||
pub struct PaymentKind; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "payment_recurrence"))] | ||
pub struct PaymentRecurrence; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "token_type"))] | ||
pub struct TokenType; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "transaction_kind"))] | ||
pub struct TransactionKind; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "transaction_result"))] | ||
pub struct TransactionResult; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "validator_state"))] | ||
pub struct ValidatorState; | ||
|
||
#[derive( | ||
diesel::query_builder::QueryId, | ||
std::fmt::Debug, | ||
diesel::sql_types::SqlType, | ||
)] | ||
#[derive(diesel::query_builder::QueryId, std::fmt::Debug, diesel::sql_types::SqlType)] | ||
#[diesel(postgres_type(name = "vote_kind"))] | ||
pub struct VoteKind; | ||
} | ||
|
@@ -227,6 +183,7 @@ diesel::table! { | |
owner -> Varchar, | ||
validator_id -> Int4, | ||
raw_amount -> Numeric, | ||
epoch -> Int4, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @neocybereth -- I have another suggestion here, it looks like you've reformatted a bunch of things in this file that aren't really part of this branch. It would be best to keep your changes minimal and not include these formatting changes. I think this line is the only change that you should actually have in this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed a commit that restores that formatting here, and also has one other small refactor in the Feel free to incorporate it into your branch here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alright I've integrated both of those 👍 |
||
} | ||
} | ||
|
||
|
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.
While testing this, I ran into a problem where the
pos_rewards
table didn't have an updatedUNIQUE
constraint which incorporates theepoch
column.I pushed a commit that fixes that: 725f9c9
Feel free to add it to your branch also.
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.
Updated that here:
1244bab