Skip to content

Commit

Permalink
feat(backfiller): add cl_audit_v2 to ingestion for recording every se…
Browse files Browse the repository at this point in the history
…q for a tree
  • Loading branch information
kespinola committed Dec 22, 2023
1 parent f36193f commit 61b436b
Show file tree
Hide file tree
Showing 26 changed files with 420 additions and 156 deletions.
16 changes: 11 additions & 5 deletions das_api/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ impl RpcApiBuilder {
rpc_context.search_assets(payload).await.map_err(Into::into)
})?;
module.register_alias("searchAssets", "search_assets")?;

module.register_async_method("get_signatures_for_asset", |rpc_params, rpc_context| async move {
let payload = rpc_params.parse::<GetSignaturesForAsset>()?;
rpc_context.get_signatures_for_asset(payload).await.map_err(Into::into)
})?;

module.register_async_method(
"get_signatures_for_asset",
|rpc_params, rpc_context| async move {
let payload = rpc_params.parse::<GetSignaturesForAsset>()?;
rpc_context
.get_signatures_for_asset(payload)
.await
.map_err(Into::into)
},
)?;
module.register_alias("getSignaturesForAsset", "get_signatures_for_asset")?;

module.register_async_method("schema", |_, rpc_context| async move {
Expand Down
74 changes: 74 additions & 0 deletions digital_asset_types/src/dao/generated/cl_audits_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.5
use super::sea_orm_active_enums::BubblegumInstruction;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;

impl EntityName for Entity {
fn table_name(&self) -> &str {
"cl_audits_v2"
}
}

#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq, Serialize, Deserialize)]
pub struct Model {
pub id: i64,
pub tree: Vec<u8>,
pub leaf_idx: i64,
pub seq: i64,
pub created_at: DateTime,
pub tx: Vec<u8>,
pub instruction: BubblegumInstruction,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
Tree,
LeafIdx,
Seq,
CreatedAt,
Tx,
Instruction,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}

impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i64;
fn auto_increment() -> bool {
true
}
}

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}

impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::BigInteger.def(),
Self::Tree => ColumnType::Binary.def(),
Self::LeafIdx => ColumnType::BigInteger.def(),
Self::Seq => ColumnType::BigInteger.def(),
Self::CreatedAt => ColumnType::DateTime.def(),
Self::Tx => ColumnType::Binary.def(),
Self::Instruction => BubblegumInstruction::db_type(),
}
}
}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl ActiveModelBehavior for ActiveModel {}
2 changes: 1 addition & 1 deletion digital_asset_types/src/dao/generated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub mod asset_grouping;
pub mod asset_v1_account_attachments;
pub mod backfill_items;
pub mod cl_audits;
pub mod cl_audits_v2;
pub mod cl_items;
pub mod raw_txn;
pub mod sea_orm_active_enums;
pub mod tasks;
pub mod token_accounts;
pub mod tokens;
pub mod tree_transactions;
2 changes: 1 addition & 1 deletion digital_asset_types/src/dao/generated/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub use super::asset_grouping::Entity as AssetGrouping;
pub use super::asset_v1_account_attachments::Entity as AssetV1AccountAttachments;
pub use super::backfill_items::Entity as BackfillItems;
pub use super::cl_audits::Entity as ClAudits;
pub use super::cl_audits_v2::Entity as ClAuditsV2;
pub use super::cl_items::Entity as ClItems;
pub use super::raw_txn::Entity as RawTxn;
pub use super::tasks::Entity as Tasks;
pub use super::token_accounts::Entity as TokenAccounts;
pub use super::tokens::Entity as Tokens;
pub use super::tree_transactions::Entity as TreeTransactions;
71 changes: 71 additions & 0 deletions digital_asset_types/src/dao/generated/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,74 @@ pub enum OwnerType {
#[sea_orm(string_value = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(
rs_type = "String",
db_type = "Enum",
enum_name = "bubblegum_instruction"
)]
pub enum BubblegumInstruction {
#[sea_orm(string_value = "bubblegum_instruction")]
BubblegumInstruction,
#[sea_orm(string_value = "burn")]
Burn,
#[sea_orm(string_value = "cancel_redeem")]
CancelRedeem,
#[sea_orm(string_value = "compress")]
Compress,
#[sea_orm(string_value = "decompress_v1")]
DecompressV1,
#[sea_orm(string_value = "delegate")]
Delegate,
#[sea_orm(string_value = "mint_to_collection_v1")]
MintToCollectionV1,
#[sea_orm(string_value = "mint_v1")]
MintV1,
#[sea_orm(string_value = "redeem")]
Redeem,
#[sea_orm(string_value = "set_and_verify_collection")]
SetAndVerifyCollection,
#[sea_orm(string_value = "transfer")]
Transfer,
#[sea_orm(string_value = "unknown")]
Unknown,
#[sea_orm(string_value = "unverify_collection")]
UnverifyCollection,
#[sea_orm(string_value = "unverify_creator")]
UnverifyCreator,
#[sea_orm(string_value = "verify_collection")]
VerifyCollection,
#[sea_orm(string_value = "verify_creator")]
VerifyCreator,
#[sea_orm(string_value = "create_tree")]
CreateTree,
}

impl std::str::FromStr for BubblegumInstruction {
type Err = sea_orm::DbErr;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"MintV1" => Ok(BubblegumInstruction::MintV1),
"MintToCollectionV1" => Ok(BubblegumInstruction::MintToCollectionV1),
"Redeem" => Ok(BubblegumInstruction::Redeem),
"CancelRedeem" => Ok(BubblegumInstruction::CancelRedeem),
"Transfer" => Ok(BubblegumInstruction::Transfer),
"Delegate" => Ok(BubblegumInstruction::Delegate),
"DecompressV1" => Ok(BubblegumInstruction::DecompressV1),
"Compress" => Ok(BubblegumInstruction::Compress),
"Burn" => Ok(BubblegumInstruction::Burn),
"CreateTree" => Ok(BubblegumInstruction::CreateTree),
"VerifyCreator" => Ok(BubblegumInstruction::VerifyCreator),
"UnverifyCreator" => Ok(BubblegumInstruction::UnverifyCreator),
"VerifyCollection" => Ok(BubblegumInstruction::VerifyCollection),
"UnverifyCollection" => Ok(BubblegumInstruction::UnverifyCollection),
"SetAndVerifyCollection" => Ok(BubblegumInstruction::SetAndVerifyCollection),
"Unknown" => Ok(BubblegumInstruction::Unknown),
_ => Err(sea_orm::DbErr::Custom(format!(
"Invalid value for BubblegumInstruction: {}",
s
))),
}
}
}
6 changes: 4 additions & 2 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ mod m20230720_120101_add_asset_grouping_verified;
mod m20230720_130101_remove_asset_grouping_null_constraints;
mod m20230724_120101_add_group_info_seq;
mod m20230726_013107_remove_not_null_constraint_from_group_value;
mod m20230908_160822_add_cl_audits_v2;
mod m20230918_182123_add_raw_name_symbol;
mod m20230919_072154_cl_audits;
mod m20231101_120101_add_instruction_into_cl_audit;
mod m20231101_120101_cl_audit_table_index;
mod m20231208_103949_create_tree_transactions_table;
mod m20231222_110618_add_indices_to_cl_audits_v2;

pub struct Migrator;

Expand Down Expand Up @@ -68,11 +69,12 @@ impl MigratorTrait for Migrator {
Box::new(m20230720_130101_remove_asset_grouping_null_constraints::Migration),
Box::new(m20230724_120101_add_group_info_seq::Migration),
Box::new(m20230726_013107_remove_not_null_constraint_from_group_value::Migration),
Box::new(m20230908_160822_add_cl_audits_v2::Migration),
Box::new(m20230918_182123_add_raw_name_symbol::Migration),
Box::new(m20230919_072154_cl_audits::Migration),
Box::new(m20231101_120101_add_instruction_into_cl_audit::Migration),
Box::new(m20231101_120101_cl_audit_table_index::Migration),
Box::new(m20231208_103949_create_tree_transactions_table::Migration),
Box::new(m20231222_110618_add_indices_to_cl_audits_v2::Migration),
]
}
}
111 changes: 111 additions & 0 deletions migration/src/m20230908_160822_add_cl_audits_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use enum_iterator::{all, Sequence};
use sea_orm_migration::prelude::{sea_query::extension::postgres::Type, *};
use sea_orm_migration::sea_orm::{ConnectionTrait, DatabaseBackend, Statement};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let conn = manager.get_connection();

manager
.create_type(
Type::create()
.as_enum(BubblegumInstruction::Table)
.values(all::<BubblegumInstruction>().map(|e| e).collect::<Vec<_>>())
.to_owned(),
)
.await?;

manager
.create_table(
Table::create()
.table(ClAuditsV2::Table)
.if_not_exists()
.col(
ColumnDef::new(ClAuditsV2::Id)
.big_integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(ClAuditsV2::Tree).binary().not_null())
.col(ColumnDef::new(ClAuditsV2::LeafIdx).big_integer().not_null())
.col(ColumnDef::new(ClAuditsV2::Seq).big_integer().not_null())
.col(
ColumnDef::new(ClAuditsV2::CreatedAt)
.date_time()
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
.not_null(),
)
.col(ColumnDef::new(ClAuditsV2::Tx).binary().not_null())
.col(
ColumnDef::new(ClAuditsV2::Instruction)
.custom(BubblegumInstruction::Table)
.not_null()
)
.to_owned(),
)
.await?;

conn.execute(Statement::from_string(
DatabaseBackend::Postgres,
"ALTER TABLE cl_audits_v2 ADD CONSTRAINT unique_tree_leafidx_seq UNIQUE (tree, leaf_idx, seq);".to_string(),
))
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_type(
Type::drop()
.if_exists()
.name(BubblegumInstruction::Table)
.to_owned(),
)
.await?;

manager
.drop_table(Table::drop().table(ClAuditsV2::Table).to_owned())
.await?;
Ok(())
}
}

/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum ClAuditsV2 {
Table,
Id,
Tree,
LeafIdx,
Seq,
CreatedAt,
Tx,
Instruction,
}

#[derive(Iden, Debug, PartialEq, Sequence)]
enum BubblegumInstruction {
Table,
Unknown,
MintV1,
Redeem,
CancelRedeem,
Transfer,
Delegate,
DecompressV1,
Compress,
Burn,
VerifyCreator,
UnverifyCreator,
VerifyCollection,
UnverifyCollection,
SetAndVerifyCollection,
MintToCollectionV1,
CreateTree,
}
62 changes: 0 additions & 62 deletions migration/src/m20231208_103949_create_tree_transactions_table.rs

This file was deleted.

Loading

0 comments on commit 61b436b

Please sign in to comment.