Skip to content

Commit

Permalink
fix: load consignment from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
k0k0ne committed Oct 16, 2024
1 parent f2bce4b commit bb7ba40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lightning/src/color_ext/database.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt::{Display, Formatter};
use std::{
collections::HashMap,
io::{self, Write},
io::{self, Read, Write},
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -230,6 +230,18 @@ impl Write for ConsignmentBinaryData {
}
}

impl Read for ConsignmentBinaryData {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let len = std::cmp::min(buf.len(), self.0.len());
if len == 0 {
return Ok(0);
}
buf[..len].copy_from_slice(&self.0[..len]);
self.0.drain(..len);
Ok(len)
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct ConsignmentHandle(usize);

Expand Down
10 changes: 8 additions & 2 deletions lightning/src/color_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use bitcoin::psbt::{PartiallySignedTransaction, Psbt};
use bitcoin::secp256k1::PublicKey;
use bitcoin::{TxOut, Txid};
use database::{
ColorDatabaseImpl, ConsignmentBinaryData, PaymentDirection, PaymentHashKey, ProxyIdKey,
RgbInfoKey,
ColorDatabaseImpl, ConsignmentBinaryData, ConsignmentHandle, PaymentDirection, PaymentHashKey, ProxyIdKey, RgbInfoKey
};
use hex::DisplayHex;
use rgb_lib::wallet::rust_only::AssetBeneficiariesMap;
Expand Down Expand Up @@ -678,6 +677,13 @@ impl ColorSourceImpl {
Ok(())
}

pub fn get_consignment_by_funding_txid(
&self, funding_txid: &Txid,
) -> Option<ConsignmentBinaryData> {
let handle = self.database.consignment().lock().unwrap().get_by_funding_txid(funding_txid)?;
self.database.consignment().lock().unwrap().resolve(handle).cloned()
}

/// Update RGB channel amount
pub fn update_rgb_channel_amount_impl(
&self, channel_id: &ChannelId, rgb_offered_htlc: u64, rgb_received_htlc: u64, pending: bool,
Expand Down

0 comments on commit bb7ba40

Please sign in to comment.