pub struct Tangle<B> { /* private fields */ }Expand description
A Tangle wrapper designed to encapsulate milestone state.
Implementations§
Source§impl<B: StorageBackend> Tangle<B>
impl<B: StorageBackend> Tangle<B>
Sourcepub fn new(config: TangleConfig, storage: ResourceHandle<B>) -> Self
pub fn new(config: TangleConfig, storage: ResourceHandle<B>) -> Self
Create a new Tangle instance with the given configuration and storage handle.
Sourcepub fn config(&self) -> &TangleConfig
pub fn config(&self) -> &TangleConfig
Get the configuration of this tangle.
Sourcepub async fn insert(
&self,
message: Message,
message_id: MessageId,
metadata: MessageMetadata,
) -> Option<MessageRef>
pub async fn insert( &self, message: Message, message_id: MessageId, metadata: MessageMetadata, ) -> Option<MessageRef>
Insert a message into the tangle.
Sourcepub async fn add_milestone(&self, idx: MilestoneIndex, milestone: Milestone)
pub async fn add_milestone(&self, idx: MilestoneIndex, milestone: Milestone)
Add a milestone to the tangle.
Sourcepub async fn remove_milestone(&self, index: MilestoneIndex)
pub async fn remove_milestone(&self, index: MilestoneIndex)
Remove a milestone from the tangle.
Sourcepub async fn get_milestone(&self, index: MilestoneIndex) -> Option<Milestone>
pub async fn get_milestone(&self, index: MilestoneIndex) -> Option<Milestone>
Get the milestone from the tangle that corresponds to the given milestone index.
Sourcepub async fn get_milestone_message(
&self,
index: MilestoneIndex,
) -> Option<MessageRef>
pub async fn get_milestone_message( &self, index: MilestoneIndex, ) -> Option<MessageRef>
Get the message associated with the given milestone index from the tangle.
Sourcepub async fn get_milestone_message_id(
&self,
index: MilestoneIndex,
) -> Option<MessageId>
pub async fn get_milestone_message_id( &self, index: MilestoneIndex, ) -> Option<MessageId>
Get the message ID associated with the given milestone index from the tangle.
Sourcepub async fn contains_milestone(&self, idx: MilestoneIndex) -> bool
pub async fn contains_milestone(&self, idx: MilestoneIndex) -> bool
Return whether the tangle contains the given milestone index.
Sourcepub fn get_latest_milestone_index(&self) -> MilestoneIndex
pub fn get_latest_milestone_index(&self) -> MilestoneIndex
Get the index of the latest milestone.
Sourcepub fn update_latest_milestone_index(&self, new_index: MilestoneIndex)
pub fn update_latest_milestone_index(&self, new_index: MilestoneIndex)
Update the index of the lastest milestone.
Sourcepub fn get_solid_milestone_index(&self) -> MilestoneIndex
pub fn get_solid_milestone_index(&self) -> MilestoneIndex
Get the latest solid milestone index.
Sourcepub fn update_solid_milestone_index(&self, new_index: MilestoneIndex)
pub fn update_solid_milestone_index(&self, new_index: MilestoneIndex)
Update the latest solid milestone index.
Sourcepub fn get_confirmed_milestone_index(&self) -> MilestoneIndex
pub fn get_confirmed_milestone_index(&self) -> MilestoneIndex
Get the latest confirmed milestone index.
Sourcepub fn update_confirmed_milestone_index(&self, new_index: MilestoneIndex)
pub fn update_confirmed_milestone_index(&self, new_index: MilestoneIndex)
Update the latest confirmed milestone index.
Sourcepub fn get_snapshot_index(&self) -> MilestoneIndex
pub fn get_snapshot_index(&self) -> MilestoneIndex
Get the snapshot index.
Sourcepub fn update_snapshot_index(&self, new_index: MilestoneIndex)
pub fn update_snapshot_index(&self, new_index: MilestoneIndex)
Update the snapshot index.
Sourcepub fn get_pruning_index(&self) -> MilestoneIndex
pub fn get_pruning_index(&self) -> MilestoneIndex
Get the pruning index.
Sourcepub fn update_pruning_index(&self, new_index: MilestoneIndex)
pub fn update_pruning_index(&self, new_index: MilestoneIndex)
Update the pruning index.
Sourcepub fn get_entry_point_index(&self) -> MilestoneIndex
pub fn get_entry_point_index(&self) -> MilestoneIndex
Get the entry point index.
Sourcepub fn update_entry_point_index(&self, new_index: MilestoneIndex)
pub fn update_entry_point_index(&self, new_index: MilestoneIndex)
Update the entry point index.
Sourcepub fn is_synced(&self) -> bool
pub fn is_synced(&self) -> bool
Return whether the tangle is within the default sync threshold.
Sourcepub fn get_sync_threshold(&self) -> u32
pub fn get_sync_threshold(&self) -> u32
Get the number of milestones until the tangle is synced.
Sourcepub fn is_synced_threshold(&self, threshold: u32) -> bool
pub fn is_synced_threshold(&self, threshold: u32) -> bool
Return whether the tangle is within the given sync threshold.
Sourcepub fn is_confirmed(&self) -> bool
pub fn is_confirmed(&self) -> bool
Return whether the tangle is fully confirmed.
Sourcepub fn is_confirmed_threshold(&self, threshold: u32) -> bool
pub fn is_confirmed_threshold(&self, threshold: u32) -> bool
Return whether the tangle is within the given confirmation threshold.
Sourcepub async fn get_solid_entry_point_index(
&self,
sep: &SolidEntryPoint,
) -> Option<MilestoneIndex>
pub async fn get_solid_entry_point_index( &self, sep: &SolidEntryPoint, ) -> Option<MilestoneIndex>
Get the milestone index associated with the given solid entry point.
Sourcepub async fn add_solid_entry_point(
&self,
sep: SolidEntryPoint,
index: MilestoneIndex,
)
pub async fn add_solid_entry_point( &self, sep: SolidEntryPoint, index: MilestoneIndex, )
Add the given solid entry point to the given milestone index.
Sourcepub async fn get_solid_entry_points(
&self,
) -> HashMap<SolidEntryPoint, MilestoneIndex>
pub async fn get_solid_entry_points( &self, ) -> HashMap<SolidEntryPoint, MilestoneIndex>
Returns a copy of all solid entry points.
Sourcepub async fn remove_solid_entry_point(&self, sep: &SolidEntryPoint)
pub async fn remove_solid_entry_point(&self, sep: &SolidEntryPoint)
Removes the given solid entry point from the set of solid entry points.
Sourcepub async fn clear_solid_entry_points(&self)
pub async fn clear_solid_entry_points(&self)
Clear all solid entry points.
Sourcepub async fn replace_solid_entry_points(
&self,
new_seps: impl IntoIterator<Item = (SolidEntryPoint, MilestoneIndex)>,
)
pub async fn replace_solid_entry_points( &self, new_seps: impl IntoIterator<Item = (SolidEntryPoint, MilestoneIndex)>, )
Replaces all solid entry points.
Sourcepub async fn is_solid_entry_point(&self, id: &MessageId) -> bool
pub async fn is_solid_entry_point(&self, id: &MessageId) -> bool
Returns whether the message associated with given solid entry point is a solid entry point.
Sourcepub async fn is_solid_message(&self, id: &MessageId) -> bool
pub async fn is_solid_message(&self, id: &MessageId) -> bool
Returns whether the message associated with the given message ID is solid.
Sourcepub async fn omrsi(&self, id: &MessageId) -> Option<IndexId>
pub async fn omrsi(&self, id: &MessageId) -> Option<IndexId>
Get the oldest milestone root snapshot index.
Sourcepub async fn ymrsi(&self, id: &MessageId) -> Option<IndexId>
pub async fn ymrsi(&self, id: &MessageId) -> Option<IndexId>
Get the youngest milestone root snapshot index.
Sourcepub async fn insert_tip(&self, message_id: MessageId, parents: Vec<MessageId>)
pub async fn insert_tip(&self, message_id: MessageId, parents: Vec<MessageId>)
Insert the given message ID and parents as a tip.
Sourcepub async fn update_tip_scores(&self)
pub async fn update_tip_scores(&self)
Update tip scores.
Sourcepub async fn get_messages_to_approve(&self) -> Option<Vec<MessageId>>
pub async fn get_messages_to_approve(&self) -> Option<Vec<MessageId>>
Return messages that require approving.
Sourcepub async fn reduce_tips(&self)
pub async fn reduce_tips(&self)
Reduce tips.
Sourcepub async fn non_lazy_tips_num(&self) -> usize
pub async fn non_lazy_tips_num(&self) -> usize
Return the number of non-lazy tips.
Sourcepub async fn get(&self, message_id: &MessageId) -> Option<MessageRef>
pub async fn get(&self, message_id: &MessageId) -> Option<MessageRef>
Get the data of a vertex associated with the given message_id.
Sourcepub async fn contains(&self, message_id: &MessageId) -> bool
pub async fn contains(&self, message_id: &MessageId) -> bool
Returns whether the message is stored in the Tangle.
Sourcepub async fn get_metadata(
&self,
message_id: &MessageId,
) -> Option<MessageMetadata>
pub async fn get_metadata( &self, message_id: &MessageId, ) -> Option<MessageMetadata>
Get the metadata of a vertex associated with the given message_id.
Sourcepub async fn get_vertex(
&self,
message_id: &MessageId,
) -> Option<impl Deref<Target = Vertex> + '_>
pub async fn get_vertex( &self, message_id: &MessageId, ) -> Option<impl Deref<Target = Vertex> + '_>
Get the metadata of a vertex associated with the given message_id.
Sourcepub async fn update_metadata<R, Update>(
&self,
message_id: &MessageId,
update: Update,
) -> Option<R>where
Update: FnOnce(&mut MessageMetadata) -> R,
pub async fn update_metadata<R, Update>(
&self,
message_id: &MessageId,
update: Update,
) -> Option<R>where
Update: FnOnce(&mut MessageMetadata) -> R,
Updates the metadata of a vertex.