github.com/metacurrency/holochain@v0.1.0-alpha-26.0.20200915073418-5c83169c9b5b/zome.go (about)

     1  // Copyright (C) 2013-2017, The MetaCurrency Project (Eric Harris-Braun, Arthur Brock, et. al.)
     2  // Use of this source code is governed by GPLv3 found in the LICENSE file
     3  //----------------------------------------------------------------------------------------
     4  
     5  package holochain
     6  
     7  import (
     8  	"errors"
     9  )
    10  
    11  // Zome struct encapsulates logically related code, from a "chromosome"
    12  type Zome struct {
    13  	Name         string
    14  	Description  string
    15  	Code         string
    16  	Entries      []EntryDef
    17  	RibosomeType string
    18  	Functions    []FunctionDef
    19  	BridgeFuncs  []string // functions in zome that can be bridged to by callerApp
    20  	//	BridgeCallee Hash     // dna Hash of provider App that this zome will call
    21  	Config map[string]interface{}
    22  }
    23  
    24  // GetEntryDef returns the entry def structure
    25  func (z *Zome) GetEntryDef(entryName string) (e *EntryDef, err error) {
    26  	for _, def := range z.Entries {
    27  		if def.Name == entryName {
    28  			e = &def
    29  			break
    30  		}
    31  	}
    32  	if e == nil {
    33  		err = errors.New("no definition for entry type: " + entryName)
    34  	}
    35  	return
    36  }
    37  
    38  func (z *Zome) GetPrivateEntryDefs() (privateDefs []EntryDef) {
    39  	privateDefs = make([]EntryDef, 0)
    40  	for _, def := range z.Entries {
    41  		if def.Sharing == Private {
    42  			privateDefs = append(privateDefs, def)
    43  		}
    44  	}
    45  	return
    46  }
    47  
    48  // GetFunctionDef returns the exposed function spec for the given zome and function
    49  func (zome *Zome) GetFunctionDef(fnName string) (fn *FunctionDef, err error) {
    50  	for _, f := range zome.Functions {
    51  		if f.Name == fnName {
    52  			fn = &f
    53  			break
    54  		}
    55  	}
    56  	if fn == nil {
    57  		err = errors.New("unknown exposed function: " + fnName)
    58  	}
    59  	return
    60  }
    61  
    62  func (zome *Zome) MakeRibosome(h *Holochain) (r Ribosome, err error) {
    63  	r, err = CreateRibosome(h, zome)
    64  	return
    65  }
    66  
    67  func (zome *Zome) CodeFileName() string {
    68  	if zome.RibosomeType == ZygoRibosomeType {
    69  		return zome.Name + ".zy"
    70  	} else if zome.RibosomeType == JSRibosomeType {
    71  		return zome.Name + ".js"
    72  	}
    73  	panic("unknown ribosome type:" + zome.RibosomeType)
    74  }