Skip to content

Commit

Permalink
rename batch endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsintunan committed Dec 12, 2023
1 parent fcac715 commit c7a0bf6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 43 deletions.
21 changes: 10 additions & 11 deletions das_api/src/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use digital_asset_types::{
Cursor, PageOptions, SearchAssetsQuery,
},
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,
get_asset, get_asset_proofs, get_assets, get_assets_by_authority, get_assets_by_creator,
get_assets_by_group, get_assets_by_owner, get_proof_for_asset, search_assets,
},
rpc::{
filter::{AssetSortBy, SearchConditionType},
Expand Down Expand Up @@ -178,11 +177,11 @@ impl ApiContract for DasApi {
.map_err(Into::into)
}

async fn get_asset_proof_batch(
async fn get_asset_proofs(
self: &DasApi,
payload: GetAssetProofBatch,
payload: GetAssetProofs,
) -> Result<HashMap<String, Option<AssetProof>>, DasApiError> {
let GetAssetProofBatch { ids } = payload;
let GetAssetProofs { ids } = payload;

let batch_size = ids.len();
if batch_size > 1000 {
Expand All @@ -194,7 +193,7 @@ impl ApiContract for DasApi {
.map(|id| validate_pubkey(id.clone()).map(|id| id.to_bytes().to_vec()))
.collect::<Result<Vec<Vec<u8>>, _>>()?;

let proofs = get_asset_proof_batch(&self.db_connection, id_bytes).await?;
let proofs = get_asset_proofs(&self.db_connection, id_bytes).await?;

let result: HashMap<String, Option<AssetProof>> = ids
.iter()
Expand All @@ -212,11 +211,11 @@ impl ApiContract for DasApi {
.map_err(Into::into)
}

async fn get_asset_batch(
async fn get_assets(
self: &DasApi,
payload: GetAssetBatch,
payload: GetAssets,
) -> Result<Vec<Option<Asset>>, DasApiError> {
let GetAssetBatch { ids, options } = payload;
let GetAssets { ids, options } = payload;

let batch_size = ids.len();
if batch_size > 1000 {
Expand All @@ -230,7 +229,7 @@ impl ApiContract for DasApi {

let options = options.unwrap_or_default();

let assets = get_asset_batch(
let assets = get_assets(
&self.db_connection,
id_bytes,
batch_size as u64,
Expand Down
17 changes: 7 additions & 10 deletions das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct GetAsset {

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct GetAssetBatch {
pub struct GetAssets {
pub ids: Vec<String>,
#[serde(default, alias = "displayOptions")]
pub options: Option<Options>,
Expand All @@ -68,7 +68,7 @@ pub struct GetAssetProof {

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

Expand Down Expand Up @@ -158,13 +158,13 @@ pub trait ApiContract: Send + Sync + 'static {
)]
async fn get_asset_proof(&self, payload: GetAssetProof) -> Result<AssetProof, DasApiError>;
#[rpc(
name = "getAssetProofBatch",
name = "getAssetProofs",
params = "named",
summary = "Get merkle proofs for compressed assets by their IDs"
)]
async fn get_asset_proof_batch(
async fn get_asset_proofs(
&self,
payload: GetAssetProofBatch,
payload: GetAssetProofs,
) -> Result<HashMap<String, Option<AssetProof>>, DasApiError>;
#[rpc(
name = "getAsset",
Expand All @@ -173,14 +173,11 @@ pub trait ApiContract: Send + Sync + 'static {
)]
async fn get_asset(&self, payload: GetAsset) -> Result<Asset, DasApiError>;
#[rpc(
name = "getAssetBatch",
name = "getAssets",
params = "named",
summary = "Get assets by their IDs"
)]
async fn get_asset_batch(
&self,
payload: GetAssetBatch,
) -> Result<Vec<Option<Asset>>, DasApiError>;
async fn get_assets(&self, payload: GetAssets) -> Result<Vec<Option<Asset>>, DasApiError>;
#[rpc(
name = "getAssetsByOwner",
params = "named",
Expand Down
34 changes: 16 additions & 18 deletions das_api/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,30 @@ 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_proofs", |rpc_params, rpc_context| async move {
let payload = rpc_params.parse::<GetAssetProofs>()?;
rpc_context
.get_asset_proofs(payload)
.await
.map_err(Into::into)
})?;
module.register_alias("getAssetProofs", "get_asset_proofs")?;
module.register_alias("get_asset_proof_batch", "get_asset_proofs")?;
module.register_alias("getAssetProofBatch", "get_asset_proofs")?;

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_async_method("get_assets", |rpc_params, rpc_context| async move {
let payload = rpc_params.parse::<GetAssets>()?;
rpc_context.get_assets(payload).await.map_err(Into::into)
})?;
module.register_alias("getAssetBatch", "get_asset_batch")?;
module.register_alias("getAssets", "get_assets")?;
module.register_alias("get_asset_batch", "get_assets")?;
module.register_alias("getAssetBatch", "get_assets")?;

module.register_async_method(
"get_assets_by_owner",
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/src/dao/scopes/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub async fn get_assets_by_owner(
.await
}

pub async fn get_asset_batch(
pub async fn get_assets(
conn: &impl ConnectionTrait,
asset_ids: Vec<Vec<u8>>,
pagination: &Pagination,
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/src/dapi/change_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub async fn get_proof_for_asset(
Ok(asset_proof)
}

pub async fn get_asset_proof_batch(
pub async fn get_asset_proofs(
db: &DatabaseConnection,
asset_ids: Vec<Vec<u8>>,
) -> Result<HashMap<String, AssetProof>, DbErr> {
Expand Down
4 changes: 2 additions & 2 deletions digital_asset_types/src/dapi/get_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ pub async fn get_asset(
asset_to_rpc(asset, options)
}

pub async fn get_asset_batch(
pub async fn get_assets(
db: &DatabaseConnection,
ids: Vec<Vec<u8>>,
limit: u64,
options: &Options,
) -> Result<HashMap<String, Asset>, DbErr> {
let pagination = Pagination::Page { page: 1 };
let assets = scopes::asset::get_asset_batch(db, ids, &pagination, limit).await?;
let assets = scopes::asset::get_assets(db, ids, &pagination, limit).await?;
let asset_list = build_asset_response(assets, limit, &pagination, options);
let asset_map = asset_list
.items
Expand Down

0 comments on commit c7a0bf6

Please sign in to comment.