summary refs log tree commit diff stats
path: root/contract
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-25 16:49:01 +0530
committerAndinus <andinus@nand.sh>2021-09-25 16:49:01 +0530
commit7b1334ade193f4ffabfb235f99329f2f70e7bb7c (patch)
tree32be4da8709221d640079f8e07835b24fbdac9b5 /contract
parent528e15ada7d970da29fed2fe385b4ddec70797e3 (diff)
downloadMyMedMemoir-7b1334ade193f4ffabfb235f99329f2f70e7bb7c.tar.gz
Move records to big_map, add update and delete functions, add tests
Diffstat (limited to 'contract')
-rw-r--r--contract/memoir.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/contract/memoir.py b/contract/memoir.py
index 792274b..c33c155 100644
--- a/contract/memoir.py
+++ b/contract/memoir.py
@@ -3,14 +3,23 @@ import smartpy as sp
 class Memoir(sp.Contract):
     def __init__(self):
         self.init(
-            dates = sp.list([]),
-            records = sp.list([])
+            records = sp.big_map(
+                tkey = sp.TInt,
+                tvalue = sp.TString
+            ),
         )
 
     @sp.entry_point
     def add_record(self, params):
-        self.data.dates.push(sp.now)
-        self.data.records.push(params.record)
+        self.data.records[params.id] = params.record
+
+    @sp.entry_point
+    def update_record(self, params):
+        self.data.records = sp.update_map(self.data.records, params.id, sp.some(params.record))
+
+    @sp.entry_point
+    def delete_record(self, params):
+        del self.data.records[params.id]
 
 @sp.add_test(name="MyMedMemoir")
 def test():
@@ -19,5 +28,8 @@ def test():
 
     c1 = Memoir()
     scenario += c1
-    scenario += c1.add_record(record = '{record #1}')
-    scenario += c1.add_record(record = '{record #2}')
+    scenario += c1.add_record(id = 0, record = '{record #0}')
+    scenario += c1.add_record(id = 1, record = '{record #1}')
+    scenario += c1.add_record(id = 2, record = '{record #2}')
+    scenario += c1.update_record(id = 1, record = '{record #1 - updated}')
+    scenario += c1.delete_record(id = 2)