// Return the instance, properly unmarshaled, given the entry in the database, which is // the hash for the Instance (vv) followed by the source from which to unmarshal (v) func (d *BoltDB) GetInstance(v []byte) fct.IBlock { var vv [32]byte copy(vv[:], v[:32]) v = v[32:] var instance fct.IBlock = d.instances[vv] if instance == nil { vp := fct.NewHash(vv[:]) fct.Prtln("Object hash: ", vp) panic("This should not happen. Object stored in the database has no IBlock instance") } r := instance.GetNewInstance() if r == nil { panic("An IBlock has failed to implement GetNewInstance()") } datalen, v := binary.BigEndian.Uint32(v[0:4]), v[4:] if len(v) != int(datalen) { fct.Prtln("Lengths don't match. Expected ", datalen, " and got ", len(v)) panic("Data not returned properly") } err := r.UnmarshalBinary(v) if err != nil { panic("This should not happen. IBlock failed to unmarshal.") } return r }