@@ -170,20 +170,22 @@ pub(crate) fn color_commitment<SP: Deref>(channel_context: &ChannelContext<SP>,
170
170
171
171
let htlc_payment_hash = hex:: encode ( htlc. payment_hash . 0 ) ;
172
172
let htlc_proxy_id = format ! ( "{chan_id}{htlc_payment_hash}" ) ;
173
- let rgb_payment_info_path = ldk_data_dir. join ( htlc_proxy_id) ;
173
+ let rgb_payment_info_proxy_id_path = ldk_data_dir. join ( htlc_proxy_id) ;
174
174
175
- let rgb_payment_info_hash_path = ldk_data_dir. join ( htlc_payment_hash) ;
176
- if rgb_payment_info_hash_path. exists ( ) {
177
- let mut rgb_payment_info = parse_rgb_payment_info ( & rgb_payment_info_hash_path) ;
175
+ let rgb_payment_info_path = ldk_data_dir. join ( htlc_payment_hash) ;
176
+ let mut rgb_payment_info_tmp_path = rgb_payment_info_path. clone ( ) ;
177
+ rgb_payment_info_tmp_path. set_extension ( "pending" ) ;
178
+ if rgb_payment_info_tmp_path. exists ( ) {
179
+ let mut rgb_payment_info = parse_rgb_payment_info ( & rgb_payment_info_tmp_path) ;
178
180
rgb_payment_info. local_rgb_amount = rgb_info. local_rgb_amount ;
179
181
rgb_payment_info. remote_rgb_amount = rgb_info. remote_rgb_amount ;
180
182
let serialized_info = serde_json:: to_string ( & rgb_payment_info) . expect ( "valid rgb payment info" ) ;
181
- fs:: write ( & rgb_payment_info_path , serialized_info) . expect ( "able to write rgb payment info file" ) ;
182
- fs:: remove_file ( rgb_payment_info_hash_path ) . expect ( "able to remove file" ) ;
183
+ fs:: write ( & rgb_payment_info_proxy_id_path , serialized_info) . expect ( "able to write rgb payment info file" ) ;
184
+ fs:: remove_file ( rgb_payment_info_tmp_path ) . expect ( "able to remove file" ) ;
183
185
}
184
186
185
- let rgb_payment_info = if rgb_payment_info_path . exists ( ) {
186
- parse_rgb_payment_info ( & rgb_payment_info_path )
187
+ let rgb_payment_info = if rgb_payment_info_proxy_id_path . exists ( ) {
188
+ parse_rgb_payment_info ( & rgb_payment_info_proxy_id_path )
187
189
} else {
188
190
let rgb_payment_info = RgbPaymentInfo {
189
191
contract_id : rgb_info. contract_id ,
@@ -194,6 +196,7 @@ pub(crate) fn color_commitment<SP: Deref>(channel_context: &ChannelContext<SP>,
194
196
inbound : htlc. offered == counterparty,
195
197
} ;
196
198
let serialized_info = serde_json:: to_string ( & rgb_payment_info) . expect ( "valid rgb payment info" ) ;
199
+ fs:: write ( rgb_payment_info_proxy_id_path, serialized_info. clone ( ) ) . expect ( "able to write rgb payment info file" ) ;
197
200
fs:: write ( rgb_payment_info_path, serialized_info) . expect ( "able to write rgb payment info file" ) ;
198
201
rgb_payment_info
199
202
} ;
@@ -558,7 +561,9 @@ pub fn write_rgb_channel_info(path: &PathBuf, rgb_info: &RgbInfo) {
558
561
559
562
/// Write RGB payment info to file
560
563
pub fn write_rgb_payment_info_file ( ldk_data_dir : & Path , payment_hash : & PaymentHash , contract_id : ContractId , amount_rgb : u64 , override_route_amount : bool , inbound : bool ) {
561
- let rgb_payment_info_path = ldk_data_dir. join ( hex:: encode ( payment_hash. 0 ) ) ;
564
+ let rgb_payment_info_path = get_rgb_payment_info_path ( payment_hash, ldk_data_dir) ;
565
+ let mut rgb_payment_info_tmp_path = rgb_payment_info_path. clone ( ) ;
566
+ rgb_payment_info_tmp_path. set_extension ( "pending" ) ;
562
567
let rgb_payment_info = RgbPaymentInfo {
563
568
contract_id,
564
569
amount : amount_rgb,
@@ -568,7 +573,8 @@ pub fn write_rgb_payment_info_file(ldk_data_dir: &Path, payment_hash: &PaymentHa
568
573
inbound,
569
574
} ;
570
575
let serialized_info = serde_json:: to_string ( & rgb_payment_info) . expect ( "valid rgb payment info" ) ;
571
- std:: fs:: write ( rgb_payment_info_path, serialized_info) . expect ( "able to write rgb payment info file" ) ;
576
+ std:: fs:: write ( rgb_payment_info_path, serialized_info. clone ( ) ) . expect ( "able to write rgb payment info file" ) ;
577
+ std:: fs:: write ( rgb_payment_info_tmp_path, serialized_info) . expect ( "able to write rgb payment info tmp file" ) ;
572
578
}
573
579
574
580
/// Rename RGB files from temporary to final channel ID
0 commit comments