@@ -11,6 +11,13 @@ class notary_actor(JSBASE):
11
11
def start_page (self ):
12
12
return "welcome to https://github.com/threefoldtech/home/issues/135"
13
13
14
+ def bcdb_get (self ):
15
+ zdb_cl = j .clients .zdb .start_test_instance ()
16
+ zdb_cl = zdb_cl .namespace_new ("notary_namespace" , secret = "1234" )
17
+ bcdb = j .data .bcdb .new (zdbclient = zdb_cl , name = "notary_bcdb" )
18
+ bcdb .models_add ("/sandbox/code/github/threefoldtech/digitalmeX/packages/notary/models" )
19
+ return bcdb
20
+
14
21
def register (self , robot_id , key , content , content_signature , schema_out ):
15
22
"""
16
23
```in
@@ -24,6 +31,15 @@ def register(self, robot_id, key, content, content_signature, schema_out):
24
31
```
25
32
"""
26
33
out = schema_out .new ()
34
+ bcdb = self .bcdb_get ()
35
+ model = bcdb .models .get ("threefold.grid.notary" )
36
+ model_obj = model .new ()
37
+ model_obj .robot_id = robot_id
38
+ model_obj .key = key
39
+ model_obj .content = content
40
+ model_obj .content_signature = content_signature
41
+ model_obj .save ()
42
+
27
43
out .message = "your register info is robot_id = {} , key = {}, content = {} ,content_signature ={}" .format (
28
44
robot_id , key , content , content_signature )
29
45
return out
@@ -38,21 +54,29 @@ def get(self, key, schema_out):
38
54
```
39
55
"""
40
56
out = schema_out .new ()
41
- # TODO: return json object
42
- out .message = "your key is {}" .format (key )
57
+ bcdb = self .bcdb_get ()
58
+ for model in bcdb .get_all ():
59
+ if model .key == key :
60
+ return model
61
+
62
+ out .message = "this key doesn't exist"
43
63
return out
44
64
45
- def delete (self , robot_id , key , key_signature , schema_out ):
65
+ def delete (self , robot_id , key , content_signature , schema_out ):
46
66
"""
47
67
```in
48
68
robot_id = "" (S)
49
69
key = "" (S)
50
- key_signature = "" (S)
70
+ content_signature = "" (S)
51
71
```
52
72
```out
53
73
message = "" (S)
54
74
```
55
- """
56
- out = schema_out .new ()
57
- # TODO: return true if success deleted from zdb otherwise return false
75
+ """
76
+ bcdb = self .bcdb_get ()
77
+ for model in bcdb .get_all ():
78
+ if model .key == key and model .robot_id == robot_id and model .content_signature == content_signature :
79
+ model .delete ()
80
+ model .save ()
81
+ return "True"
58
82
return "False"
0 commit comments