Skip to content

Commit

Permalink
token account saving
Browse files Browse the repository at this point in the history
  • Loading branch information
austbot committed Sep 30, 2022
1 parent 6aa33ee commit ca38b3d
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 80 deletions.
13 changes: 13 additions & 0 deletions digital_asset_types/src/dao/generated/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl EntityName for Entity {
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Serialize, Deserialize)]
pub struct Model {
pub id: Vec<u8>,
pub alt_id: Option<Vec<u8>>,
pub specification_version: SpecificationVersions,
pub specification_asset_class: SpecificationAssetClass,
pub owner: Option<Vec<u8>>,
Expand All @@ -45,6 +46,7 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
AltId,
SpecificationVersion,
SpecificationAssetClass,
Owner,
Expand Down Expand Up @@ -83,6 +85,7 @@ impl PrimaryKeyTrait for PrimaryKey {
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
AssetData,
AssetV1AccountAttachments,
AssetGrouping,
AssetAuthority,
AssetCreators,
Expand All @@ -93,6 +96,7 @@ impl ColumnTrait for Column {
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Binary.def(),
Self::AltId => ColumnType::Binary.def().null(),
Self::SpecificationVersion => SpecificationVersions::db_type(),
Self::SpecificationAssetClass => SpecificationAssetClass::db_type(),
Self::Owner => ColumnType::Binary.def().null(),
Expand Down Expand Up @@ -125,6 +129,9 @@ impl RelationTrait for Relation {
.from(Column::AssetData)
.to(super::asset_data::Column::Id)
.into(),
Self::AssetV1AccountAttachments => {
Entity::has_many(super::asset_v1_account_attachments::Entity).into()
}
Self::AssetGrouping => Entity::has_many(super::asset_grouping::Entity).into(),
Self::AssetAuthority => Entity::has_many(super::asset_authority::Entity).into(),
Self::AssetCreators => Entity::has_many(super::asset_creators::Entity).into(),
Expand All @@ -138,6 +145,12 @@ impl Related<super::asset_data::Entity> for Entity {
}
}

impl Related<super::asset_v1_account_attachments::Entity> for Entity {
fn to() -> RelationDef {
Relation::AssetV1AccountAttachments.def()
}
}

impl Related<super::asset_grouping::Entity> for Entity {
fn to() -> RelationDef {
Relation::AssetGrouping.def()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ impl EntityName for Entity {
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Serialize, Deserialize)]
pub struct Model {
pub id: Vec<u8>,
pub asset_id: Option<Vec<u8>>,
pub attachment_type: V1AccountAttachments,
pub initialized: bool,
pub data: Option<Vec<u8>>,
pub data: Option<Json>,
pub slot_updated: i64,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
AssetId,
AttachmentType,
Initialized,
Data,
Expand All @@ -44,24 +46,38 @@ impl PrimaryKeyTrait for PrimaryKey {
}

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

impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Binary.def(),
Self::AssetId => ColumnType::Binary.def().null(),
Self::AttachmentType => V1AccountAttachments::db_type(),
Self::Initialized => ColumnType::Boolean.def(),
Self::Data => ColumnType::Binary.def().null(),
Self::Data => ColumnType::JsonBinary.def().null(),
Self::SlotUpdated => ColumnType::BigInteger.def(),
}
}
}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
match self {
Self::Asset => Entity::belongs_to(super::asset::Entity)
.from(Column::AssetId)
.to(super::asset::Column::Id)
.into(),
}
}
}

impl Related<super::asset::Entity> for Entity {
fn to() -> RelationDef {
Relation::Asset.def()
}
}

Expand Down
112 changes: 56 additions & 56 deletions digital_asset_types/src/dao/generated/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "mutability")]
pub enum Mutability {
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "chain_mutability")]
pub enum ChainMutability {
#[sea_orm(string_value = "immutable")]
Immutable,
#[sea_orm(string_value = "mutable")]
Expand All @@ -17,43 +17,61 @@ pub enum Mutability {
#[sea_orm(
rs_type = "String",
db_type = "Enum",
enum_name = "royalty_target_type"
enum_name = "specification_asset_class"
)]
pub enum RoyaltyTargetType {
#[sea_orm(string_value = "creators")]
Creators,
#[sea_orm(string_value = "fanout")]
Fanout,
pub enum SpecificationAssetClass {
#[sea_orm(string_value = "FUNGIBLE_ASSET")]
FungibleAsset,
#[sea_orm(string_value = "FUNGIBLE_TOKEN")]
FungibleToken,
#[sea_orm(string_value = "IDENTITY_NFT")]
IdentityNft,
#[sea_orm(string_value = "NFT")]
Nft,
#[sea_orm(string_value = "NON_TRANSFERABLE_NFT")]
NonTransferableNft,
#[sea_orm(string_value = "PRINT")]
Print,
#[sea_orm(string_value = "PRINTABLE_NFT")]
PrintableNft,
#[sea_orm(string_value = "TRANSFER_RESTRICTED_NFT")]
TransferRestrictedNft,
#[sea_orm(string_value = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "mutability")]
pub enum Mutability {
#[sea_orm(string_value = "immutable")]
Immutable,
#[sea_orm(string_value = "mutable")]
Mutable,
#[sea_orm(string_value = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "owner_type")]
pub enum OwnerType {
#[sea_orm(string_value = "single")]
Single,
#[sea_orm(string_value = "token")]
Token,
#[sea_orm(string_value = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(
rs_type = "String",
db_type = "Enum",
enum_name = "v1_account_attachments"
enum_name = "royalty_target_type"
)]
pub enum V1AccountAttachments {
#[sea_orm(string_value = "edition")]
Edition,
#[sea_orm(string_value = "edition_marker")]
EditionMarker,
#[sea_orm(string_value = "master_edition_v1")]
MasterEditionV1,
#[sea_orm(string_value = "master_edition_v2")]
MasterEditionV2,
#[sea_orm(string_value = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "chain_mutability")]
pub enum ChainMutability {
#[sea_orm(string_value = "immutable")]
Immutable,
#[sea_orm(string_value = "mutable")]
Mutable,
pub enum RoyaltyTargetType {
#[sea_orm(string_value = "creators")]
Creators,
#[sea_orm(string_value = "fanout")]
Fanout,
#[sea_orm(string_value = "single")]
Single,
#[sea_orm(string_value = "unknown")]
Unknown,
}
Expand All @@ -77,35 +95,17 @@ pub enum SpecificationVersions {
#[sea_orm(
rs_type = "String",
db_type = "Enum",
enum_name = "specification_asset_class"
enum_name = "v1_account_attachments"
)]
pub enum SpecificationAssetClass {
#[sea_orm(string_value = "FUNGIBLE_ASSET")]
FungibleAsset,
#[sea_orm(string_value = "FUNGIBLE_TOKEN")]
FungibleToken,
#[sea_orm(string_value = "IDENTITY_NFT")]
IdentityNft,
#[sea_orm(string_value = "NFT")]
Nft,
#[sea_orm(string_value = "NON_TRANSFERABLE_NFT")]
NonTransferableNft,
#[sea_orm(string_value = "PRINT")]
Print,
#[sea_orm(string_value = "PRINTABLE_NFT")]
PrintableNft,
#[sea_orm(string_value = "TRANSFER_RESTRICTED_NFT")]
TransferRestrictedNft,
#[sea_orm(string_value = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "owner_type")]
pub enum OwnerType {
#[sea_orm(string_value = "single")]
Single,
#[sea_orm(string_value = "token")]
Token,
pub enum V1AccountAttachments {
#[sea_orm(string_value = "edition")]
Edition,
#[sea_orm(string_value = "edition_marker")]
EditionMarker,
#[sea_orm(string_value = "master_edition_v1")]
MasterEditionV1,
#[sea_orm(string_value = "master_edition_v2")]
MasterEditionV2,
#[sea_orm(string_value = "unknown")]
Unknown,
}
3 changes: 3 additions & 0 deletions digital_asset_types/src/dao/generated/token_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Model {
pub delegate: Option<Vec<u8>>,
pub delegated_amount: i64,
pub slot_updated: i64,
pub token_program: Vec<u8>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
Expand All @@ -36,6 +37,7 @@ pub enum Column {
Delegate,
DelegatedAmount,
SlotUpdated,
TokenProgram,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
Expand Down Expand Up @@ -68,6 +70,7 @@ impl ColumnTrait for Column {
Self::Delegate => ColumnType::Binary.def().null(),
Self::DelegatedAmount => ColumnType::BigInteger.def(),
Self::SlotUpdated => ColumnType::BigInteger.def(),
Self::TokenProgram => ColumnType::Binary.def(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion digital_asset_types/src/dapi/listed_assets_by_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub async fn get_listed_assets_by_owner(
.filter(
Condition::all()
.add(asset::Column::Owner.eq(owner_address.clone()))
.add(asset::Column::Delegate.is_not_null()),
.add(
asset::Column::Delegate.is_not_null()),
)
.find_also_related(AssetData)
// .order_by_asc(sort_column)
Expand Down
17 changes: 13 additions & 4 deletions init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ create table tokens
extension_data bytea,
slot_updated bigint not null
);

create index t_mint_auth on tokens (mint_authority);
create index t_freeze_auth on tokens (freeze_authority);
create index t_close_auth on tokens (close_authority);
create index t_slot_updated_idx on tokens USING BTREE (slot_updated);
create index t_supply on tokens USING BTREE (supply);
create index t_decimals on tokens USING BTREE (decimals);

create table token_accounts
(
Expand All @@ -100,9 +105,13 @@ create table token_accounts
close_authority bytea,
delegate bytea,
delegated_amount bigint not null default 0,
slot_updated bigint not null
slot_updated bigint not null,
token_program bytea not null
);

create index ta_delegate on token_accounts (delegate);
create index ta_slot_updated_idx on token_accounts USING BTREE (slot_updated);
create index ta_amount on token_accounts USING BTREE (amount);
create index ta_amount_del on token_accounts USING BTREE (delegated_amount);

create table asset_data
(
Expand Down Expand Up @@ -170,7 +179,7 @@ create table asset_v1_account_attachments
asset_id bytea references asset (id),
attachment_type v1_account_attachments not null,
initialized bool not null default false,
data bytea,
data jsonb,
slot_updated bigint not null
);

Expand Down
10 changes: 10 additions & 0 deletions nft_ingester/src/program_transformers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ use tokio::sync::mpsc::UnboundedSender;
use crate::program_transformers::{
bubblegum::handle_bubblegum_instruction, token_metadata::handle_token_metadata_account,
};
use crate::program_transformers::token::handle_token_program_account;

mod bubblegum;
mod common;
mod token_metadata;
mod token;

pub struct ProgramTransformer {
storage: DatabaseConnection,
Expand Down Expand Up @@ -85,6 +87,14 @@ impl ProgramTransformer {
)
.await
}
ProgramParseResult::TokenProgramAccount(parsing_result) => {
handle_token_program_account(
&acct,
parsing_result,
&self.storage,
&self.task_sender,
).await
}
_ => Err(IngesterError::NotImplemented),
}?;
}
Expand Down
Loading

0 comments on commit ca38b3d

Please sign in to comment.