-
Notifications
You must be signed in to change notification settings - Fork 22
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
add task that tracks stake delegation #157
Changes from 7 commits
e276231
9d1dda3
d09923b
df472ed
50b497f
d7a1078
b9ad7ab
21785b0
02f0174
dc5338b
d474564
ac1aa29
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,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, | ||
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. here as well |
||
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 {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,5 @@ readonly=false | |
readonly=false | ||
|
||
[MultieraCip25EntryTask] | ||
|
||
[MultieraAddressDelegationTask] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ mod m20220528_000012_create_plutus_data_table; | |
mod m20220808_000013_create_transaction_reference_input_table; | ||
mod m20221031_000014_create_dex_table; | ||
mod m20230223_000015_modify_block_table; | ||
mod m20230927_231206_create_stake_delegation_table; | ||
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. let's probably keep the naming convention (date + number)? 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. good catch, I didn't notice that. The weird thing is that I created this file with sea-orm-cli, so I'm not sure why it's choosing that name |
||
|
||
pub struct Migrator; | ||
|
||
|
@@ -41,6 +42,7 @@ impl MigratorTrait for Migrator { | |
Box::new(m20220808_000013_create_transaction_reference_input_table::Migration), | ||
Box::new(m20221031_000014_create_dex_table::Migration), | ||
Box::new(m20230223_000015_modify_block_table::Migration), | ||
Box::new(m20230927_231206_create_stake_delegation_table::Migration), | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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_231206_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 | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_table(Table::drop().table(Entity).to_owned()) | ||
.await | ||
} | ||
} |
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.
shouldn't we add
#[sea_orm(column_type = "BigInteger")]
?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'm not sure that does anything, to be honest. The columns already have
bigint
type for me, and it's what the docs say should happen I think (https://www.sea-ql.org/SeaORM/docs/next/generate-entity/entity-structure/).But I can add it just in case anyway.