holochain-rust icon indicating copy to clipboard operation
holochain-rust copied to clipboard

impossible states: `EntryWithHeader` to `ChainItem`

Open thedavidmeister opened this issue 6 years ago • 2 comments

in the spirit of impossible states

EntryWithHeader is any entry any header

impl EntryWithHeader {
    pub fn new(entry: Entry, header: ChainHeader) -> EntryWithHeader {
        EntryWithHeader { entry, header }
    }
}

we ?always? want a specific header/entry combo (the header in a chain and the entry referenced and hashed by the header)

name suggestions:

  • ChainItem
  • ChainLink
  • ChainPair
  • ChainJoint

a ChainFoo::new() should fail if the ChainHeader.entry_address() does not match Entry.address()

ideally a seq of ChainFoo structs could be validated (individual integrity and valid ordering/references)

a ChainFoo uses a simple tuple structure (for easy destructuring) and is immutable:

pub struct ChainFoo(ChainHeader, Entry);

impl ChainFoo {

  pub fn new(header: ChainHeader, entry: Entry) -> Result<ChainFoo, HolochainError> {
    if header.entry().address() = entry.address() {
      Ok(ChainFoo(header, entry))
    }
    else {
      Err(HolochainError::InternalError("Header/Entry mismatch"))
    }
  }

  pub fn header(&self) -> ChainHeader {
    self.0.clone()
  }

  pub fn entry(&self) -> Entry {
    self.1.clone()
  }

}

thedavidmeister avatar Feb 03 '19 14:02 thedavidmeister

sure, some sanity checks/assertions with useful error messages never hurt anybody :)

thedavidmeister avatar Nov 13 '19 08:11 thedavidmeister