Skip to content

Commit

Permalink
use leaf index instead of leaf id
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsintunan committed Jul 18, 2023
1 parent 5759c5a commit 78b4ad5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
9 changes: 4 additions & 5 deletions das_api/src/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,16 @@ impl ApiContract for DasApi {
before,
after,
tree,
leaf_id,
leaf_index,
} = payload;

if id.is_none() && (tree.is_none() || leaf_id.is_none()) {
if id.is_none() && (tree.is_none() || leaf_index.is_none()) {
return Err(DasApiError::ValidationError(
"Must provide either id or both tree and leaf_id".to_string(),
"Must provide either 'id' or both 'tree' and 'leafIndex'".to_string(),
));
}
let id = validate_opt_pubkey(&id)?;
let tree = validate_opt_pubkey(&tree)?;
let leaf_id = validate_opt_pubkey(&leaf_id)?;

self.validate_pagination(&limit, &page, &before, &after)?;

Expand All @@ -420,7 +419,7 @@ impl ApiContract for DasApi {
before.map(|x| bs58::decode(x).into_vec().unwrap_or_default()),
after.map(|x| bs58::decode(x).into_vec().unwrap_or_default()),
tree,
leaf_id,
leaf_index,
)
.await
.map_err(Into::into)
Expand Down
2 changes: 1 addition & 1 deletion das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub struct GetSignaturesForAsset {
pub before: Option<String>,
pub after: Option<String>,
pub tree: Option<String>,
pub leaf_id: Option<String>,
pub leaf_index: Option<i64>,
}

#[document_rpc]
Expand Down
28 changes: 12 additions & 16 deletions digital_asset_types/src/dao/scopes/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,29 +327,25 @@ pub async fn get_signatures_for_asset(
pagination: &Pagination,
limit: u64,
tree_id: Option<Vec<u8>>,
leaf_id: Option<Vec<u8>>,
leaf_idx: Option<i64>,
) -> Result<Vec<Vec<String>>, DbErr> {
let mut stmt = asset::Entity::find();
if let (Some(tree_id), Some(leaf_idx)) = (tree_id, leaf_idx) {
let transactions = fetch_transactions(conn, tree_id, leaf_idx, pagination, limit).await?;
return Ok(transactions);
}

if let Some(asset_id) = asset_id {
stmt = stmt
.filter(asset::Column::Id.eq(asset_id))
.order_by(asset::Column::Id, Order::Desc)
.limit(1);
} else if let (Some(tree_id), Some(leaf_id)) = (tree_id, leaf_id) {
stmt = stmt
.filter(asset::Column::TreeId.eq(tree_id))
.filter(asset::Column::Leaf.eq(leaf_id))
// .order_by(??, Order::Desc)
.limit(1);
} else {
if asset_id.is_none() {
return Err(DbErr::Custom(
"Either asset_id or both tree_id and leaf_id must be provided".to_string(),
"Either 'id' or both 'tree' and 'leafIndex' must be provided".to_string(),
));
}

let stmt = asset::Entity::find()
.distinct_on([(asset::Entity, asset::Column::Id)])
.filter(asset::Column::Id.eq(asset_id))
.order_by(asset::Column::Id, Order::Desc)
.limit(1);
let asset = stmt.one(conn).await?;

if let Some(asset) = asset {
let tree = asset
.tree_id
Expand Down
4 changes: 2 additions & 2 deletions digital_asset_types/src/dapi/signatures_for_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub async fn get_signatures_for_asset(
before: Option<Vec<u8>>,
after: Option<Vec<u8>>,
tree: Option<Vec<u8>>,
leaf_id: Option<Vec<u8>>,
leaf_idx: Option<i64>,
) -> Result<TransactionSignatureList, DbErr> {
let pagination = create_pagination(before, after, page)?;
let transactions =
scopes::asset::get_signatures_for_asset(db, asset_id, &pagination, limit, tree, leaf_id)
scopes::asset::get_signatures_for_asset(db, asset_id, &pagination, limit, tree, leaf_idx)
.await?;
Ok(build_transaction_signatures_response(
transactions,
Expand Down

0 comments on commit 78b4ad5

Please sign in to comment.