-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add task that tracks stake delegation (#157)
* introduce new relation that tracks stake delegation certs * add 'delegation/address' route * regen docs/bin/openapi.json * remove copy-pasted comment in migration * cleanup unused branches/variants of certificates * add previous pool column this helps getting un-delegation events by pool, since otherwise re-delegation doesn't directly address the pool that no longer has the delegation. * add endpoint get pool's delegation history by pool * add slot and pool fields to the delegation for pool query * delegationForAddress: extract staking credential if arg is full address * rename migration file and add stake credential column index * add limit for slot range and pools * eslint fixes
- Loading branch information
1 parent
d8fc630
commit b3deea0
Showing
22 changed files
with
826 additions
and
1 deletion.
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
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,38 @@ | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)] | ||
#[sea_orm(table_name = "StakeDelegationCredentialRelation")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, column_type = "BigInteger")] | ||
pub id: i64, | ||
pub stake_credential: i64, | ||
// pool registrations are not tracked in StakeCredentials, | ||
pub pool_credential: Option<Vec<u8>>, | ||
pub tx_id: i64, | ||
pub previous_pool: Option<Vec<u8>>, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::stake_credential::Entity", | ||
from = "Column::StakeCredential", | ||
to = "super::stake_credential::Column::Id" | ||
)] | ||
StakeCredential, | ||
#[sea_orm( | ||
belongs_to = "super::transaction::Entity", | ||
from = "Column::TxId", | ||
to = "super::transaction::Column::Id" | ||
)] | ||
Transaction, | ||
} | ||
|
||
impl Related<super::stake_credential::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::StakeCredential.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
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 |
---|---|---|
|
@@ -63,3 +63,5 @@ readonly=false | |
readonly=false | ||
|
||
[MultieraCip25EntryTask] | ||
|
||
[MultieraAddressDelegationTask] |
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
75 changes: 75 additions & 0 deletions
75
indexer/migration/src/m20230927_000016_create_stake_delegation_table.rs
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,75 @@ | ||
use entity::prelude::{StakeCredential, StakeCredentialColumn, Transaction, TransactionColumn}; | ||
use entity::stake_delegation::*; | ||
use sea_schema::migration::prelude::*; | ||
|
||
pub struct Migration; | ||
|
||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m20230927_000016_create_stake_delegation_table" | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(Entity) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(Column::Id) | ||
.big_integer() | ||
.not_null() | ||
.auto_increment(), | ||
) | ||
.col( | ||
ColumnDef::new(Column::StakeCredential) | ||
.big_integer() | ||
.not_null(), | ||
) | ||
.col(ColumnDef::new(Column::TxId).big_integer().not_null()) | ||
.col(ColumnDef::new(Column::PoolCredential).binary()) | ||
.col(ColumnDef::new(Column::PreviousPool).binary()) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-stake_delegation-credential_id") | ||
.from(Entity, Column::StakeCredential) | ||
.to(StakeCredential, StakeCredentialColumn::Id) | ||
.on_delete(ForeignKeyAction::Cascade), | ||
) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-stake_delegation-tx_id") | ||
.from(Entity, Column::TxId) | ||
.to(Transaction, TransactionColumn::Id) | ||
.on_delete(ForeignKeyAction::Cascade), | ||
) | ||
.primary_key( | ||
Index::create() | ||
.table(Entity) | ||
.name("stake_delegation_credential-pk") | ||
.col(Column::Id), | ||
) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
Index::create() | ||
.table(Entity) | ||
.name("index-stake_delegation_credential-stake_credential") | ||
.col(Column::StakeCredential) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(Entity).to_owned()) | ||
.await | ||
} | ||
} |
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.