blockfrost / blockfrost-rust

Rust SDK for Blockfrost.io
Apache License 2.0
16 stars 17 forks source link

Expected use of `Lister` to get all results #23

Closed b00kdev closed 10 months ago

b00kdev commented 2 years ago

First, thank you for this SDK. It has been very helpful in getting our project launched.

I have a simple function to get all the utxos for a given address. I'm testing with an address that has just a single utxo. When I run the code below, it runs forever until I kill the program.

async fn get_all_address_utxos(api_key: &str, address: &str) -> anyhow::Result<Vec<AddressUtxo>> {
    let mut settings = BlockFrostSettings::new().use_mainnet();
    settings
        .query_parameters
        .set_count(100)
        .set_page(1)
        .set_order(QueryOrder::Descending);
    let api = BlockFrostApi::new(api_key, settings);

    let mut lister = api.addresses_utxos_all(address);

    let mut res = Vec::new();
    while let Some(page) = lister.next().await {
        res.append(&mut page?);
    }

    Ok(res)
}

It looks like when there aren't any more results, page is an empty Vec. I can easily check for this and break out of the while loop but I was expecting the iterator to return None when there weren't any results remaining. Is this an incorrect assumption?

marcospb19 commented 2 years ago

I think you did a correct assumption, the code should check for empty Vecs, but it's not.

Thanks for the report, marking as a bug, any PR would be welcome.