Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const contract = fileSystem.readFileSync("./contract.sol").toString("utf-8");
- console.log(contract);
- // output
- contract StringContainer {
- string[] public listOfStrings;
- StringUtils utils = new StringUtils();
- function add(string memory newString) returns (bool success){
- for(uint index=0;index<listOfStrings.length;index++) {
- if(utils.equals(listOfStrings[index], newString)){
- return false;
- }
- }
- listOfStrings.push(newString);
- return true;
- }
- }
- contract StringUtils {
- function equals(string memory first,string memory second) constant returns (bool areEqual){
- bytes memory bytesFirst = bytes(first);
- bytes memory bytesSecond = bytes(second);
- if(bytesFirst.length != bytesSecond.length){
- return false;
- } else {
- for (uint i = 0; i < bytesFirst.length; i++)
- if (bytesFirst[i] != bytesSecond[i])
- return false;
- }
- return true;
- }
- }
- Example app listening on port 3000!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement