Skip to content

Commit

Permalink
Merge remote-tracking branch 'helius/helius' into espi/token-extensio…
Browse files Browse the repository at this point in the history
…ns-upstream
  • Loading branch information
kespinola committed Mar 27, 2024
2 parents 65baf08 + ad2b4ab commit df72080
Show file tree
Hide file tree
Showing 18 changed files with 880 additions and 174 deletions.
273 changes: 175 additions & 98 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ anyhow = "1.0.75"
async-std = "1.0.0"
async-trait = "0.1.60"
backon = "0.4.1"
blockbuster = "2.0.0"
blockbuster = "2.1.0"
borsh = "~0.10.3"
borsh-derive = "~0.10.3"
bs58 = "0.4.0"
Expand Down Expand Up @@ -99,6 +99,7 @@ spl-associated-token-account = ">= 1.1.3, < 3.0"
spl-concurrent-merkle-tree = "0.2.0"
spl-noop = "0.2.0"
spl-token = ">= 3.5.0, < 5.0"
spl-token-2022 = "1.0"
sqlx = "0.6.2"
stretto = "0.7.2"
thiserror = "1.0.31"
Expand Down
1 change: 1 addition & 0 deletions digital_asset_types/src/dao/extensions/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Default for asset::Model {
owner_delegate_seq: None,
leaf_seq: None,
base_info_seq: None,
mint_extensions: None,
}
}
}
3 changes: 3 additions & 0 deletions digital_asset_types/src/dao/generated/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct Model {
pub owner_delegate_seq: Option<i64>,
pub leaf_seq: Option<i64>,
pub base_info_seq: Option<i64>,
pub mint_extensions: Option<Json>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
Expand Down Expand Up @@ -86,6 +87,7 @@ pub enum Column {
OwnerDelegateSeq,
LeafSeq,
BaseInfoSeq,
MintExtensions,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
Expand Down Expand Up @@ -139,6 +141,7 @@ impl ColumnTrait for Column {
Self::OwnerDelegateSeq => ColumnType::BigInteger.def().null(),
Self::LeafSeq => ColumnType::BigInteger.def().null(),
Self::BaseInfoSeq => ColumnType::BigInteger.def().null(),
Self::MintExtensions => ColumnType::JsonBinary.def().null(),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions digital_asset_types/src/dao/generated/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Model {
pub close_authority: Option<Vec<u8>>,
pub extension_data: Option<Vec<u8>>,
pub slot_updated: i64,
pub extensions: Option<Json>,
}

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

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
Expand Down Expand Up @@ -66,6 +68,7 @@ impl ColumnTrait for Column {
Self::CloseAuthority => ColumnType::Binary.def().null(),
Self::ExtensionData => ColumnType::Binary.def().null(),
Self::SlotUpdated => ColumnType::BigInteger.def(),
Self::Extensions => ColumnType::JsonBinary.def().null(),
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions digital_asset_types/src/dapi/common/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use log::warn;
use mime_guess::Mime;

use sea_orm::DbErr;
use serde_json::Map;
use serde_json::Value;
use std::cmp::Ordering;
use std::collections::HashMap;
Expand Down Expand Up @@ -47,6 +48,30 @@ pub fn file_from_str(str: String) -> File {
}
}

fn filter_non_null_fields(value: Option<&Value>) -> Option<Value> {
match value {
Some(Value::Null) => None,
Some(Value::Object(map)) => {
if map.values().all(|v| matches!(v, Value::Null)) {
None
} else {
let filtered_map: Map<String, Value> = map
.into_iter()
.filter(|(_k, v)| !matches!(v, Value::Null))
.map(|(k, v)| (k.clone(), v.clone()))
.collect();

if filtered_map.is_empty() {
None
} else {
Some(Value::Object(filtered_map))
}
}
}
_ => value.cloned(),
}
}

pub fn build_asset_response(
assets: Vec<FullAsset>,
limit: u64,
Expand Down Expand Up @@ -368,6 +393,8 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result<RpcAsset, DbE
.unwrap_or(false);
let edition_nonce =
safe_select(chain_data_selector, "$.edition_nonce").and_then(|v| v.as_u64());

let mint_ext = filter_non_null_fields(asset.mint_extensions.as_ref());
Ok(RpcAsset {
interface: interface.clone(),
id: bs58::encode(asset.id).into_string(),
Expand Down Expand Up @@ -435,6 +462,7 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result<RpcAsset, DbE
remaining: u.get("remaining").and_then(|t| t.as_u64()).unwrap_or(0),
}),
burnt: asset.burnt,
mint_extensions: mint_ext,
})
}

Expand Down
3 changes: 3 additions & 0 deletions digital_asset_types/src/rpc/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::BTreeMap;

use crate::dao::sea_orm_active_enums::ChainMutability;
use schemars::JsonSchema;
use serde_json::Value;
use {
serde::{Deserialize, Serialize},
std::collections::HashMap,
Expand Down Expand Up @@ -364,4 +365,6 @@ pub struct Asset {
pub supply: Option<Supply>,
pub mutable: bool,
pub burnt: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub mint_extensions: Option<Value>,
}
1 change: 1 addition & 0 deletions digital_asset_types/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn create_asset(
slot_updated_token_account: None,
slot_updated_cnft_transaction: None,
data_hash: None,
mint_extensions: None,
alt_id: None,
creator_hash: None,
owner_delegate_seq: Some(0),
Expand Down
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod m20240116_130744_add_update_metadata_ix;
mod m20240117_120101_alter_creator_indices;
mod m20240124_173104_add_tree_seq_index_to_cl_audits_v2;
mod m20240124_181900_add_slot_updated_column_per_update_type;
mod m20240219_115532_add_extensions_column;

pub mod model;

Expand Down Expand Up @@ -85,6 +86,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240117_120101_alter_creator_indices::Migration),
Box::new(m20240124_173104_add_tree_seq_index_to_cl_audits_v2::Migration),
Box::new(m20240124_181900_add_slot_updated_column_per_update_type::Migration),
Box::new(m20240219_115532_add_extensions_column::Migration),
]
}
}
59 changes: 59 additions & 0 deletions migration/src/m20240219_115532_add_extensions_column.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use sea_orm_migration::{
prelude::*,
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 connection = manager.get_connection();

connection
.execute(Statement::from_string(
DatabaseBackend::Postgres,
"ALTER TABLE asset ADD COLUMN mint_extensions jsonb;".to_string(),
))
.await?;
connection
.execute(Statement::from_string(
DatabaseBackend::Postgres,
"ALTER TABLE tokens ADD COLUMN extensions jsonb;".to_string(),
))
.await?;
connection
.execute(Statement::from_string(
DatabaseBackend::Postgres,
"ALTER TABLE token_accounts ADD COLUMN extensions jsonb;".to_string(),
))
.await?;
Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let connection = manager.get_connection();

connection
.execute(Statement::from_string(
DatabaseBackend::Postgres,
"ALTER TABLE asset DROP COLUMN mint_extensions;".to_string(),
))
.await?;
connection
.execute(Statement::from_string(
DatabaseBackend::Postgres,
"ALTER TABLE tokens DROP COLUMN extensions;".to_string(),
))
.await?;
connection
.execute(Statement::from_string(
DatabaseBackend::Postgres,
"ALTER TABLE token_accounts DROP COLUMN extensions;".to_string(),
))
.await?;

Ok(())
}
}
9 changes: 7 additions & 2 deletions program_transformers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ blockbuster = { workspace = true }
bs58 = { workspace = true }
cadence = { workspace = true }
cadence-macros = { workspace = true }
digital_asset_types = { workspace = true, features = ["json_types", "sql_types"] }
digital_asset_types = { workspace = true, features = [
"json_types",
"sql_types",
] }
futures = { workspace = true }
log = { workspace = true }
mpl-bubblegum = { workspace = true }
num-traits = { workspace = true }
sea-orm = { workspace = true }
serde_json = { workspace = true }
solana-sdk = { workspace = true }
solana-transaction-status = { workspace = true }
spl-account-compression = { workspace = true, features = ["no-entrypoint"] }
spl-token = { workspace = true, features = ["no-entrypoint"] }
spl-token = { wjjorkspace = true, features = ["no-entrypoint"] }
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
sqlx = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["time"] }
Expand Down
16 changes: 15 additions & 1 deletion program_transformers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
bubblegum::handle_bubblegum_instruction,
error::{ProgramTransformerError, ProgramTransformerResult},
token::handle_token_program_account,
token_extensions::handle_token_extensions_program_account,
token_metadata::handle_token_metadata_account,
},
blockbuster::{
Expand All @@ -26,7 +27,9 @@ mod asset_upserts;
mod bubblegum;
pub mod error;
mod token;
mod token_extensions;
mod token_metadata;
mod utils;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccountInfo {
Expand Down Expand Up @@ -227,7 +230,18 @@ impl ProgramTransformer {
)
.await
}
_ => Err(ProgramTransformerError::NotImplemented),
ProgramParseResult::TokenExtensionsProgramAccount(parsing_result) => {
handle_token_extensions_program_account(
account_info,
parsing_result,
&self.storage,
&self.download_metadata_notifier,
)
.await
}
ProgramParseResult::Bubblegum(_)
| ProgramParseResult::MplCore(_)
| ProgramParseResult::Unknown => Err(ProgramTransformerError::NotImplemented),
}?;
}
Ok(())
Expand Down
Loading

0 comments on commit df72080

Please sign in to comment.