forked from holochain/holochain-proto
/
entry_del.go
68 lines (62 loc) · 1.34 KB
/
entry_del.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
package holochain
import (
"encoding/json"
. "github.com/holochain/holochain-proto/hash"
)
const (
DelEntryType = SysEntryTypePrefix + "del"
DelEntrySchema = `
{
"$id": "http://example.com/example.json",
"type": "object",
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"Hash": {
"$id": "/properties/Hash",
"type": "string",
"title": "The Hash Schema ",
"default": ""
},
"Message": {
"$id": "/properties/message",
"type": "string",
"title": "The Message Schema ",
"default": ""
}
},
"required": ["Hash"]
}
`
)
// DelEntry struct holds the record of an entry's deletion
type DelEntry struct {
Hash Hash
Message string
}
var DelEntryDef = &EntryDef{Name: DelEntryType, DataFormat: DataFormatJSON, Sharing: Public, Schema: DelEntrySchema}
func (e *DelEntry) ToJSON() (encodedEntry string, err error) {
var x struct {
Hash string
Message string
}
x.Hash = e.Hash.String()
x.Message = e.Message
var j []byte
j, err = json.Marshal(x)
encodedEntry = string(j)
return
}
func DelEntryFromJSON(j string) (entry DelEntry, err error) {
var x struct {
Hash string
Message string
}
err = json.Unmarshal([]byte(j), &x)
if err != nil {
return
}
entry.Message = x.Message
entry.Hash, err = NewHash(x.Hash)
return
}