fork download
  1. importPackage(java.io);
  2. importPackage(java.lang);
  3.  
  4. // your code goes here
  5. // Solidity smart contract code
  6. // SPDX-License-Identifier: MIT
  7. pragma solidity ^0.8.0;
  8.  
  9. contract RealEstate {
  10. struct Property {
  11. string name;
  12. uint price;
  13. address[] owners;
  14. uint[] ownership;
  15. }
  16.  
  17. mapping(uint => Property) public properties;
  18. mapping(uint => mapping(address => uint)) public ownerships;
  19.  
  20. function createProperty(uint id, string memory name, uint price) public {
  21. properties[id] = Property(name, price, new address[](0), new uint[](0));
  22. }
  23.  
  24. function buyOwnership(uint id, uint percentage) public payable {
  25. require(properties[id].price * percentage / 100 == msg.value, "Incorrect value sent");
  26. require(percentage > 0 && percentage <= 100, "Invalid percentage");
  27.  
  28. uint ownership = properties[id].ownership.length;
  29. properties[id].ownership.push(percentage);
  30. properties[id].owners.push(msg.sender);
  31. ownerships[id][msg.sender] = ownership;
  32. }
  33.  
  34. function sellOwnership(uint id, uint percentage) public {
  35. uint index = ownerships[id][msg.sender];
  36. require(properties[id].ownership[index] == percentage, "Ownership percentage mismatch");
  37. require(percentage > 0 && percentage <= 100, "Invalid percentage");
  38.  
  39. uint value = properties[id].price * percentage / 100;
  40. properties[id].ownership[index] = 0;
  41. ownerships[id][msg.sender] = 0;
  42. properties[id].owners[index] = properties[id].owners[properties[id].owners.length - 1];
  43. properties[id].owners.pop();
  44.  
  45. (bool success, ) = payable(msg.sender).call{value: value}("");
  46. require(success, "Transfer failed.");
  47. }
  48. }
Runtime error #stdin #stdout #stderr 0.34s 38672KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: "prog.js", line 7: missing ; before statement
js: pragma solidity ^0.8.0;
js: ...............^
js: "prog.js", line 9: missing ; before statement
js: contract RealEstate {
js: ...................^
js: "prog.js", line 10: missing ; before statement
js:     struct Property {
js: ....................^
js: "prog.js", line 12: missing ; before statement
js:         uint price;
js: ..................^
js: "prog.js", line 13: syntax error
js:         address[] owners;
js: ................^
js: "prog.js", line 14: syntax error
js:         uint[] ownership;
js: .............^
js: "prog.js", line 15: syntax error
js:     }
js: ....^
js: "prog.js", line 17: missing ; before statement
js:     mapping(uint => Property) public properties;
js: ....................................^
js: "prog.js", line 18: missing ; before statement
js:     mapping(uint => mapping(address => uint)) public ownerships;
js: ....................................................^
js: "prog.js", line 20: missing ) after formal parameters
js:     function createProperty(uint id, string memory name, uint price) public {
js: ...................................^
js: "prog.js", line 1: Compilation produced 10 syntax errors.