pub fn create_allocation_from_asset(
    asset: &Asset,
    table_asset: &SqlAsset,
    connection: &SqliteConnection,
) -> Result<(Vec<SqlAllocationUtxo>, Vec<SqlAllocation>), SqlCacheError> {
    // get the last allocationutxo and allocation id
    // increase id from there
    let last_alloc_utxo = sql_allocation_utxo_table
        .load::<SqlAllocationUtxo>(connection)?
        .last()
        .cloned();
    let last_alloc = sql_allocation_table
        .load::<SqlAllocation>(connection)?
        .last()
        .cloned();

    let allocations = asset.known_allocations();

    let mut utxos = vec![];
    let mut allocation_vec = vec![];

    let mut added_allocations = 0;

    for (index, item) in allocations.into_iter().enumerate() {
        let this_utxo_id = match last_alloc_utxo.clone() {
            Some(alloc_utxo) => alloc_utxo.id + index as i32 + 1,
            None => 0 + index as i32,
        };
        utxos.push(SqlAllocationUtxo {
            id: this_utxo_id,
            sql_asset_id: table_asset.id,
            txid: item.0.txid.to_hex(),
            vout: item.0.vout as i32,
        });
        for (index, alloc) in item.1.into_iter().enumerate() {
            allocation_vec.push(SqlAllocation {
                id: match last_alloc.clone() {
                    Some(alloc) => {
                        alloc.id + added_allocations + index as i32 + 1
                    }
                    None => 0 + added_allocations + index as i32,
                },
                sql_allocation_utxo_id: this_utxo_id,
                node_id: alloc.node_id().to_hex(),
                assignment_index: alloc.index().clone() as i32,
                amount: alloc.value().value as i64,
                blinding: alloc.value().blinding.0.to_vec().to_hex(),
            });
        }
        added_allocations += item.1.len() as i32;
    }

    Ok((utxos, allocation_vec))
}
/// Create a list of AllocationUtxo and Allocation table entry
/// with correct associations between them.
/// The AllocationUtxo entries are associated with the given Asset entry.
///
/// For a Given Assets structure, this will create the correct AllocationUtxo
/// and Allocation table entries to write to the database
Create a list of AllocationUtxo and Allocation table entry
with correct associations between them.
The AllocationUtxo entries are associated with the given Asset entry.

For a Given Assets structure, this will create the correct AllocationUtxo
and Allocation table entries to write to the database
Create a list of AllocationUtxo and Allocation table entry with correct associations between them . The AllocationUtxo entries are associated with the given Asset entry . For a Given Assets structure this will create the correct AllocationUtxo and Allocation table entries to write to the database
pub fn create_allocation_from_asset(
    asset: &Asset,
    table_asset: &SqlAsset,
    connection: &SqliteConnection,
) -> Result<(Vec<SqlAllocationUtxo>, Vec<SqlAllocation>), SqlCacheError> {
    // get the last allocationutxo and allocation id
    // increase id from there
    let last_alloc_utxo = sql_allocation_utxo_table
        .load::<SqlAllocationUtxo>(connection)?
        .last()
        .cloned();
    let last_alloc = sql_allocation_table
        .load::<SqlAllocation>(connection)?
        .last()
        .cloned();
    let allocations = asset.known_allocations();
    let mut utxos = vec![];
    let mut allocation_vec = vec![];
    let mut added_allocations = 0;
    for (index, item) in allocations.into_iter().enumerate() {
        let this_utxo_id = match last_alloc_utxo.clone() {
            Some(alloc_utxo) => alloc_utxo.id + index as i32 + 1,
            None => 0 + index as i32,
        };
        utxos.push(SqlAllocationUtxo {
            id: this_utxo_id,
            sql_asset_id: table_asset.id,
            txid: item.0.txid.to_hex(),
            vout: item.0.vout as i32,
        });
        for (index, alloc) in item.1.into_iter().enumerate() {
            allocation_vec.push(SqlAllocation {
                id: match last_alloc.clone() {
                    Some(alloc) => {
                        alloc.id + added_allocations + index as i32 + 1
                    }
                    None => 0 + added_allocations + index as i32,
                },
                sql_allocation_utxo_id: this_utxo_id,
                node_id: alloc.node_id().to_hex(),
                assignment_index: alloc.index().clone() as i32,
                amount: alloc.value().value as i64,
                blinding: alloc.value().blinding.0.to_vec().to_hex(),
            });
        }
        added_allocations += item.1.len() as i32;
    }
    Ok((utxos, allocation_vec))
}
pub fn create_allocation_from_asset ( asset : & Asset , table_asset : & SqlAsset , connection : & SqliteConnection , ) -> Result < ( Vec < SqlAllocationUtxo > , Vec < SqlAllocation > ) , SqlCacheError > { // get the last allocationutxo and allocation id // increase id from there let last_alloc_utxo = sql_allocation_utxo_table . load :: < SqlAllocationUtxo > ( connection ) ? . last ( ) . cloned ( ) ; let last_alloc = sql_allocation_table . load :: < SqlAllocation > ( connection ) ? . last ( ) . cloned ( ) ; let allocations = asset . known_allocations ( ) ; let mut utxos = vec ! [ ] ; let mut allocation_vec = vec ! [ ] ; let mut added_allocations = 0 ; for ( index , item ) in allocations . into_iter ( ) . enumerate ( ) { let this_utxo_id = match last_alloc_utxo . clone ( ) { Some ( alloc_utxo ) => alloc_utxo . id + index as i32 + 1 , None => 0 + index as i32 , } ; utxos . push ( SqlAllocationUtxo { id : this_utxo_id , sql_asset_id : table_asset . id , txid : item . 0 . txid . to_hex ( ) , vout : item . 0 . vout as i32 , } ) ; for ( index , alloc ) in item . 1 . into_iter ( ) . enumerate ( ) { allocation_vec . push ( SqlAllocation { id : match last_alloc . clone ( ) { Some ( alloc ) => { alloc . id + added_allocations + index as i32 + 1 } None => 0 + added_allocations + index as i32 , } , sql_allocation_utxo_id : this_utxo_id , node_id : alloc . node_id ( ) . to_hex ( ) , assignment_index : alloc . index ( ) . clone ( ) as i32 , amount : alloc . value ( ) . value as i64 , blinding : alloc . value ( ) . blinding . 0 . to_vec ( ) . to_hex ( ) , } ) ; } added_allocations += item . 1 . len ( ) as i32 ; } Ok ( ( utxos , allocation_vec ) ) }
Create a list of AllocationUtxo and Allocation table entry
with correct associations between them.
Create a list of AllocationUtxo and Allocation table entry with correct associations between them .
asset
&Asset
table_asset
&SqlAsset
connection
&SqliteConnection
asset
&Asset
table_asset
&SqlAsset
connection
&SqliteConnection