Skip to content
Snippets Groups Projects
Commit 8caa8fe5 authored by Éloïs's avatar Éloïs
Browse files

[feat] gva: add amount input to queries uds & utxos

parent 17dce9f3
No related branches found
No related tags found
1 merge request!1335Gva proto 2
......@@ -75,6 +75,8 @@ pub(crate) struct UtxoGva {
pub(crate) tx_hash: String,
/// Index of output in origin transaction
pub(crate) output_index: u32,
/// Written block
pub(crate) written_block: u32,
/// Written time
pub(crate) written_time: u64,
}
......@@ -46,6 +46,7 @@ impl UdsQuery {
#[graphql(desc = "Ed25519 public key on base 58 representation")] pubkey: String,
#[graphql(default)] filter: UdsFilter,
#[graphql(desc = "pagination", default)] pagination: PaginationWithIntCursor,
#[graphql(desc = "Amount needed")] amount: Option<i64>,
) -> async_graphql::Result<Connection<usize, UdGva, Sum, EmptyFields>> {
let pagination = PaginationWithIntCursor::convert_to_page_info(pagination);
......@@ -63,6 +64,9 @@ impl UdsQuery {
) = data
.dbs_pool
.execute(move |dbs| {
if let Some(current_block) =
duniter_dbs_read_ops::get_current_block_meta(&dbs.bc_db)?
{
let paged_data = match filter {
UdsFilter::All => duniter_dbs_read_ops::uds_of_pubkey::all_uds_of_pubkey(
&dbs.bc_db,
......@@ -72,7 +76,13 @@ impl UdsQuery {
),
UdsFilter::Unspent => {
duniter_dbs_read_ops::uds_of_pubkey::unspent_uds_of_pubkey(
&dbs.bc_db, pubkey, pagination, None, None,
&dbs.bc_db,
pubkey,
pagination,
None,
amount.map(|amount| {
SourceAmount::new(amount, current_block.unit_base as i64)
}),
)
}
}?;
......@@ -85,7 +95,10 @@ impl UdsQuery {
.unwrap_or_else(|| unreachable!()),
);
}
Ok::<_, KvError>((paged_data, times))
Ok::<_, anyhow::Error>((paged_data, times))
} else {
Err(anyhow::Error::msg("no blockchain"))
}
})
.await??;
......
......@@ -31,6 +31,7 @@ impl UtxosQuery {
ctx: &async_graphql::Context<'_>,
#[graphql(desc = "DUBP wallet script")] script: String,
#[graphql(desc = "pagination", default)] pagination: PaginationWithStrCursor,
#[graphql(desc = "Amount needed")] amount: Option<i64>,
) -> async_graphql::Result<Connection<String, UtxoGva, Sum, EmptyFields>> {
let pagination = PaginationWithStrCursor::convert_to_page_info(pagination);
......@@ -48,10 +49,15 @@ impl UtxosQuery {
) = data
.dbs_pool
.execute(move |dbs| {
if let Some(current_block) =
duniter_dbs_read_ops::get_current_block_meta(&dbs.bc_db)?
{
let paged_data = duniter_dbs_read_ops::utxos::find_script_utxos(
&dbs.gva_db,
&dbs.txs_mp_db,
None,
amount.map(|amount| {
SourceAmount::new(amount, current_block.unit_base as i64)
}),
pagination,
&script,
)?;
......@@ -65,6 +71,9 @@ impl UtxosQuery {
);
}
Ok::<_, anyhow::Error>((paged_data, times))
} else {
Err(anyhow::Error::msg("no blockchain"))
}
})
.await??;
......@@ -87,6 +96,7 @@ impl UtxosQuery {
base: source_amount.base(),
tx_hash: utxo_id_with_bn.0.tx_hash.to_hex(),
output_index: utxo_id_with_bn.0.output_index as u32,
written_block: (utxo_id_with_bn.1).0,
written_time: blockchain_time,
},
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment