-
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
Open
neocybereth
wants to merge
13
commits into
anoma:main
Choose a base branch
from
neocybereth:feat/add-total-reward-for-epoch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a3040ff
feat: add total reward for epoch
neocybereth 523a368
fix: add migration to add epoch field to rewwrds table
neocybereth 5030f97
fix: restore sample_env
neocybereth 3540112
fix: add rewards migrations
neocybereth 90fecd6
fix: add pos_rewards table
neocybereth 2146524
fix: update migrations
neocybereth 59726d0
fix: update migration
neocybereth 149ed55
fix: update accoridng to review
neocybereth 92e0aa7
fix: formatting on schema
neocybereth c61a2e6
fix: update rewards epoch func
neocybereth 0957a4a
fix: orm pos_rewards fix for bigdecimal
neocybereth 1244bab
fix: update sql statements
neocybereth fae5e1f
fix: add webserver endpoint
neocybereth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
orm/migrations/2024-12-16-231256_add_epoch_pos_rewards_table/down.sql
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,3 @@ | ||
ALTER table pos_rewards ADD CONSTRAINT pos_rewards_owner_validator_id_key UNIQUE (owner, validator_id); | ||
ALTER table pos_rewards DROP CONSTRAINT pos_rewards_owner_validator_id_epoch_key; | ||
ALTER TABLE pos_rewards DROP COLUMN epoch; |
7 changes: 7 additions & 0 deletions
7
orm/migrations/2024-12-16-231256_add_epoch_pos_rewards_table/up.sql
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,7 @@ | ||
-- 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; | ||
-- Also update the UNIQUE constraint to include the epoch column | ||
ALTER table pos_rewards ADD CONSTRAINT pos_rewards_owner_validator_id_epoch_key unique (owner, validator_id, epoch); | ||
ALTER table pos_rewards DROP CONSTRAINT pos_rewards_owner_validator_id_key; |
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 |
---|---|---|
@@ -1,29 +1,28 @@ | ||
use std::str::FromStr; | ||
|
||
use bigdecimal::BigDecimal; | ||
use diesel::{Insertable, Queryable, Selectable}; | ||
use crate::schema::pos_rewards; | ||
use shared::rewards::Reward; | ||
use std::str::FromStr; | ||
|
||
use crate::schema::pos_rewards; | ||
|
||
#[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_str(&reward.amount.to_string()).unwrap(), | ||
epoch, | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
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 comment
The 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
rewards/src/services/namada.rs
to reuse the existing function for querying current epoch instead of copying it: 2d0a5acFeel free to incorporate it into your branch here
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.
alright I've integrated both of those 👍