This repository has been 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 pathaction_migrate.go
103 lines (86 loc) · 2.42 KB
/
action_migrate.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (C) 2013-2018, 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 (
. "github.com/holochain/holochain-proto/hash"
peer "github.com/libp2p/go-libp2p-peer"
)
//------------------------------------------------------------
// Migrate Action
type ActionMigrate struct {
entry MigrateEntry
header *Header
}
func (a *ActionMigrate) Name() string {
return "migrate"
}
func (a *ActionMigrate) Entry() Entry {
j, err := a.entry.ToJSON()
if err != nil {
panic(err)
}
return &GobEntry{C: j}
}
func (a *ActionMigrate) EntryType() string {
return MigrateEntryType
}
func (a *ActionMigrate) SetHeader(header *Header) {
a.header = header
}
func (a *ActionMigrate) GetHeader() (header *Header) {
return a.header
}
func (action *ActionMigrate) Share(h *Holochain, def *EntryDef) (err error) {
err = h.dht.Change(action.header.EntryLink, PUT_REQUEST, HoldReq{EntryHash: action.header.EntryLink})
return
}
func (action *ActionMigrate) SysValidation(h *Holochain, def *EntryDef, pkg *Package, sources []peer.ID) (err error) {
// correct entry def
if def != MigrateEntryDef {
err = ErrEntryDefInvalid
return
}
// has a header
if action.header == nil {
err = ErrActionMissingHeader
return
}
// entry is valid
err = sysValidateEntry(h, def, action.Entry(), pkg)
// @TODO should migration only be valid if peer ID is node owner?
return
}
func (a *ActionMigrate) CheckValidationRequest(def *EntryDef) (err error) {
// intentionally left blank ;)
return
}
func (a *ActionMigrate) Receive(dht *DHT, msg *Message) (response interface{}, err error) {
// this is always an error because there is no action message for migrate
err = ErrActionReceiveInvalid
return
}
//------------------------------------------------------------
// Migrate API fn
type APIFnMigrate struct {
action ActionMigrate
}
func (fn *APIFnMigrate) Name() string {
return fn.action.Name()
}
func (fn *APIFnMigrate) Args() []Arg {
return []Arg{{Name: "migrationType",
Type: StringArg},
{Name: "DNAHash",
Type: HashArg},
{Name: "Key",
Type: HashArg},
{Name: "data",
Type: StringArg}}
}
func (fn *APIFnMigrate) Call(h *Holochain) (response interface{}, err error) {
var hash Hash
response, err = h.commitAndShare(&fn.action, hash)
return
}