Skip to content

Commit

Permalink
Merge branch 'triton-build' into espi/das-ingester-backfiller
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanito87 authored Dec 11, 2023
2 parents 4430c94 + ba20d9d commit 448479e
Show file tree
Hide file tree
Showing 44 changed files with 1,180 additions and 258 deletions.
252 changes: 211 additions & 41 deletions das_api/src/api/api_impl.rs

Large diffs are not rendered by default.

84 changes: 83 additions & 1 deletion das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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};
use open_rpc_schema::schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

mod api_impl;
pub use api_impl::*;
Expand All @@ -21,6 +23,10 @@ pub struct GetAssetsByGroup {
pub page: Option<u32>,
pub before: Option<String>,
pub after: Option<String>,
#[serde(default)]
pub display_options: Option<DisplayOptions>,
#[serde(default)]
pub cursor: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
Expand All @@ -32,12 +38,26 @@ pub struct GetAssetsByOwner {
pub page: Option<u32>,
pub before: Option<String>,
pub after: Option<String>,
#[serde(default)]
pub display_options: Option<DisplayOptions>,
#[serde(default)]
pub cursor: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetAsset {
pub id: String,
#[serde(default)]
pub display_options: Option<DisplayOptions>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetAssetBatch {
pub ids: Vec<String>,
#[serde(default)]
pub display_options: Option<DisplayOptions>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
Expand All @@ -46,6 +66,12 @@ pub struct GetAssetProof {
pub id: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetAssetProofBatch {
pub ids: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetAssetsByCreator {
Expand All @@ -56,6 +82,10 @@ pub struct GetAssetsByCreator {
pub page: Option<u32>,
pub before: Option<String>,
pub after: Option<String>,
#[serde(default)]
pub display_options: Option<DisplayOptions>,
#[serde(default)]
pub cursor: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -87,6 +117,12 @@ pub struct SearchAssets {
pub after: Option<String>,
#[serde(default)]
pub json_uri: Option<String>,
#[serde(default)]
pub display_options: Option<DisplayOptions>,
#[serde(default)]
pub cursor: Option<String>,
#[serde(default)]
pub name: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
Expand All @@ -98,6 +134,10 @@ pub struct GetAssetsByAuthority {
pub page: Option<u32>,
pub before: Option<String>,
pub after: Option<String>,
#[serde(default)]
pub display_options: Option<DisplayOptions>,
#[serde(default)]
pub cursor: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
Expand All @@ -107,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 All @@ -117,12 +172,30 @@ pub trait ApiContract: Send + Sync + 'static {
summary = "Get a merkle proof for a compressed asset by its ID"
)]
async fn get_asset_proof(&self, payload: GetAssetProof) -> Result<AssetProof, DasApiError>;
#[rpc(
name = "getAssetProofBatch",
params = "named",
summary = "Get merkle proofs for compressed assets by their IDs"
)]
async fn get_asset_proof_batch(
&self,
payload: GetAssetProofBatch,
) -> Result<HashMap<String, Option<AssetProof>>, DasApiError>;
#[rpc(
name = "getAsset",
params = "named",
summary = "Get an asset by its ID"
)]
async fn get_asset(&self, payload: GetAsset) -> Result<Asset, DasApiError>;
#[rpc(
name = "getAssetBatch",
params = "named",
summary = "Get assets by their IDs"
)]
async fn get_asset_batch(
&self,
payload: GetAssetBatch,
) -> Result<Vec<Option<Asset>>, DasApiError>;
#[rpc(
name = "getAssetsByOwner",
params = "named",
Expand Down Expand Up @@ -171,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>;
}
27 changes: 27 additions & 0 deletions das_api/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,33 @@ impl RpcApiBuilder {
})?;
module.register_alias("getAssetProof", "get_asset_proof")?;

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

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

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

module.register_async_method(
"get_assets_by_owner",
|rpc_params, rpc_context| async move {
Expand Down Expand Up @@ -80,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
8 changes: 8 additions & 0 deletions das_api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ pub enum DasApiError {
PaginationEmptyError,
#[error("Deserialization error: {0}")]
DeserializationError(#[from] serde_json::Error),
#[error("Batch Size Error. Batch size should not be greater than 1000.")]
BatchSizeExceededError,
#[error("Pagination Error. Limit should not be greater than 1000.")]
PaginationExceededError,
#[error("Cursor Validation Err: {0} is invalid")]
CursorValidationError(String),
#[error("Pagination Sorting Error. Only sorting based on id is support for this pagination")]
PaginationSortingValidationError,
}

impl Into<RpcError> for DasApiError {
Expand Down
17 changes: 17 additions & 0 deletions das_api/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ pub fn validate_pubkey(str_pubkey: String) -> Result<Pubkey, DasApiError> {
Pubkey::from_str(&str_pubkey).map_err(|_| DasApiError::PubkeyValidationError(str_pubkey))
}

pub fn validate_search_with_name(
name: &Option<String>,
owner: &Option<Vec<u8>>,
) -> Result<Option<Vec<u8>>, DasApiError> {
let opt_name = if let Some(n) = name {
if owner.is_none() {
return Err(DasApiError::ValidationError(
"Owner address must be provided in order to search assets by name".to_owned(),
));
}
Some(n.clone().into_bytes())
} else {
None
};
Ok(opt_name)
}

pub fn validate_opt_pubkey(pubkey: &Option<String>) -> Result<Option<Vec<u8>>, DasApiError> {
let opt_bytes = if let Some(pubkey) = pubkey {
let pubkey = Pubkey::from_str(pubkey)
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
Loading

0 comments on commit 448479e

Please sign in to comment.