Skip to content

Commit

Permalink
conway governance tasks (#181)
Browse files Browse the repository at this point in the history
* drep tasks and sancho support

* drep delegation for adddress and votes for address endpoints

* use a credential instead of bech32 address

* votes for action ids endpoint

* voting task: avoid insert when empty

* all votes endpoint: rename and fix doc

* add transaction history drep filters

* update cml (to non merged branch)

* fix route name inconsistencies and wrong tx id format

* fix VoteDelegCert credential format

* multiera address task: implement the combined certificates

* multiera address delegation: add new certificates

* multiera_drep_delegation add combined certs

* multiera address: clippy

* cardano sink: handle conway era

* cardano net setting: handle sancho

* fix multiera_drep_delegation not using drep credential

* Bump to cml 5.3.0

---------

Co-authored-by: Sebastien Guillemot <sebastiengllmt@gmail.com>
  • Loading branch information
ecioppettini and SebastienGllmt authored May 2, 2024
1 parent 75cb89b commit c3c94fd
Show file tree
Hide file tree
Showing 54 changed files with 1,433 additions and 140 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ members = [
"indexer/plan-visualizer",
"indexer/task-docgen"
]


[workspace.dependencies]
cml-chain = { version = "5.3.0" }
cml-core = { version = "5.3.0" }
cml-crypto = { version = "5.3.0" }
cml-multi-era = { version = "5.3.0" }
8 changes: 4 additions & 4 deletions indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ tasks = { path = "tasks" }
# [indexer]
anyhow = { version = "1.0.69" }
async-trait = { version = "0.1.64" }
cml-chain = { version = "5.2.0" }
cml-core = { version = "5.2.0" }
cml-crypto = { version = "5.2.0" }
cml-multi-era = { version = "5.2.0" }
cml-chain = { workspace = true }
cml-core = { workspace = true }
cml-crypto = { workspace = true }
cml-multi-era = { workspace = true }
clap = { version = "3.1", features = ["derive"] }
ctrlc = { version = "3.2.4", features = ["termination"] }
dotenv = { version = "0.15.0" }
Expand Down
25 changes: 25 additions & 0 deletions indexer/entity/src/governance_votes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "GovernanceVote")]
pub struct Model {
#[sea_orm(primary_key, column_type = "BigInteger")]
pub id: i64,
pub tx_id: i64,
pub voter: Vec<u8>,
pub gov_action_id: Vec<u8>,
pub vote: Vec<u8>,
}

#[derive(Copy, Clone, Debug, DeriveRelation, EnumIter)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::transaction::Entity",
from = "Column::TxId",
to = "super::transaction::Column::Id"
)]
Transaction,
}

impl ActiveModelBehavior for ActiveModel {}
3 changes: 3 additions & 0 deletions indexer/entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ pub mod asset_mint;
pub mod asset_utxos;
pub mod cip25_entry;
pub mod dex_swap;
pub mod governance_votes;
pub mod native_asset;
pub mod plutus_data;
pub mod plutus_data_hash;
pub mod projected_nft;
// todo: rename to pool?
pub mod stake_delegation;
pub mod stake_delegation_drep;
pub mod transaction_metadata;
5 changes: 5 additions & 0 deletions indexer/entity/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ pub use super::dex_swap::{
ActiveModel as DexSwapActiveModel, Column as DexSwapColumn, Entity as DexSwap,
Model as DexSwapModel, PrimaryKey as DexSwapPrimaryKey, Relation as DexSwapRelation,
};
pub use super::governance_votes::{
ActiveModel as GovernanceVoteActiveModel, Column as GovernanceVoteColumn,
Entity as GovernanceVote, Model as GovernanceVoteModel, PrimaryKey as GovernanceVotePrimaryKey,
Relation as GovernanceVoteRelation,
};
pub use super::native_asset::{
ActiveModel as NativeAssetActiveModel, Column as NativeAssetColumn, Entity as NativeAsset,
Model as NativeAssetModel, PrimaryKey as NativeAssetPrimaryKey,
Expand Down
37 changes: 37 additions & 0 deletions indexer/entity/src/stake_delegation_drep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "StakeDelegationDrepCredentialRelation")]
pub struct Model {
#[sea_orm(primary_key, column_type = "BigInteger")]
pub id: i64,
pub stake_credential: i64,
pub drep_credential: Option<Vec<u8>>,
pub tx_id: i64,
pub previous_drep_credential: 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 {}
62 changes: 62 additions & 0 deletions indexer/genesis/sanchonet-byron-genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"avvmDistr": {},
"blockVersionData": {
"heavyDelThd": "300000000000",
"maxBlockSize": "2000000",
"maxHeaderSize": "2000000",
"maxProposalSize": "700",
"maxTxSize": "4096",
"mpcThd": "20000000000000",
"scriptVersion": 0,
"slotDuration": "20000",
"softforkRule": {
"initThd": "900000000000000",
"minThd": "600000000000000",
"thdDecrement": "50000000000000"
},
"txFeePolicy": {
"multiplier": "43946000000",
"summand": "155381000000000"
},
"unlockStakeEpoch": "18446744073709551615",
"updateImplicit": "10000",
"updateProposalThd": "100000000000000",
"updateVoteThd": "1000000000000"
},
"bootStakeholders": {
"318488dc356f6034104804b2cb6a2dcc055202491386fb0d5af7c3ba": 1,
"3a3c2ffaf066c8f211a1bdfd844f767ac453b1d94915e725c5867467": 1,
"3ae8eabb4e0626cea0ba38d8303d59514dae9c307d93bad3d259e4a9": 1
},
"heavyDelegation": {
"318488dc356f6034104804b2cb6a2dcc055202491386fb0d5af7c3ba": {
"cert": "b80e06679023284236df3464dc6aab3f56f23cb721d5943c59632ac77004f76ae415b6d291606c7194509e1fefa0c8341eed269bd0e0e1433302b00912a4230c",
"delegatePk": "9ELoyHN4GVtXrFzAJZApAVjrhwftqEFVoDXl9ebtTwpe/lG4b5ZkgH3DqwHE1hNJFRsnYs4zYzMmdbnoR7lfUA==",
"issuerPk": "MHFL9SqIV6KuXSAvp08jHBRtHwNsDJMsCxbmXLorSbfLAORg7waqVL8NEaKU3Lb0FBIX5sHVC21i1M/c0jrnlA==",
"omega": 0
},
"3a3c2ffaf066c8f211a1bdfd844f767ac453b1d94915e725c5867467": {
"cert": "ce91b8e35b67de2236fa79b353d1c4ebd97ad4b4cc89056a1acfc217ece8e91fbffc4bf44604a96a1064c9997f6cd39b81284aadfac752056eafc6b5996a6509",
"delegatePk": "Grpf6iTqd9aWc3QWvfthNv2l8Pp0X2tKpoIoPn0+Dy1+ow60UTu9i1j4KPjp1uzrnM4JoUcmkCGF507fPagO8w==",
"issuerPk": "1FPA7qSOPVDlNZoQAuoB2dnm+tKI5td6+BO5sJ2rswVxuS6S6sjBFVfVz/VXfKTcEt/AKyffgzWXAtPCnhC1jw==",
"omega": 0
},
"3ae8eabb4e0626cea0ba38d8303d59514dae9c307d93bad3d259e4a9": {
"cert": "908dd25262598050d60cb24928a7059fea3726a1dd7764645edab654d3b4e37ba69acd4841454f70f0f643305ede0ef66dc0ea9747a2387da05d2af77963f30a",
"delegatePk": "1zYduiReianx6HJHgQqtira7XY6M/Ol4tFj/O7TzTLcNfgazJm8pq5y6HAANwl91iL1pDZuIgFjzI+2i1Z6y2Q==",
"issuerPk": "Pgj3IyTJDyxr+t5fcMuM3aPtyNCxOo4T9sr78BNbgWBGwlTGo0P6UtzNLyqloLsH8V6Lv6kYMdWELAiEyfCpkw==",
"omega": 0
}
},
"nonAvvmBalances": {
"FHnt4NL7yPXqn7xha3WB99wYLxAc1FhceD3D1pQWaCthk9RYB46aGb6Tbq2KxV5": "0",
"FHnt4NL7yPXwj8m191s48v1RZtQqA2sVHpamzStuXTuAnzYUSR6hRPqhYmW3MY4": "0",
"FHnt4NL7yPXzVZ5xexcb7rWqCYWuFU7y6Pp4tLTiv6txhDcpQ2m7AFGMirsi1F1": "30000000000000000",
"FHnt4NL7yPY27r794z4UiYJ3RwezucDRLX94Pzy6mYPNUNWboB71S9xUm2WEDrv": "0"
},
"protocolConsts": {
"k": 432,
"protocolMagic": 4
},
"startTime": 1686789000
}
4 changes: 4 additions & 0 deletions indexer/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod m20230927_000016_create_stake_delegation_table;
mod m20231025_000017_projected_nft;
mod m20231220_000018_asset_utxo_table;
mod m20240229_000019_add_block_tx_count_column;
mod m20240326_000020_create_drep_delegation_table;
mod m20240326_000021_create_governance_voting_table;

pub struct Migrator;

Expand Down Expand Up @@ -49,6 +51,8 @@ impl MigratorTrait for Migrator {
Box::new(m20231025_000017_projected_nft::Migration),
Box::new(m20231220_000018_asset_utxo_table::Migration),
Box::new(m20240229_000019_add_block_tx_count_column::Migration),
Box::new(m20240326_000020_create_drep_delegation_table::Migration),
Box::new(m20240326_000021_create_governance_voting_table::Migration),
]
}
}
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_drep::*;
use sea_schema::migration::prelude::*;

pub struct Migration;

impl MigrationName for Migration {
fn name(&self) -> &str {
"m20240326_000020_create_drep_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::DrepCredential).binary())
.col(ColumnDef::new(Column::PreviousDrepCredential).binary())
.foreign_key(
ForeignKey::create()
.name("fk-stake_delegation_drep-credential_id")
.from(Entity, Column::StakeCredential)
.to(StakeCredential, StakeCredentialColumn::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKey::create()
.name("fk-stake_delegation_drep-tx_id")
.from(Entity, Column::TxId)
.to(Transaction, TransactionColumn::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.primary_key(
Index::create()
.table(Entity)
.name("stake_delegation_drep_credential-pk")
.col(Column::Id),
)
.to_owned(),
)
.await?;

manager
.create_index(
Index::create()
.table(Entity)
.name("index-stake_delegation_credential_drep-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
}
}
Loading

0 comments on commit c3c94fd

Please sign in to comment.