Skip to content

Commit c1d959d

Browse files
committed
Compatibility with the latest ledger-map
1 parent 2ea0a94 commit c1d959d

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

cli/src/main.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use chrono::DateTime;
1010
use dcc_common::{
1111
account_balance_get_as_string, amount_as_string, cursor_from_data, refresh_caches_from_ledger,
1212
zlib_compress, Account, CursorDirection, DccIdentity, FundsTransfer, LedgerCursor,
13-
NodeProviderProfile, UpdateOfferingPayload, UpdateProfilePayload, LABEL_DC_TOKEN_TRANSFER,
13+
NodeProviderProfile, UpdateProfilePayload, LABEL_DC_TOKEN_TRANSFER,
1414
};
1515
use decent_cloud::ledger_canister_client::LedgerCanister;
1616
use decent_cloud_canister::DC_TOKEN_TRANSFER_FEE_E9S;
@@ -20,10 +20,7 @@ use icrc_ledger_types::{
2020
icrc::generic_metadata_value::MetadataValue, icrc1::transfer::TransferArg,
2121
icrc1::transfer::TransferError as Icrc1TransferError,
2222
};
23-
use ledger_map::{
24-
platform_specific::{self, persistent_storage_read},
25-
LedgerMap,
26-
};
23+
use ledger_map::{platform_specific::persistent_storage_read, LedgerMap};
2724
use log::{info, Level, LevelFilter, Metadata, Record};
2825
use std::{
2926
collections::HashMap,
@@ -46,8 +43,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4643
.expect("Could not get home directory")
4744
.join(".dcc/ledger/main.bin"),
4845
};
49-
platform_specific::override_backing_file(Some(ledger_path.clone()));
50-
let ledger_local = LedgerMap::new(None).expect("Failed to load the local ledger");
46+
let ledger_local =
47+
LedgerMap::new_with_path(None, Some(ledger_path)).expect("Failed to load the local ledger");
5148
refresh_caches_from_ledger(&ledger_local).expect("Failed to get balances");
5249

5350
let network = args
@@ -495,7 +492,6 @@ async fn fetch_ledger_data(
495492
ledger_canister: &LedgerCanister,
496493
local_ledger_path: PathBuf,
497494
) -> Result<(), Box<dyn std::error::Error>> {
498-
ledger_map::override_backing_file(Some(local_ledger_path.clone()));
499495
let mut ledger_file = OpenOptions::new()
500496
.read(true)
501497
.write(true)
@@ -504,7 +500,8 @@ async fn fetch_ledger_data(
504500
.expect("failed to open the local ledger path");
505501

506502
let cursor_local = {
507-
let ledger = LedgerMap::new(None).expect("Failed to create LedgerMap");
503+
let ledger = LedgerMap::new_with_path(None, Some(local_ledger_path.clone()))
504+
.expect("Failed to create LedgerMap");
508505
cursor_from_data(
509506
ledger_map::partition_table::get_data_partition().start_lba,
510507
ledger_map::platform_specific::persistent_storage_size_bytes(),
@@ -578,8 +575,8 @@ pub async fn push_ledger_data(
578575
ledger_canister: &LedgerCanister,
579576
local_ledger_path: PathBuf,
580577
) -> Result<(), Box<dyn std::error::Error>> {
581-
ledger_map::override_backing_file(Some(local_ledger_path));
582-
let ledger_local = LedgerMap::new(Some(vec![])).expect("Failed to create LedgerMap");
578+
let ledger_local = LedgerMap::new_with_path(Some(vec![]), Some(local_ledger_path))
579+
.expect("Failed to create LedgerMap");
583580
let cursor_local = cursor_from_data(
584581
ledger_map::partition_table::get_data_partition().start_lba,
585582
ledger_map::platform_specific::persistent_storage_size_bytes(),

common/src/offerings.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,9 @@ mod tests {
345345
.unwrap()
346346
.into_path()
347347
.join("test_ledger_store.bin");
348-
ledger_map::platform_specific::override_backing_file(Some(file_path));
349-
ledger_map::partition_table::persist();
350348

351-
LedgerMap::new(labels_to_index).expect("Failed to create a test temp ledger")
349+
LedgerMap::new_with_path(labels_to_index, Some(file_path))
350+
.expect("Failed to create a test temp ledger")
352351
}
353352

354353
fn create_offering(

common/src/rewards/tests_rewards.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ fn new_temp_ledger(labels_to_index: Option<Vec<String>>) -> LedgerMap {
125125
.unwrap()
126126
.into_path()
127127
.join("test_ledger_store.bin");
128-
ledger_map::platform_specific::override_backing_file(Some(file_path));
129-
ledger_map::partition_table::persist();
130128

131-
LedgerMap::new(labels_to_index).expect("Failed to create a test temp ledger")
129+
LedgerMap::new_with_path(labels_to_index, Some(file_path))
130+
.expect("Failed to create a test temp ledger")
132131
}
133132

134133
// fn new_test_account(desc: &[u8]) -> Account {

0 commit comments

Comments
 (0)