Skip to content

Commit

Permalink
Patch137 2 (#111)
Browse files Browse the repository at this point in the history
* apply helius pr#133

* apply helius pr#137

* fix conflicts helius pr#137

---------

Co-authored-by: Kirill Fomichev <[email protected]>
  • Loading branch information
Juanito87 and fanatid authored Nov 27, 2023
1 parent 9933c41 commit 7abbc0e
Show file tree
Hide file tree
Showing 28 changed files with 421 additions and 94 deletions.
40 changes: 38 additions & 2 deletions das_api/src/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use digital_asset_types::{
dapi::{
get_asset, get_asset_batch, get_asset_proof_batch, get_assets_by_authority,
get_assets_by_creator, get_assets_by_group, get_assets_by_owner, get_proof_for_asset,
search_assets,
search_assets, get_signatures_for_asset
},
rpc::{
filter::{AssetSortBy, SearchConditionType},
response::GetGroupingResponse,
OwnershipModel, RoyaltyModel
},
rpc::{OwnershipModel, RoyaltyModel},
rpc::{},
};
use open_rpc_derive::document_rpc;
use sea_orm::{sea_query::ConditionType, ConnectionTrait, DbBackend, Statement};
Expand All @@ -32,6 +33,7 @@ use {
sea_orm::{DatabaseConnection, DbErr, SqlxPostgresConnector},
sqlx::postgres::PgPoolOptions,
};
use digital_asset_types::rpc::response::TransactionSignatureList;

pub struct DasApi {
db_connection: DatabaseConnection,
Expand Down Expand Up @@ -497,4 +499,38 @@ impl ApiContract for DasApi {
group_size: gs.size,
})
}

async fn get_signatures_for_asset(
self: &DasApi,
payload: GetSignaturesForAsset,
) -> Result<TransactionSignatureList, DasApiError> {
let GetSignaturesForAsset {
id,
limit,
page,
before,
after,
tree,
leaf_index,
sort_by,
cursor,
} = payload;

if !((id.is_some() && tree.is_none() && leaf_index.is_none())
|| (id.is_none() && tree.is_some() && leaf_index.is_some()))
{
return Err(DasApiError::ValidationError(
"Must provide either 'id' or both 'tree' and 'leafIndex'".to_string(),
));
}
let id = validate_opt_pubkey(&id)?;
let tree = validate_opt_pubkey(&tree)?;
let sort_by = sort_by.unwrap_or_default();
let page_options =
self.validate_pagination(&limit, &page, &before, &after, &cursor, &Some(&sort_by))?;

get_signatures_for_asset(&self.db_connection, id, tree, leaf_index, sort_by, &page_options)
.await
.map_err(Into::into)
}
}
26 changes: 25 additions & 1 deletion das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::DasApiError;
use async_trait::async_trait;
use digital_asset_types::rpc::display_options::DisplayOptions;
use digital_asset_types::rpc::filter::SearchConditionType;
use digital_asset_types::rpc::response::AssetList;
use digital_asset_types::rpc::response::{AssetList, TransactionSignatureList};
use digital_asset_types::rpc::{filter::AssetSorting, response::GetGroupingResponse};
use digital_asset_types::rpc::{Asset, AssetProof, Interface, OwnershipModel, RoyaltyModel};
use open_rpc_derive::{document_rpc, rpc};
Expand Down Expand Up @@ -147,6 +147,21 @@ pub struct GetGrouping {
pub group_value: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetSignaturesForAsset {
pub id: Option<String>,
pub limit: Option<u32>,
pub page: Option<u32>,
pub before: Option<String>,
pub after: Option<String>,
pub tree: Option<String>,
pub leaf_index: Option<i64>,
pub sort_by: Option<AssetSorting>,
#[serde(default)]
pub cursor: Option<String>,
}

#[document_rpc]
#[async_trait]
pub trait ApiContract: Send + Sync + 'static {
Expand Down Expand Up @@ -229,4 +244,13 @@ pub trait ApiContract: Send + Sync + 'static {
summary = "Get a list of assets grouped by a specific authority"
)]
async fn get_grouping(&self, payload: GetGrouping) -> Result<GetGroupingResponse, DasApiError>;
#[rpc(
name = "getSignaturesForAsset",
params = "named",
summary = "Get transaction signatures for an asset"
)]
async fn get_signatures_for_asset(
&self,
payload: GetSignaturesForAsset,
) -> Result<TransactionSignatureList, DasApiError>;
}
6 changes: 6 additions & 0 deletions das_api/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ 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_alias("getSignaturesForAsset", "get_signatures_for_asset")?;

module.register_async_method("schema", |_, rpc_context| async move {
Ok(rpc_context.schema())
Expand Down
10 changes: 5 additions & 5 deletions digital_asset_types/src/dao/generated/asset_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub struct Model {
pub metadata: Json,
pub slot_updated: i64,
pub reindex: Option<bool>,
pub raw_name: Vec<u8>,
pub raw_symbol: Vec<u8>,
pub raw_name: Option<Vec<u8>>,
pub raw_symbol: Option<Vec<u8>>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
Expand Down Expand Up @@ -70,9 +70,9 @@ impl ColumnTrait for Column {
Self::MetadataMutability => Mutability::db_type(),
Self::Metadata => ColumnType::JsonBinary.def(),
Self::SlotUpdated => ColumnType::BigInteger.def(),
Self::Reindex => ColumnType::Boolean.def(),
Self::RawName => ColumnType::Binary.def(),
Self::RawSymbol => ColumnType::Binary.def(),
Self::Reindex => ColumnType::Boolean.def().null(),
Self::RawName => ColumnType::Binary.def().null(),
Self::RawSymbol => ColumnType::Binary.def().null(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions digital_asset_types/src/dao/generated/asset_grouping.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -12,15 +12,15 @@ impl EntityName for Entity {
}
}

#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Serialize, Deserialize)]
pub struct Model {
pub id: i64,
pub asset_id: Vec<u8>,
pub group_key: String,
pub group_value: Option<String>,
pub seq: Option<i64>,
pub slot_updated: Option<i64>,
pub verified: Option<bool>,
pub verified: bool,
pub group_info_seq: Option<i64>,
}

Expand Down
9 changes: 6 additions & 3 deletions digital_asset_types/src/dao/generated/cl_audits.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

use std::convert::From;

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

Expand All @@ -22,8 +21,9 @@ pub struct Model {
pub seq: i64,
pub level: i64,
pub hash: Vec<u8>,
pub created_at: Option<DateTime>,
pub created_at: DateTime,
pub tx: String,
pub instruction: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
Expand All @@ -37,6 +37,8 @@ pub enum Column {
Hash,
CreatedAt,
Tx,
#[sea_orm(column_name = "Instruction")]
Instruction,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
Expand Down Expand Up @@ -67,6 +69,7 @@ impl ColumnTrait for Column {
Self::Hash => ColumnType::Binary.def(),
Self::CreatedAt => ColumnType::DateTime.def(),
Self::Tx => ColumnType::String(None).def(),
Self::Instruction => ColumnType::String(None).def().null(),
}
}
}
Expand Down
68 changes: 34 additions & 34 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 @@ -14,20 +14,12 @@ pub enum Mutability {
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(
rs_type = "String",
db_type = "Enum",
enum_name = "v1_account_attachments"
)]
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(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,
}
Expand Down Expand Up @@ -60,6 +52,22 @@ pub enum RoyaltyTargetType {
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(
rs_type = "String",
db_type = "Enum",
enum_name = "specification_versions"
)]
pub enum SpecificationVersions {
#[sea_orm(string_value = "unknown")]
Unknown,
#[sea_orm(string_value = "v0")]
V0,
#[sea_orm(string_value = "v1")]
V1,
#[sea_orm(string_value = "v2")]
V2,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(
rs_type = "String",
db_type = "Enum",
Expand Down Expand Up @@ -88,30 +96,22 @@ pub enum SpecificationAssetClass {
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,
#[sea_orm(string_value = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(
rs_type = "String",
db_type = "Enum",
enum_name = "specification_versions"
enum_name = "v1_account_attachments"
)]
pub enum SpecificationVersions {
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,
#[sea_orm(string_value = "v0")]
V0,
#[sea_orm(string_value = "v1")]
V1,
#[sea_orm(string_value = "v2")]
V2,
}
#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "owner_type")]
Expand Down
Loading

0 comments on commit 7abbc0e

Please sign in to comment.