Nik_Perepelov

Сука, солидити

Nov 17th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. pragma solidity >=0.5.0 <0.5.12;
  2. pragma experimental ABIEncoderV2;
  3. contract Goods{
  4. //Поля контракта
  5. //Стоимость товара
  6. uint24 cost;
  7. //Количество товара
  8. uint24 num_of_Goods;
  9. //Название товара
  10. string name;
  11. //Конструктор - вызывается при создании контракта
  12. constructor (uint24 en_cost, uint24 en_num, string memory en_name) public{
  13. cost = en_cost;
  14. num_of_Goods = en_num;
  15. name = en_name;
  16. }
  17. function getCost() public view returns(uint24){
  18. return cost;
  19. }
  20. function getNumOfGoods() public view returns(uint24){
  21. return num_of_Goods;
  22. }
  23. function getName() public view returns(string memory){
  24. return name;
  25. }
  26. function addNum(uint24 add_num){
  27. num_of_Goods += add_num;
  28. }
  29. }
  30.  
  31. //Делаем контракт для создания корзины пользователя
  32. contract Cart{
  33. //Храним адрес владельца корзины
  34. address private owner;
  35. //Список товаров.
  36. address[] private list_of_goods;
  37. //Товар - его количество
  38. mapping(address => uint24) count_of_goods;
  39. uint32 sum_of_cart = 0;
  40.  
  41. //Создаем конструктор, который вытаскивает
  42. //Отправителя транзакции и делает его
  43. //Владельцем корзины
  44. constructor () public {
  45. owner = msg.sender;
  46. }
  47.  
  48. //Проверка хозяина
  49. function getOwner() public view returns(address){
  50. return owner;
  51. }
  52.  
  53. //Добавляем в словарь(map) нужное количество товаров
  54. //Обращение по адресу товара в сети
  55. function addGoods(address Goods_addr, uint24 count) public {
  56. count_of_goods[Goods_addr] += count;
  57. //Вытащить цену на лекарство
  58. //И рассчитать новую сумму за корзину
  59. //Создаем объект Goods по его адресу
  60. Goods tmp_good = Goods(Goods_addr);
  61. sum_of_cart += count * tmp_good.getCost();
  62. }
  63.  
  64. function getCartCost() public view returns(uint32){
  65. return sum_of_cart;
  66. }
  67.  
  68. function checkGoods(address Goods_addr) public view returns(uint24){
  69. return count_of_goods[Goods_addr];
  70. }
  71. }
  72.  
  73. contract Bill{
  74. //Кому чек выписываем
  75. address private buyer;
  76. //Временное поле - баланс клиента
  77. uint32 tempory_balance;
  78. constructor () public{
  79. buyer = msg.sender;
  80. }
  81. //Для демонстрации
  82. function setBalance(uint32 tmp_balace) public {
  83. tempory_balance = tmp_balace;
  84. }
  85. function make_a_bill(address addr_cart) public returns(string memory) {
  86. Cart tmp_cart = Cart(addr_cart);
  87. if (tempory_balance - tmp_cart.getCartCost() >= 0){
  88.  
  89. } else {
  90.  
  91. }
  92. }
  93. }
  94.  
  95. /*Интерфейс работы с аптекой*/
  96. contract Apteka{
  97. //Храним адреса контрактов с товаром
  98. address[] private ListOfGoods;
  99. uint24 budget = 0;
  100. address owner;
  101. constructor(uint24 start_capital) public{
  102. //Мы храним адреса контрактов типа "Товар"
  103. //ListOfGoods.push(address(new Goods(100, 10, "Fenotropil")));
  104. owner = msg.sender;
  105. budget = start_capital;
  106. }
  107.  
  108. //добавление товара
  109. funcrion addGood(uint24 cost_of_good, uint24 num_of_good, string memory name_of_good) public{
  110. require(owner == msg.sender);
  111. uint24 is_exists = -1;
  112. for (uint24 i = 0; i < ListOfGoods.length; i++){
  113. if (Goods(ListOfGoods[i]).getName() == name_of_good){
  114. is_exists = i;
  115. }
  116. }
  117.  
  118. if (is_exists == -1){
  119. ListOfGoods.push(address(new Goods(cost_of_good, num_of_good, name_of_good)));
  120. }
  121. else{
  122. ListOfGoods[i]
  123. }
  124. }
  125.  
  126. function getProdutcs() public view returns(address[] memory){
  127. return ListOfGoods;
  128. }
  129. //Получаем информацию о товаре по адресу
  130. function getGoodsInfo(address _prod) public view returns(string memory, uint24){
  131. //Создаем временный контракт по адресу оригинала
  132. Goods tmp = Goods(_prod);
  133. return (tmp.getName(), tmp.getCost());
  134. }
  135. function getAllInfo() public view returns(string[] memory, uint24[] memory){
  136. string[] memory tmp_str = new string[](ListOfGoods.length);
  137. uint24[] memory tmp_price = new uint24[](ListOfGoods.length);
  138. for (uint24 i = 0; i < ListOfGoods.length; i++){
  139. tmp_str[i] = Goods(ListOfGoods[i]).getName();
  140. tmp_price[i] = Goods(ListOfGoods[i]).getCost();
  141. }
  142. return (tmp_str, tmp_price);
  143. }
  144. }
Add Comment
Please, Sign In to add comment