Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed Mar 21, 2020
1 parent c34d07c commit 11dd2e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,28 @@ impl OutputPosList {
}
Ok(())
}

/// Pop the head of the list.
/// Returns the output_pos.
/// Returns None if list was empty.
pub fn pop_entry(batch: &Batch<'_>, commit: Commitment) -> Result<Option<OutputPos>, Error> {
match Self::get_list(batch, commit)? {
None => Ok(None),
Some(OutputPosList::Unique { pos }) => {
// TODO - delete the list itself.

Ok(Some(pos))
}
Some(OutputPosList::Multi { head, tail }) => {
// read head from db
// read next one
// update next to a head if it was a middle
// update list head
// update list to a unique if next is a tail
Ok(None)
}
}
}
}

pub enum OutputPosEntry {
Expand Down
14 changes: 14 additions & 0 deletions chain/tests/store_output_pos_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ fn test_store_output_pos_list() {
Ok(Some(OutputPosList::Multi { head: 3, tail: 1 })),
);

assert_eq!(
OutputPosList::pop_entry(&batch, commit,),
Ok(Some(OutputPos {
pos: 3,
height: 3,
features: OutputFeatures::Plain,
})),
);

assert_eq!(
OutputPosList::get_list(&batch, commit),
Ok(Some(OutputPosList::Multi { head: 2, tail: 1 })),
);

// Cleanup chain directory
clean_output_dir(chain_dir);
}

0 comments on commit 11dd2e8

Please sign in to comment.