Created
August 6, 2018 14:15
-
-
Save webcaetano/48f178fde7d8082eb323f68ae18faf9a to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.22; | |
import './Utils.sol'; | |
contract bundinha is Utils { | |
uint N; | |
string bundinha; | |
function setN(uint x) public { | |
N = x; | |
} | |
function getN() constant public returns (uint) { | |
return N; | |
} | |
function setBundinha(string x) public { | |
require(strlen(x) <= 32); | |
bundinha = x; | |
} | |
function getBundinha() constant public returns (string){ | |
return bundinha; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.22; | |
contract Utils { | |
function Utils() public { | |
} | |
// function compareStrings (string a, string b) view returns (bool){ | |
// return keccak256(a) == keccak256(b); | |
// } | |
// // verifies that an amount is greater than zero | |
// modifier greaterThanZero(uint256 _amount) { | |
// require(_amount > 0); | |
// _; | |
// } | |
// validates an address - currently only checks that it isn't null | |
modifier validAddress(address _address) { | |
require(_address != address(0)); | |
_; | |
} | |
// verifies that the address is different than this contract address | |
modifier notThis(address _address) { | |
require(_address != address(this)); | |
_; | |
} | |
function strlen(string s) internal pure returns (uint) { | |
// Starting here means the LSB will be the byte we care about | |
uint ptr; | |
uint end; | |
assembly { | |
ptr := add(s, 1) | |
end := add(mload(s), ptr) | |
} | |
for (uint len = 0; ptr < end; len++) { | |
uint8 b; | |
assembly { b := and(mload(ptr), 0xFF) } | |
if (b < 0x80) { | |
ptr += 1; | |
} else if(b < 0xE0) { | |
ptr += 2; | |
} else if(b < 0xF0) { | |
ptr += 3; | |
} else if(b < 0xF8) { | |
ptr += 4; | |
} else if(b < 0xFC) { | |
ptr += 5; | |
} else { | |
ptr += 6; | |
} | |
} | |
return len; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment