Skip to content

Commit c5c86e6

Browse files
committed
Move db ops to update_rgb_channel_info method
1 parent 997d3ad commit c5c86e6

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

lightning/src/rgb_utils/mod.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,8 @@ pub(crate) fn update_rgb_channel_id(
593593
let temp_chan_id = temporary_channel_id.0.as_hex().to_string();
594594
let chan_id = channel_id.0.as_hex().to_string();
595595

596-
let rgb_info = kv_store.read_rgb_channel_info(&temp_chan_id, false).expect("rename ok");
597-
kv_store.write_rgb_channel_info(&chan_id, &rgb_info, false);
598-
kv_store.remove_rgb_channel_info(&temp_chan_id, false).expect("rename ok");
599-
600-
let rgb_info = kv_store.read_rgb_channel_info(&temp_chan_id, true).expect("rename ok");
601-
kv_store.write_rgb_channel_info(&chan_id, &rgb_info, true);
602-
kv_store.remove_rgb_channel_info(&temp_chan_id, true).expect("rename ok");
596+
kv_store.update_rgb_channel_info(&temp_chan_id, &chan_id, false).expect("rename ok");
597+
kv_store.update_rgb_channel_info(&temp_chan_id, &chan_id, true).expect("rename ok");
603598

604599
if let Ok(consignment_data) = kv_store.read_rgb_consignment(&temp_chan_id) {
605600
kv_store.write_rgb_consignment(&chan_id, consignment_data);
@@ -732,6 +727,10 @@ pub trait RgbKvStoreExt {
732727
fn remove_rgb_channel_info(&self, channel_id: &str, pending: bool) -> Result<(), io::Error>;
733728
/// remove consignment from KVStore
734729
fn remove_rgb_consignment(&self, id: &str);
730+
/// move channel info from one key to another (read + write + remove)
731+
fn update_rgb_channel_info(
732+
&self, old_channel_id: &str, new_channel_id: &str, pending: bool,
733+
) -> Result<(), io::Error>;
735734
/// whether the payment is colored
736735
fn is_payment_rgb(&self, payment_hash: &PaymentHash) -> bool;
737736
/// filter first hops to only include channels with sufficient RGB assets
@@ -804,6 +803,14 @@ impl<K: KVStoreSync + ?Sized> RgbKvStoreExt for K {
804803
.expect("KVStore remove failed");
805804
}
806805

806+
fn update_rgb_channel_info(
807+
&self, old_channel_id: &str, new_channel_id: &str, pending: bool,
808+
) -> Result<(), io::Error> {
809+
let rgb_info = self.read_rgb_channel_info(old_channel_id, pending)?;
810+
self.write_rgb_channel_info(new_channel_id, &rgb_info, pending);
811+
self.remove_rgb_channel_info(old_channel_id, pending)
812+
}
813+
807814
fn is_payment_rgb(&self, payment_hash: &PaymentHash) -> bool {
808815
self.read_rgb_payment_info(payment_hash, false).is_ok()
809816
|| self.read_rgb_payment_info(payment_hash, true).is_ok()

0 commit comments

Comments
 (0)