Guest User

Untitled

a guest
Feb 3rd, 2019
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [%%version 0.5]
  2.  
  3. type storage = {
  4. usersDocuments : (address,address set) big_map;
  5. documents: string set;
  6. }
  7.  
  8. let%init storage : storage = {
  9. usersDocuments = BigMap;
  10. documents = Set;
  11. }
  12.  
  13. contract Document = struct
  14.  
  15. type storage = string * address * address set * address set
  16.  
  17.  
  18. let%entry main () storage =
  19. [],storage
  20.  
  21. let%entry sign () storage =
  22. let (hash, owner, signs, access) = storage in
  23. let userAddress = Current.sender() in
  24. if not(Set.mem userAddress access) then failwith ("Sign not alowed");
  25. if Set.mem userAddress signs then failwith ("sign already exist");
  26.  
  27. let signs = Set.add userAddress signs in
  28. [], (hash, owner, signs, access)
  29.  
  30. let%entry addAccess (user:address) storage =
  31. let (hash, owner, signs, access) = storage in
  32. let userAddress = Current.sender() in
  33. if owner <> userAddress then failwith "you not owner";
  34. let access = Set.add user access in
  35.  
  36. [], (hash, owner, signs, access)
  37.  
  38. let%entry removeAccess (user:address) storage =
  39. let (hash, owner, signs, access) = storage in
  40. let userAddress = Current.sender() in
  41. if owner <> userAddress then failwith "you not owner";
  42. let access = Set.remove user access in
  43. [], (hash, owner, signs, access)
  44.  
  45. end
  46.  
  47.  
  48. let%entry createFile ((fileHash : string),(manager:key_hash)) storage =
  49. let userAddress = Current.sender() in
  50. if Set.mem fileHash storage.documents then
  51. failwith "sorry file exist use him api";
  52.  
  53. let (createContractOp,docAddress) =
  54. Contract.create
  55. ~storage: (fileHash,userAddress,Set,Set)
  56. ~manager:manager
  57. ~spendable:true
  58. ~delegatable:true
  59. ~delegate:(None)
  60. ~amount:0tz (contract Document)
  61. in
  62.  
  63. let userDocuments = match Map.find userAddress storage.usersDocuments with
  64. | None -> Set
  65. | Some docSotrage -> docSotrage
  66. in
  67. let userDocuments = Set.add docAddress userDocuments in
  68.  
  69. let documents = Set.add fileHash storage.documents in
  70. let usersDocuments = Map.add userAddress userDocuments storage.usersDocuments in
  71.  
  72. let storage = storage.usersDocuments <- usersDocuments in
  73. let storage = storage.documents <- documents in
  74.  
  75. [ createContractOp], storage
  76.  
  77.  
  78. let%entry main () storage =
  79. ([], storage)
RAW Paste Data