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