pub fn read_allocations(
    asset: &SqlAsset,
    connection: &SqliteConnection,
) -> Result<BTreeMap<OutPoint, Vec<Allocation>>, SqlCacheError> {
    // Get the associated utxo with asset entry
    let utxo_list = SqlAllocationUtxo::belonging_to(asset)
        .load::<SqlAllocationUtxo>(connection)?;

    // Get the associated allocations with the above utxos
    let allocations = SqlAllocation::belonging_to(&utxo_list)
        .load::<SqlAllocation>(connection)?
        .grouped_by(&utxo_list);

    // Group them accordingly and zip the two vectors by correct groupings
    let grouped_allocation =
        utxo_list.into_iter().zip(&allocations).collect::<Vec<_>>();

    let mut allocation_map = BTreeMap::new();

    grouped_allocation.into_iter().for_each(|item| {
        allocation_map.insert(item.0, item.1);
    });

    // Read the zipped data into a BtreeMap
    let mut known_allocation = BTreeMap::new();

    for item in allocation_map.into_iter() {
        let mut allocations = vec![];
        for allocation in item.1 {
            allocations
                .push(Allocation::from_sql_allocation(&allocation, &item.0)?);
        }
        known_allocation.insert(
            OutPoint {
                txid: Txid::from_hex(&item.0.txid[..])?,
                vout: item.0.vout as u32,
            },
            allocations,
        );
    }

    Ok(known_allocation)
}
/// Read the associated AllocationUtxo and Allocation entries
/// with the given Asset entry executed over the given database
/// connection.
/// This will return a BtreeMap which can be directly used as the
/// `known_allocations` field in the Asset Data structure.
Read the associated AllocationUtxo and Allocation entries
with the given Asset entry executed over the given database
connection.
This will return a BtreeMap which can be directly used as the
`known_allocations` field in the Asset Data structure.
Read the associated AllocationUtxo and Allocation entries with the given Asset entry executed over the given database connection . This will return a BtreeMap which can be directly used as the ` known_allocations ` field in the Asset Data structure .
pub fn read_allocations(
    asset: &SqlAsset,
    connection: &SqliteConnection,
) -> Result<BTreeMap<OutPoint, Vec<Allocation>>, SqlCacheError> {
    // Get the associated utxo with asset entry
    let utxo_list = SqlAllocationUtxo::belonging_to(asset)
        .load::<SqlAllocationUtxo>(connection)?;
    // Get the associated allocations with the above utxos
    let allocations = SqlAllocation::belonging_to(&utxo_list)
        .load::<SqlAllocation>(connection)?
        .grouped_by(&utxo_list);
    // Group them accordingly and zip the two vectors by correct groupings
    let grouped_allocation =
        utxo_list.into_iter().zip(&allocations).collect::<Vec<_>>();
    let mut allocation_map = BTreeMap::new();
    grouped_allocation.into_iter().for_each(|item| {
        allocation_map.insert(item.0, item.1);
    });
    // Read the zipped data into a BtreeMap
    let mut known_allocation = BTreeMap::new();
    for item in allocation_map.into_iter() {
        let mut allocations = vec![];
        for allocation in item.1 {
            allocations
                .push(Allocation::from_sql_allocation(&allocation, &item.0)?);
        }
        known_allocation.insert(
            OutPoint {
                txid: Txid::from_hex(&item.0.txid[..])?,
                vout: item.0.vout as u32,
            },
            allocations,
        );
    }
    Ok(known_allocation)
}
pub fn read_allocations ( asset : & SqlAsset , connection : & SqliteConnection , ) -> Result < BTreeMap < OutPoint , Vec < Allocation > > , SqlCacheError > { // Get the associated utxo with asset entry let utxo_list = SqlAllocationUtxo :: belonging_to ( asset ) . load :: < SqlAllocationUtxo > ( connection ) ? ; // Get the associated allocations with the above utxos let allocations = SqlAllocation :: belonging_to ( & utxo_list ) . load :: < SqlAllocation > ( connection ) ? . grouped_by ( & utxo_list ) ; // Group them accordingly and zip the two vectors by correct groupings let grouped_allocation = utxo_list . into_iter ( ) . zip ( & allocations ) . collect :: < Vec < _ > > ( ) ; let mut allocation_map = BTreeMap :: new ( ) ; grouped_allocation . into_iter ( ) . for_each ( | item | { allocation_map . insert ( item . 0 , item . 1 ) ; } ) ; // Read the zipped data into a BtreeMap let mut known_allocation = BTreeMap :: new ( ) ; for item in allocation_map . into_iter ( ) { let mut allocations = vec ! [ ] ; for allocation in item . 1 { allocations . push ( Allocation :: from_sql_allocation ( & allocation , & item . 0 ) ? ) ; } known_allocation . insert ( OutPoint { txid : Txid :: from_hex ( & item . 0 . txid [ .. ] ) ? , vout : item . 0 . vout as u32 , } , allocations , ) ; } Ok ( known_allocation ) }
Read the associated AllocationUtxo and Allocation entries
with the given Asset entry executed over the given database
connection.
Read the associated AllocationUtxo and Allocation entries with the given Asset entry executed over the given database connection .
asset
&SqlAsset
connection
&SqliteConnection
asset
&SqlAsset
connection
&SqliteConnection