-
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.
- Loading branch information
1 parent
8378f15
commit ab58a2f
Showing
17 changed files
with
726 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)] | ||
#[sea_orm(table_name = "AssetUtxo")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, column_type = "BigInteger")] | ||
pub id: i64, | ||
#[sea_orm(column_type = "BigInteger")] | ||
pub asset_id: i64, | ||
#[sea_orm(column_type = "BigInteger")] | ||
pub utxo_id: i64, | ||
pub amount: Option<i64>, | ||
pub tx_id: i64, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::transaction_output::Entity", | ||
from = "Column::UtxoId", | ||
to = "super::transaction_output::Column::Id" | ||
)] | ||
TransactionOutput, | ||
|
||
#[sea_orm( | ||
belongs_to = "super::native_asset::Entity", | ||
from = "Column::AssetId", | ||
to = "super::native_asset::Column::Id" | ||
)] | ||
Asset, | ||
|
||
#[sea_orm( | ||
belongs_to = "super::transaction::Entity", | ||
from = "Column::TxId", | ||
to = "super::transaction::Column::Id" | ||
)] | ||
Transaction, | ||
} | ||
|
||
impl Related<super::transaction_output::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::TransactionOutput.def() | ||
} | ||
} | ||
|
||
impl Related<super::native_asset::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Asset.def() | ||
} | ||
} | ||
|
||
impl Related<super::transaction::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Transaction.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
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 |
---|---|---|
|
@@ -65,3 +65,5 @@ readonly=false | |
[MultieraCip25EntryTask] | ||
|
||
[MultieraAddressDelegationTask] | ||
|
||
[MultieraAssetUtxos] |
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
80 changes: 80 additions & 0 deletions
80
indexer/migration/src/m20231220_000018_asset_utxo_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,80 @@ | ||
use entity::{asset_utxos::*, prelude}; | ||
use sea_schema::migration::prelude::*; | ||
|
||
pub struct Migration; | ||
|
||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m20231220_000018_asset_utxos.rs" | ||
} | ||
} | ||
|
||
#[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::AssetId).big_integer().not_null()) | ||
.col(ColumnDef::new(Column::UtxoId).big_integer().not_null()) | ||
.col(ColumnDef::new(Column::TxId).big_integer().not_null()) | ||
.col(ColumnDef::new(Column::Amount).big_integer()) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-asset_utxo-asset_id") | ||
.from(Entity, Column::AssetId) | ||
.to(prelude::NativeAsset, prelude::NativeAssetColumn::Id) | ||
.on_delete(ForeignKeyAction::Cascade), | ||
) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-asset_utxo-tx_id") | ||
.from(Entity, Column::TxId) | ||
.to(prelude::Transaction, prelude::TransactionColumn::Id) | ||
.on_delete(ForeignKeyAction::Cascade), | ||
) | ||
.foreign_key( | ||
ForeignKey::create() | ||
.name("fk-asset_utxo-utxo_id") | ||
.from(Entity, Column::UtxoId) | ||
.to( | ||
prelude::TransactionOutput, | ||
prelude::TransactionOutputColumn::Id, | ||
) | ||
.on_delete(ForeignKeyAction::Cascade), | ||
) | ||
.primary_key( | ||
Index::create() | ||
.table(Entity) | ||
.name("asset_utxo-pk") | ||
.col(Column::Id), | ||
) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
Index::create() | ||
.table(Entity) | ||
.name("index-asset_utxo-transaction") | ||
.col(Column::TxId) | ||
.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.