Skip to content

Commit

Permalink
LS file modules
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Sep 16, 2020
1 parent 39363ad commit 885b2b8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions bee-node/src/node.rs
Expand Up @@ -19,7 +19,7 @@ use bee_crypto::ternary::Hash;
use bee_network::{self, Address, Command::Connect, EndpointId, Event, EventSubscriber, Network, Origin};
use bee_peering::{ManualPeerManager, PeerManager};
use bee_protocol::{tangle, MilestoneIndex, Protocol};
use bee_snapshot::local::{LocalSnapshot, ReadWriteError};
use bee_snapshot::local::{FileError, LocalSnapshot};

use async_std::task::{block_on, spawn};
use futures::{
Expand All @@ -38,7 +38,7 @@ type Receiver = ShutdownStream<Fuse<EventSubscriber>>;
pub enum Error {
/// Occurs, when there is an error while reading the snapshot file.
#[error("Reading the snapshot file failed.")]
LocalSnapshotReadError(ReadWriteError),
LocalSnapshotReadError(FileError),

/// Occurs, when there is an error while shutting down the node.
#[error("Shutting down failed.")]
Expand Down
Expand Up @@ -9,7 +9,7 @@
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

use crate::constants::IOTA_SUPPLY;
use crate::{constants::IOTA_SUPPLY, global::GlobalSnapshot};

use bee_ledger::state::LedgerState;
use bee_protocol::MilestoneIndex;
Expand All @@ -36,11 +36,6 @@ pub enum Error {
DifferentNewline,
}

pub struct GlobalSnapshot {
state: LedgerState,
index: MilestoneIndex,
}

impl GlobalSnapshot {
pub fn from_file(path: &str, index: MilestoneIndex) -> Result<Self, Error> {
let file = File::open(path).map_err(|_| Error::FileNotFound)?;
Expand Down
12 changes: 10 additions & 2 deletions bee-snapshot/src/global/mod.rs
Expand Up @@ -10,7 +10,15 @@
// See the License for the specific language governing permissions and limitations under the License.

mod config;
mod snapshot;
mod file;

pub use config::{GlobalSnapshotConfig, GlobalSnapshotConfigBuilder};
pub use snapshot::{Error as ReadWriteError, GlobalSnapshot};
pub use file::Error as FileError;

use bee_ledger::state::LedgerState;
use bee_protocol::MilestoneIndex;

pub struct GlobalSnapshot {
state: LedgerState,
index: MilestoneIndex,
}
4 changes: 2 additions & 2 deletions bee-snapshot/src/lib.rs
Expand Up @@ -30,8 +30,8 @@ use log::{info, warn};
use std::{path::Path, sync::Arc};

pub enum Error {
Global(global::ReadWriteError),
Local(local::ReadWriteError),
Global(global::FileError),
Local(local::FileError),
Download(local::DownloadError),
}

Expand Down
Expand Up @@ -9,7 +9,7 @@
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and limitations under the License.

use crate::{constants::IOTA_SUPPLY, local::LocalSnapshotMetadata, metadata::SnapshotMetadata};
use crate::{constants::IOTA_SUPPLY, local::LocalSnapshot, local::LocalSnapshotMetadata, metadata::SnapshotMetadata};

use bee_crypto::ternary::{Hash, HASH_LENGTH};
use bee_ledger::state::LedgerState;
Expand All @@ -26,11 +26,6 @@ use std::{
io::{BufReader, BufWriter, Read, Write},
};

pub struct LocalSnapshot {
pub(crate) metadata: LocalSnapshotMetadata,
pub(crate) state: LedgerState,
}

const VERSION: u8 = 4;

// TODO detail errors
Expand Down
9 changes: 7 additions & 2 deletions bee-snapshot/src/local/mod.rs
Expand Up @@ -11,14 +11,14 @@

mod config;
mod download;
mod file;
mod metadata;
mod snapshot;

pub(crate) use download::{download_local_snapshot, Error as DownloadError};

pub use config::{LocalSnapshotConfig, LocalSnapshotConfigBuilder};
pub use file::Error as FileError;
pub use metadata::LocalSnapshotMetadata;
pub use snapshot::{Error as ReadWriteError, LocalSnapshot};

use crate::metadata::SnapshotMetadata;

Expand All @@ -29,6 +29,11 @@ use log::{error, info};

use std::collections::HashMap;

pub struct LocalSnapshot {
pub(crate) metadata: LocalSnapshotMetadata,
pub(crate) state: LedgerState,
}

#[derive(Debug)]
pub(crate) enum Error {}

Expand Down

0 comments on commit 885b2b8

Please sign in to comment.