Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. const contract = fileSystem.readFileSync("./contract.sol").toString("utf-8");
  2. console.log(contract);
  3.  
  4. // output
  5. contract StringContainer {
  6.  
  7. string[] public listOfStrings;
  8. StringUtils utils = new StringUtils();
  9.  
  10.  
  11. function add(string memory newString) returns (bool success){
  12.  
  13. for(uint index=0;index<listOfStrings.length;index++) {
  14. if(utils.equals(listOfStrings[index], newString)){
  15. return false;
  16. }
  17. }
  18.  
  19. listOfStrings.push(newString);
  20. return true;
  21. }
  22.  
  23. }
  24.  
  25.  
  26. contract StringUtils {
  27.  
  28. function equals(string memory first,string memory second) constant returns (bool areEqual){
  29. bytes memory bytesFirst = bytes(first);
  30. bytes memory bytesSecond = bytes(second);
  31.  
  32. if(bytesFirst.length != bytesSecond.length){
  33. return false;
  34. } else {
  35. for (uint i = 0; i < bytesFirst.length; i++)
  36. if (bytesFirst[i] != bytesSecond[i])
  37. return false;
  38. }
  39.  
  40. return true;
  41. }
  42.  
  43. }
  44. Example app listening on port 3000!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement