Caesar21

Untitled

Sep 12th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. pragma solidity ^0.4.21;
  2.  
  3. contract asus{
  4.  
  5. //表示授權多久&授權區間
  6. struct Authorized_times {
  7. uint Time_begin;
  8. uint Time_end;
  9. uint Begin_date;
  10. uint End_date;
  11. }
  12.  
  13. address public chairperson;
  14.  
  15. //映射關係,從address->apps'id->data category->時間
  16. mapping (address => mapping(string => mapping(string => Authorized_times))) users;
  17.  
  18. constructor() public{
  19. chairperson = msg.sender;
  20. }
  21.  
  22. //創建使用者給APP的授權
  23. function Creating_authorization(address blockchain_address, string app_id, string data_category, uint time_num, uint begin_date, uint end_date) public {
  24. require(
  25. msg.sender == blockchain_address,
  26. "You can only authorize your own account. "
  27. );
  28. users[blockchain_address][app_id][data_category].Time_begin = now;
  29. users[blockchain_address][app_id][data_category].Time_end = now + time_num * 1 days;
  30. users[blockchain_address][app_id][data_category].Begin_date = begin_date;
  31. users[blockchain_address][app_id][data_category].End_date = end_date;
  32. }
  33.  
  34. //修改授權的效期時間
  35. function Modifying_authorization_time_period(address blockchain_address, string app_id, string data_category, uint time_num) public {
  36. require(
  37. msg.sender == blockchain_address,
  38. "You can only modify authorization on your own account. "
  39. );
  40. users[blockchain_address][app_id][data_category].Time_begin = now;
  41. users[blockchain_address][app_id][data_category].Time_end = now + time_num * 1 days;
  42. }
  43.  
  44. //修改授權的起止時間
  45. function Modifying_authorization_time_expiration(address blockchain_address, string app_id, string data_category, uint begin_date, uint end_date) public {
  46. require(
  47. msg.sender == blockchain_address,
  48. "You can only modify authorization on your own account. "
  49. );
  50. users[blockchain_address][app_id][data_category].Begin_date = begin_date;
  51. users[blockchain_address][app_id][data_category].End_date = end_date;
  52. }
  53.  
  54. //查看授權的效期時間
  55. function Get_time_period(address blockchain_address, string app_id, string data_category) public returns(uint t_begin, uint t_end) {
  56. require(
  57. msg.sender == blockchain_address,
  58. "You can only get your own account's message. "
  59. );
  60. return (users[blockchain_address][app_id][data_category].Time_begin, users[blockchain_address][app_id][data_category].Time_end);
  61. }
  62.  
  63. //查看授權的起止時間
  64. function Get_time_expiration(address blockchain_address, string app_id, string data_category) public returns(uint d_begin, uint d_end) {
  65. require(
  66. msg.sender == blockchain_address,
  67. "You can only get your own account's message. "
  68. );
  69. return (users[blockchain_address][app_id][data_category].Begin_date, users[blockchain_address][app_id][data_category].End_date);
  70. }
  71.  
  72.  
  73.  
  74. //判斷對APP是否有授權
  75. function Verifying_user_authorization(address blockchain_address, string app_id, string data_category, uint date_begin, uint date_end) public returns(bool){
  76. bool result = false;
  77. if(now >= users[blockchain_address][app_id][data_category].Time_begin && now <= users[blockchain_address][app_id][data_category].Time_end)
  78. {
  79. if(date_begin >= users[blockchain_address][app_id][data_category].Begin_date && date_end <= users[blockchain_address][app_id][data_category].End_date
  80. && date_begin <= date_end)
  81. {
  82. result = true;
  83. }
  84. }
  85.  
  86. return result;
  87. }
  88.  
  89. }
Add Comment
Please, Sign In to add comment