contract_name
stringlengths
1
61
file_path
stringlengths
5
50.4k
contract_address
stringlengths
42
42
language
stringclasses
1 value
class_name
stringlengths
1
61
class_code
stringlengths
4
330k
class_documentation
stringlengths
0
29.1k
class_documentation_type
stringclasses
6 values
func_name
stringlengths
0
62
func_code
stringlengths
1
303k
func_documentation
stringlengths
2
14.9k
func_documentation_type
stringclasses
4 values
compiler_version
stringlengths
15
42
license_type
stringclasses
14 values
swarm_source
stringlengths
0
71
meta
dict
__index_level_0__
int64
0
60.4k
MultiVesting
MultiVesting.sol
0x66e9aeedc17558cfc97b6734600b7a835f8e7ceb
Solidity
MultiVesting
contract MultiVesting is Ownable, Destroyable { using SafeMath for uint256; // beneficiary of tokens struct Beneficiary { uint256 released; uint256 vested; uint256 start; uint256 cliff; uint256 duration; bool revoked; bool revocable; bool isBeneficiary; } event Released(address _beneficiary, uint256 amount); event Revoked(address _beneficiary); event NewBeneficiary(address _beneficiary); event BeneficiaryDestroyed(address _beneficiary); mapping(address => Beneficiary) public beneficiaries; Token public token; uint256 public totalVested; uint256 public totalReleased; /* * Modifiers */ modifier isNotBeneficiary(address _beneficiary) { require(!beneficiaries[_beneficiary].isBeneficiary); _; } modifier isBeneficiary(address _beneficiary) { require(beneficiaries[_beneficiary].isBeneficiary); _; } modifier wasRevoked(address _beneficiary) { require(beneficiaries[_beneficiary].revoked); _; } modifier wasNotRevoked(address _beneficiary) { require(!beneficiaries[_beneficiary].revoked); _; } /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until _start + _duration. By then all * of the balance will have vested. * @param _token address of the token of vested tokens */ function MultiVesting(address _token) public { require(_token != address(0)); token = Token(_token); } function() payable public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary (alternative to fallback function). */ function release() public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function release(address _beneficiary) private isBeneficiary(_beneficiary) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 unreleased = releasableAmount(_beneficiary); require(unreleased > 0); beneficiary.released = beneficiary.released.add(unreleased); totalReleased = totalReleased.add(unreleased); token.transfer(_beneficiary, unreleased); if((beneficiary.vested - beneficiary.released) == 0){ beneficiary.isBeneficiary = false; } Released(_beneficiary, unreleased); } /** * @notice Allows the owner to transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function releaseTo(address _beneficiary) public onlyOwner { release(_beneficiary); } /** * @dev Add new beneficiary to start vesting * @param _beneficiary address of the beneficiary to whom vested tokens are transferred * @param _start time in seconds which the tokens will vest * @param _cliff time in seconds of the cliff in which tokens will begin to vest * @param _duration duration in seconds of the period in which the tokens will vest * @param _revocable whether the vesting is revocable or not */ function addBeneficiary(address _beneficiary, uint256 _vested, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) onlyOwner isNotBeneficiary(_beneficiary) public { require(_beneficiary != address(0)); require(_cliff >= _start); require(token.balanceOf(this) >= totalVested.sub(totalReleased).add(_vested)); beneficiaries[_beneficiary] = Beneficiary({ released : 0, vested : _vested, start : _start, cliff : _cliff, duration : _duration, revoked : false, revocable : _revocable, isBeneficiary : true }); totalVested = totalVested.add(_vested); NewBeneficiary(_beneficiary); } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. * @param _beneficiary Beneficiary address */ function revoke(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; require(beneficiary.revocable); require(!beneficiary.revoked); uint256 balance = beneficiary.vested.sub(beneficiary.released); uint256 unreleased = releasableAmount(_beneficiary); uint256 refund = balance.sub(unreleased); token.transfer(owner, refund); totalReleased = totalReleased.add(refund); beneficiary.revoked = true; beneficiary.released = beneficiary.released.add(refund); Revoked(_beneficiary); } /** * @notice Allows the owner to destroy a beneficiary. Remain tokens are returned to the owner. * @param _beneficiary Beneficiary address */ function destroyBeneficiary(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 balance = beneficiary.vested.sub(beneficiary.released); token.transfer(owner, balance); totalReleased = totalReleased.add(balance); beneficiary.isBeneficiary = false; beneficiary.released = beneficiary.released.add(balance); BeneficiaryDestroyed(_beneficiary); } /** * @dev Calculates the amount that has already vested but hasn't been released yet. * @param _beneficiary Beneficiary address */ function releasableAmount(address _beneficiary) public view returns (uint256) { return vestedAmount(_beneficiary).sub(beneficiaries[_beneficiary].released); } /** * @dev Calculates the amount that has already vested. * @param _beneficiary Beneficiary address */ function vestedAmount(address _beneficiary) public view returns (uint256) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 totalBalance = beneficiary.vested; if (now < beneficiary.cliff) { return 0; } else if (now >= beneficiary.start.add(beneficiary.duration) || beneficiary.revoked) { return totalBalance; } else { return totalBalance.mul(now.sub(beneficiary.start)).div(beneficiary.duration); } } /** * @notice Allows the owner to flush the eth. */ function flushEth() public onlyOwner { owner.transfer(this.balance); } /** * @notice Allows the owner to destroy the contract and return the tokens to the owner. */ function destroy() public onlyOwner { token.transfer(owner, token.balanceOf(this)); selfdestruct(owner); } }
destroyBeneficiary
function destroyBeneficiary(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 balance = beneficiary.vested.sub(beneficiary.released); token.transfer(owner, balance); totalReleased = totalReleased.add(balance); beneficiary.isBeneficiary = false; beneficiary.released = beneficiary.released.add(balance); BeneficiaryDestroyed(_beneficiary); }
/** * @notice Allows the owner to destroy a beneficiary. Remain tokens are returned to the owner. * @param _beneficiary Beneficiary address */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://bd1d9802790e0281240ddbd34fb7e404a0dc8500b3639c2b04a8a6c42f0133ab
{ "func_code_index": [ 5240, 5725 ] }
56,261
MultiVesting
MultiVesting.sol
0x66e9aeedc17558cfc97b6734600b7a835f8e7ceb
Solidity
MultiVesting
contract MultiVesting is Ownable, Destroyable { using SafeMath for uint256; // beneficiary of tokens struct Beneficiary { uint256 released; uint256 vested; uint256 start; uint256 cliff; uint256 duration; bool revoked; bool revocable; bool isBeneficiary; } event Released(address _beneficiary, uint256 amount); event Revoked(address _beneficiary); event NewBeneficiary(address _beneficiary); event BeneficiaryDestroyed(address _beneficiary); mapping(address => Beneficiary) public beneficiaries; Token public token; uint256 public totalVested; uint256 public totalReleased; /* * Modifiers */ modifier isNotBeneficiary(address _beneficiary) { require(!beneficiaries[_beneficiary].isBeneficiary); _; } modifier isBeneficiary(address _beneficiary) { require(beneficiaries[_beneficiary].isBeneficiary); _; } modifier wasRevoked(address _beneficiary) { require(beneficiaries[_beneficiary].revoked); _; } modifier wasNotRevoked(address _beneficiary) { require(!beneficiaries[_beneficiary].revoked); _; } /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until _start + _duration. By then all * of the balance will have vested. * @param _token address of the token of vested tokens */ function MultiVesting(address _token) public { require(_token != address(0)); token = Token(_token); } function() payable public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary (alternative to fallback function). */ function release() public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function release(address _beneficiary) private isBeneficiary(_beneficiary) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 unreleased = releasableAmount(_beneficiary); require(unreleased > 0); beneficiary.released = beneficiary.released.add(unreleased); totalReleased = totalReleased.add(unreleased); token.transfer(_beneficiary, unreleased); if((beneficiary.vested - beneficiary.released) == 0){ beneficiary.isBeneficiary = false; } Released(_beneficiary, unreleased); } /** * @notice Allows the owner to transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function releaseTo(address _beneficiary) public onlyOwner { release(_beneficiary); } /** * @dev Add new beneficiary to start vesting * @param _beneficiary address of the beneficiary to whom vested tokens are transferred * @param _start time in seconds which the tokens will vest * @param _cliff time in seconds of the cliff in which tokens will begin to vest * @param _duration duration in seconds of the period in which the tokens will vest * @param _revocable whether the vesting is revocable or not */ function addBeneficiary(address _beneficiary, uint256 _vested, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) onlyOwner isNotBeneficiary(_beneficiary) public { require(_beneficiary != address(0)); require(_cliff >= _start); require(token.balanceOf(this) >= totalVested.sub(totalReleased).add(_vested)); beneficiaries[_beneficiary] = Beneficiary({ released : 0, vested : _vested, start : _start, cliff : _cliff, duration : _duration, revoked : false, revocable : _revocable, isBeneficiary : true }); totalVested = totalVested.add(_vested); NewBeneficiary(_beneficiary); } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. * @param _beneficiary Beneficiary address */ function revoke(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; require(beneficiary.revocable); require(!beneficiary.revoked); uint256 balance = beneficiary.vested.sub(beneficiary.released); uint256 unreleased = releasableAmount(_beneficiary); uint256 refund = balance.sub(unreleased); token.transfer(owner, refund); totalReleased = totalReleased.add(refund); beneficiary.revoked = true; beneficiary.released = beneficiary.released.add(refund); Revoked(_beneficiary); } /** * @notice Allows the owner to destroy a beneficiary. Remain tokens are returned to the owner. * @param _beneficiary Beneficiary address */ function destroyBeneficiary(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 balance = beneficiary.vested.sub(beneficiary.released); token.transfer(owner, balance); totalReleased = totalReleased.add(balance); beneficiary.isBeneficiary = false; beneficiary.released = beneficiary.released.add(balance); BeneficiaryDestroyed(_beneficiary); } /** * @dev Calculates the amount that has already vested but hasn't been released yet. * @param _beneficiary Beneficiary address */ function releasableAmount(address _beneficiary) public view returns (uint256) { return vestedAmount(_beneficiary).sub(beneficiaries[_beneficiary].released); } /** * @dev Calculates the amount that has already vested. * @param _beneficiary Beneficiary address */ function vestedAmount(address _beneficiary) public view returns (uint256) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 totalBalance = beneficiary.vested; if (now < beneficiary.cliff) { return 0; } else if (now >= beneficiary.start.add(beneficiary.duration) || beneficiary.revoked) { return totalBalance; } else { return totalBalance.mul(now.sub(beneficiary.start)).div(beneficiary.duration); } } /** * @notice Allows the owner to flush the eth. */ function flushEth() public onlyOwner { owner.transfer(this.balance); } /** * @notice Allows the owner to destroy the contract and return the tokens to the owner. */ function destroy() public onlyOwner { token.transfer(owner, token.balanceOf(this)); selfdestruct(owner); } }
releasableAmount
function releasableAmount(address _beneficiary) public view returns (uint256) { return vestedAmount(_beneficiary).sub(beneficiaries[_beneficiary].released); }
/** * @dev Calculates the amount that has already vested but hasn't been released yet. * @param _beneficiary Beneficiary address */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://bd1d9802790e0281240ddbd34fb7e404a0dc8500b3639c2b04a8a6c42f0133ab
{ "func_code_index": [ 5883, 6060 ] }
56,262
MultiVesting
MultiVesting.sol
0x66e9aeedc17558cfc97b6734600b7a835f8e7ceb
Solidity
MultiVesting
contract MultiVesting is Ownable, Destroyable { using SafeMath for uint256; // beneficiary of tokens struct Beneficiary { uint256 released; uint256 vested; uint256 start; uint256 cliff; uint256 duration; bool revoked; bool revocable; bool isBeneficiary; } event Released(address _beneficiary, uint256 amount); event Revoked(address _beneficiary); event NewBeneficiary(address _beneficiary); event BeneficiaryDestroyed(address _beneficiary); mapping(address => Beneficiary) public beneficiaries; Token public token; uint256 public totalVested; uint256 public totalReleased; /* * Modifiers */ modifier isNotBeneficiary(address _beneficiary) { require(!beneficiaries[_beneficiary].isBeneficiary); _; } modifier isBeneficiary(address _beneficiary) { require(beneficiaries[_beneficiary].isBeneficiary); _; } modifier wasRevoked(address _beneficiary) { require(beneficiaries[_beneficiary].revoked); _; } modifier wasNotRevoked(address _beneficiary) { require(!beneficiaries[_beneficiary].revoked); _; } /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until _start + _duration. By then all * of the balance will have vested. * @param _token address of the token of vested tokens */ function MultiVesting(address _token) public { require(_token != address(0)); token = Token(_token); } function() payable public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary (alternative to fallback function). */ function release() public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function release(address _beneficiary) private isBeneficiary(_beneficiary) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 unreleased = releasableAmount(_beneficiary); require(unreleased > 0); beneficiary.released = beneficiary.released.add(unreleased); totalReleased = totalReleased.add(unreleased); token.transfer(_beneficiary, unreleased); if((beneficiary.vested - beneficiary.released) == 0){ beneficiary.isBeneficiary = false; } Released(_beneficiary, unreleased); } /** * @notice Allows the owner to transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function releaseTo(address _beneficiary) public onlyOwner { release(_beneficiary); } /** * @dev Add new beneficiary to start vesting * @param _beneficiary address of the beneficiary to whom vested tokens are transferred * @param _start time in seconds which the tokens will vest * @param _cliff time in seconds of the cliff in which tokens will begin to vest * @param _duration duration in seconds of the period in which the tokens will vest * @param _revocable whether the vesting is revocable or not */ function addBeneficiary(address _beneficiary, uint256 _vested, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) onlyOwner isNotBeneficiary(_beneficiary) public { require(_beneficiary != address(0)); require(_cliff >= _start); require(token.balanceOf(this) >= totalVested.sub(totalReleased).add(_vested)); beneficiaries[_beneficiary] = Beneficiary({ released : 0, vested : _vested, start : _start, cliff : _cliff, duration : _duration, revoked : false, revocable : _revocable, isBeneficiary : true }); totalVested = totalVested.add(_vested); NewBeneficiary(_beneficiary); } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. * @param _beneficiary Beneficiary address */ function revoke(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; require(beneficiary.revocable); require(!beneficiary.revoked); uint256 balance = beneficiary.vested.sub(beneficiary.released); uint256 unreleased = releasableAmount(_beneficiary); uint256 refund = balance.sub(unreleased); token.transfer(owner, refund); totalReleased = totalReleased.add(refund); beneficiary.revoked = true; beneficiary.released = beneficiary.released.add(refund); Revoked(_beneficiary); } /** * @notice Allows the owner to destroy a beneficiary. Remain tokens are returned to the owner. * @param _beneficiary Beneficiary address */ function destroyBeneficiary(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 balance = beneficiary.vested.sub(beneficiary.released); token.transfer(owner, balance); totalReleased = totalReleased.add(balance); beneficiary.isBeneficiary = false; beneficiary.released = beneficiary.released.add(balance); BeneficiaryDestroyed(_beneficiary); } /** * @dev Calculates the amount that has already vested but hasn't been released yet. * @param _beneficiary Beneficiary address */ function releasableAmount(address _beneficiary) public view returns (uint256) { return vestedAmount(_beneficiary).sub(beneficiaries[_beneficiary].released); } /** * @dev Calculates the amount that has already vested. * @param _beneficiary Beneficiary address */ function vestedAmount(address _beneficiary) public view returns (uint256) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 totalBalance = beneficiary.vested; if (now < beneficiary.cliff) { return 0; } else if (now >= beneficiary.start.add(beneficiary.duration) || beneficiary.revoked) { return totalBalance; } else { return totalBalance.mul(now.sub(beneficiary.start)).div(beneficiary.duration); } } /** * @notice Allows the owner to flush the eth. */ function flushEth() public onlyOwner { owner.transfer(this.balance); } /** * @notice Allows the owner to destroy the contract and return the tokens to the owner. */ function destroy() public onlyOwner { token.transfer(owner, token.balanceOf(this)); selfdestruct(owner); } }
vestedAmount
function vestedAmount(address _beneficiary) public view returns (uint256) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 totalBalance = beneficiary.vested; if (now < beneficiary.cliff) { return 0; } else if (now >= beneficiary.start.add(beneficiary.duration) || beneficiary.revoked) { return totalBalance; } else { return totalBalance.mul(now.sub(beneficiary.start)).div(beneficiary.duration); } }
/** * @dev Calculates the amount that has already vested. * @param _beneficiary Beneficiary address */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://bd1d9802790e0281240ddbd34fb7e404a0dc8500b3639c2b04a8a6c42f0133ab
{ "func_code_index": [ 6189, 6717 ] }
56,263
MultiVesting
MultiVesting.sol
0x66e9aeedc17558cfc97b6734600b7a835f8e7ceb
Solidity
MultiVesting
contract MultiVesting is Ownable, Destroyable { using SafeMath for uint256; // beneficiary of tokens struct Beneficiary { uint256 released; uint256 vested; uint256 start; uint256 cliff; uint256 duration; bool revoked; bool revocable; bool isBeneficiary; } event Released(address _beneficiary, uint256 amount); event Revoked(address _beneficiary); event NewBeneficiary(address _beneficiary); event BeneficiaryDestroyed(address _beneficiary); mapping(address => Beneficiary) public beneficiaries; Token public token; uint256 public totalVested; uint256 public totalReleased; /* * Modifiers */ modifier isNotBeneficiary(address _beneficiary) { require(!beneficiaries[_beneficiary].isBeneficiary); _; } modifier isBeneficiary(address _beneficiary) { require(beneficiaries[_beneficiary].isBeneficiary); _; } modifier wasRevoked(address _beneficiary) { require(beneficiaries[_beneficiary].revoked); _; } modifier wasNotRevoked(address _beneficiary) { require(!beneficiaries[_beneficiary].revoked); _; } /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until _start + _duration. By then all * of the balance will have vested. * @param _token address of the token of vested tokens */ function MultiVesting(address _token) public { require(_token != address(0)); token = Token(_token); } function() payable public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary (alternative to fallback function). */ function release() public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function release(address _beneficiary) private isBeneficiary(_beneficiary) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 unreleased = releasableAmount(_beneficiary); require(unreleased > 0); beneficiary.released = beneficiary.released.add(unreleased); totalReleased = totalReleased.add(unreleased); token.transfer(_beneficiary, unreleased); if((beneficiary.vested - beneficiary.released) == 0){ beneficiary.isBeneficiary = false; } Released(_beneficiary, unreleased); } /** * @notice Allows the owner to transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function releaseTo(address _beneficiary) public onlyOwner { release(_beneficiary); } /** * @dev Add new beneficiary to start vesting * @param _beneficiary address of the beneficiary to whom vested tokens are transferred * @param _start time in seconds which the tokens will vest * @param _cliff time in seconds of the cliff in which tokens will begin to vest * @param _duration duration in seconds of the period in which the tokens will vest * @param _revocable whether the vesting is revocable or not */ function addBeneficiary(address _beneficiary, uint256 _vested, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) onlyOwner isNotBeneficiary(_beneficiary) public { require(_beneficiary != address(0)); require(_cliff >= _start); require(token.balanceOf(this) >= totalVested.sub(totalReleased).add(_vested)); beneficiaries[_beneficiary] = Beneficiary({ released : 0, vested : _vested, start : _start, cliff : _cliff, duration : _duration, revoked : false, revocable : _revocable, isBeneficiary : true }); totalVested = totalVested.add(_vested); NewBeneficiary(_beneficiary); } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. * @param _beneficiary Beneficiary address */ function revoke(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; require(beneficiary.revocable); require(!beneficiary.revoked); uint256 balance = beneficiary.vested.sub(beneficiary.released); uint256 unreleased = releasableAmount(_beneficiary); uint256 refund = balance.sub(unreleased); token.transfer(owner, refund); totalReleased = totalReleased.add(refund); beneficiary.revoked = true; beneficiary.released = beneficiary.released.add(refund); Revoked(_beneficiary); } /** * @notice Allows the owner to destroy a beneficiary. Remain tokens are returned to the owner. * @param _beneficiary Beneficiary address */ function destroyBeneficiary(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 balance = beneficiary.vested.sub(beneficiary.released); token.transfer(owner, balance); totalReleased = totalReleased.add(balance); beneficiary.isBeneficiary = false; beneficiary.released = beneficiary.released.add(balance); BeneficiaryDestroyed(_beneficiary); } /** * @dev Calculates the amount that has already vested but hasn't been released yet. * @param _beneficiary Beneficiary address */ function releasableAmount(address _beneficiary) public view returns (uint256) { return vestedAmount(_beneficiary).sub(beneficiaries[_beneficiary].released); } /** * @dev Calculates the amount that has already vested. * @param _beneficiary Beneficiary address */ function vestedAmount(address _beneficiary) public view returns (uint256) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 totalBalance = beneficiary.vested; if (now < beneficiary.cliff) { return 0; } else if (now >= beneficiary.start.add(beneficiary.duration) || beneficiary.revoked) { return totalBalance; } else { return totalBalance.mul(now.sub(beneficiary.start)).div(beneficiary.duration); } } /** * @notice Allows the owner to flush the eth. */ function flushEth() public onlyOwner { owner.transfer(this.balance); } /** * @notice Allows the owner to destroy the contract and return the tokens to the owner. */ function destroy() public onlyOwner { token.transfer(owner, token.balanceOf(this)); selfdestruct(owner); } }
flushEth
function flushEth() public onlyOwner { owner.transfer(this.balance); }
/** * @notice Allows the owner to flush the eth. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://bd1d9802790e0281240ddbd34fb7e404a0dc8500b3639c2b04a8a6c42f0133ab
{ "func_code_index": [ 6789, 6878 ] }
56,264
MultiVesting
MultiVesting.sol
0x66e9aeedc17558cfc97b6734600b7a835f8e7ceb
Solidity
MultiVesting
contract MultiVesting is Ownable, Destroyable { using SafeMath for uint256; // beneficiary of tokens struct Beneficiary { uint256 released; uint256 vested; uint256 start; uint256 cliff; uint256 duration; bool revoked; bool revocable; bool isBeneficiary; } event Released(address _beneficiary, uint256 amount); event Revoked(address _beneficiary); event NewBeneficiary(address _beneficiary); event BeneficiaryDestroyed(address _beneficiary); mapping(address => Beneficiary) public beneficiaries; Token public token; uint256 public totalVested; uint256 public totalReleased; /* * Modifiers */ modifier isNotBeneficiary(address _beneficiary) { require(!beneficiaries[_beneficiary].isBeneficiary); _; } modifier isBeneficiary(address _beneficiary) { require(beneficiaries[_beneficiary].isBeneficiary); _; } modifier wasRevoked(address _beneficiary) { require(beneficiaries[_beneficiary].revoked); _; } modifier wasNotRevoked(address _beneficiary) { require(!beneficiaries[_beneficiary].revoked); _; } /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until _start + _duration. By then all * of the balance will have vested. * @param _token address of the token of vested tokens */ function MultiVesting(address _token) public { require(_token != address(0)); token = Token(_token); } function() payable public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary (alternative to fallback function). */ function release() public { release(msg.sender); } /** * @notice Transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function release(address _beneficiary) private isBeneficiary(_beneficiary) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 unreleased = releasableAmount(_beneficiary); require(unreleased > 0); beneficiary.released = beneficiary.released.add(unreleased); totalReleased = totalReleased.add(unreleased); token.transfer(_beneficiary, unreleased); if((beneficiary.vested - beneficiary.released) == 0){ beneficiary.isBeneficiary = false; } Released(_beneficiary, unreleased); } /** * @notice Allows the owner to transfers vested tokens to beneficiary. * @param _beneficiary Beneficiary address */ function releaseTo(address _beneficiary) public onlyOwner { release(_beneficiary); } /** * @dev Add new beneficiary to start vesting * @param _beneficiary address of the beneficiary to whom vested tokens are transferred * @param _start time in seconds which the tokens will vest * @param _cliff time in seconds of the cliff in which tokens will begin to vest * @param _duration duration in seconds of the period in which the tokens will vest * @param _revocable whether the vesting is revocable or not */ function addBeneficiary(address _beneficiary, uint256 _vested, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) onlyOwner isNotBeneficiary(_beneficiary) public { require(_beneficiary != address(0)); require(_cliff >= _start); require(token.balanceOf(this) >= totalVested.sub(totalReleased).add(_vested)); beneficiaries[_beneficiary] = Beneficiary({ released : 0, vested : _vested, start : _start, cliff : _cliff, duration : _duration, revoked : false, revocable : _revocable, isBeneficiary : true }); totalVested = totalVested.add(_vested); NewBeneficiary(_beneficiary); } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. * @param _beneficiary Beneficiary address */ function revoke(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; require(beneficiary.revocable); require(!beneficiary.revoked); uint256 balance = beneficiary.vested.sub(beneficiary.released); uint256 unreleased = releasableAmount(_beneficiary); uint256 refund = balance.sub(unreleased); token.transfer(owner, refund); totalReleased = totalReleased.add(refund); beneficiary.revoked = true; beneficiary.released = beneficiary.released.add(refund); Revoked(_beneficiary); } /** * @notice Allows the owner to destroy a beneficiary. Remain tokens are returned to the owner. * @param _beneficiary Beneficiary address */ function destroyBeneficiary(address _beneficiary) public onlyOwner { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 balance = beneficiary.vested.sub(beneficiary.released); token.transfer(owner, balance); totalReleased = totalReleased.add(balance); beneficiary.isBeneficiary = false; beneficiary.released = beneficiary.released.add(balance); BeneficiaryDestroyed(_beneficiary); } /** * @dev Calculates the amount that has already vested but hasn't been released yet. * @param _beneficiary Beneficiary address */ function releasableAmount(address _beneficiary) public view returns (uint256) { return vestedAmount(_beneficiary).sub(beneficiaries[_beneficiary].released); } /** * @dev Calculates the amount that has already vested. * @param _beneficiary Beneficiary address */ function vestedAmount(address _beneficiary) public view returns (uint256) { Beneficiary storage beneficiary = beneficiaries[_beneficiary]; uint256 totalBalance = beneficiary.vested; if (now < beneficiary.cliff) { return 0; } else if (now >= beneficiary.start.add(beneficiary.duration) || beneficiary.revoked) { return totalBalance; } else { return totalBalance.mul(now.sub(beneficiary.start)).div(beneficiary.duration); } } /** * @notice Allows the owner to flush the eth. */ function flushEth() public onlyOwner { owner.transfer(this.balance); } /** * @notice Allows the owner to destroy the contract and return the tokens to the owner. */ function destroy() public onlyOwner { token.transfer(owner, token.balanceOf(this)); selfdestruct(owner); } }
destroy
function destroy() public onlyOwner { token.transfer(owner, token.balanceOf(this)); selfdestruct(owner); }
/** * @notice Allows the owner to destroy the contract and return the tokens to the owner. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://bd1d9802790e0281240ddbd34fb7e404a0dc8500b3639c2b04a8a6c42f0133ab
{ "func_code_index": [ 6992, 7126 ] }
56,265
sRUNE
sRUNE.sol
0xe845941fb6858c6d0e5cf18f9307086e56254e26
Solidity
IERC20
interface IERC20 { //function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); //function transfer(address recipient, uint256 amount) external returns (bool); //function allowance(address owner, address spender) external view returns (uint256); //function approve(address spender, uint256 amount) external returns (bool); //function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); //event Transfer(address indexed from, address indexed to, uint256 value); //event Approval(address indexed owner, address indexed spender, uint256 value); }
balanceOf
function balanceOf(address account) external view returns (uint256);
//function totalSupply() external view returns (uint256);
LineComment
v0.5.1+commit.c8a2cb62
{ "func_code_index": [ 83, 156 ] }
56,266
PopulousTokenRewardPool
/Users/nemitariajienka/Desktop/DeFi_backup/DeFi/contracts/reward/PopulousTokenRewardPool.sol
0xabc607f40ca9225117c83e3f03bbe15df8bb93a4
Solidity
Math
library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } }
/** * @dev Standard math utilities missing in the Solidity language. */
NatSpecMultiLine
max
function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; }
/** * @dev Returns the largest of two numbers. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
{ "func_code_index": [ 79, 188 ] }
56,267
PopulousTokenRewardPool
/Users/nemitariajienka/Desktop/DeFi_backup/DeFi/contracts/reward/PopulousTokenRewardPool.sol
0xabc607f40ca9225117c83e3f03bbe15df8bb93a4
Solidity
Math
library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } }
/** * @dev Standard math utilities missing in the Solidity language. */
NatSpecMultiLine
min
function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; }
/** * @dev Returns the smallest of two numbers. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
{ "func_code_index": [ 255, 363 ] }
56,268
PopulousTokenRewardPool
/Users/nemitariajienka/Desktop/DeFi_backup/DeFi/contracts/reward/PopulousTokenRewardPool.sol
0xabc607f40ca9225117c83e3f03bbe15df8bb93a4
Solidity
Math
library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } }
/** * @dev Standard math utilities missing in the Solidity language. */
NatSpecMultiLine
average
function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); }
/** * @dev Returns the average of two numbers. The result is rounded towards * zero. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
{ "func_code_index": [ 472, 666 ] }
56,269
PopulousTokenRewardPool
/Users/nemitariajienka/Desktop/DeFi_backup/DeFi/contracts/reward/PopulousTokenRewardPool.sol
0xabc607f40ca9225117c83e3f03bbe15df8bb93a4
Solidity
PopulousTokenRewardPool
contract PopulousTokenRewardPool is Ownable { using SafeMath for uint256; using Address for address; ERC20 public pToken; ERC20 public rewardToken; uint256 public duration; uint256 public periodFinish = 0; uint256 public totalDeposit = 0; uint256 public totalRewardPaid = 0; uint256 public rewardRate = 0; uint256 public lastUpdateTime; uint256 public rewardPerTokenStored; mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; mapping(address => uint256) internal userInfo; event RewardAdded(uint256 reward); event Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardPaid(address indexed user, uint256 reward); //event RewardDenied(address indexed user, uint256 reward); modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; } constructor(address _pToken, address _rewardToken, uint256 _duration) public { pToken = ERC20(_pToken); rewardToken = ERC20(_rewardToken); duration = _duration; } function lastTimeRewardApplicable() public view returns (uint256) { return Math.min(block.timestamp, periodFinish); } function rewardPerToken() public view returns (uint256) { uint256 PTokenSupply = pToken.balanceOf(address(this)); if (PTokenSupply == 0) { return rewardPerTokenStored; } return rewardPerTokenStored.add( lastTimeRewardApplicable() .sub(lastUpdateTime) .mul(rewardRate) .mul(1e18) .div(PTokenSupply) ); } function getuserinfo(address _user) public view returns(uint256 ){ return userInfo[_user]; } function earned(address account) public view returns (uint256) { return userInfo[account] .mul(rewardPerToken().sub(userRewardPerTokenPaid[account])) .div(1e18) .add(rewards[account]); } // stake visibility is public as overriding LPTokenWrapper's stake() function function stake(uint256 amount) public updateReward(msg.sender) { //require(msg.sender == exclusiveAddress, "Must be the exclusiveAddress to stake"); require(amount > 0, "Cannot stake 0"); //UserInfo storage user = userInfo[msg.sender]; pToken.transferFrom(address(msg.sender), address(this), amount); //user.amount = user.amount.add(amount); userInfo[msg.sender] = userInfo[msg.sender].add(amount); totalDeposit = totalDeposit.add(amount); emit Staked(msg.sender, amount); } function withdraw(uint256 amount) public updateReward(msg.sender) { require(amount > 0, "Cannot withdraw 0"); userInfo[msg.sender] = userInfo[msg.sender].sub(amount); totalDeposit = totalDeposit.sub(amount); pToken.transfer(address(msg.sender), amount); emit Withdrawn(msg.sender, amount); } function exit() external { withdraw(userInfo[msg.sender]); getReward(); } function withdrawAll() external { withdraw(userInfo[msg.sender]); } function getTotalDeposit() public view returns(uint256) { return totalDeposit; } function getTotalRewardPaid() public view returns(uint256) { return totalRewardPaid; } /** * A push mechanism for accounts that have not claimed their rewards for a long time. * The implementation is semantically analogous to getReward(), but uses a push pattern * instead of pull pattern. */ function pushReward(address recipient) public updateReward(recipient) onlyOwner { uint256 reward = earned(recipient); if (reward > 0) { rewards[recipient] = 0; totalRewardPaid = totalRewardPaid.add(reward); rewardToken.transfer(recipient, reward); emit RewardPaid(recipient, reward); } } function getReward() public updateReward(msg.sender) { uint256 reward = earned(msg.sender); if (reward > 0) { rewards[msg.sender] = 0; totalRewardPaid = totalRewardPaid.add(reward); rewardToken.transfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } } function notifyRewardAmount(uint256 reward) external onlyOwner updateReward(address(0)) { // overflow fix according to https://sips.synthetix.io/sips/sip-77 require(reward < uint(-1) / 1e18, "the notified reward cannot invoke multiplication overflow"); if (block.timestamp >= periodFinish) { rewardRate = reward.div(duration); } else { uint256 remaining = periodFinish.sub(block.timestamp); uint256 leftover = remaining.mul(rewardRate); rewardRate = reward.add(leftover).div(duration); } lastUpdateTime = block.timestamp; periodFinish = block.timestamp.add(duration); emit RewardAdded(reward); } }
stake
function stake(uint256 amount) public updateReward(msg.sender) { //require(msg.sender == exclusiveAddress, "Must be the exclusiveAddress to stake"); require(amount > 0, "Cannot stake 0"); //UserInfo storage user = userInfo[msg.sender]; pToken.transferFrom(address(msg.sender), address(this), amount); //user.amount = user.amount.add(amount); userInfo[msg.sender] = userInfo[msg.sender].add(amount); totalDeposit = totalDeposit.add(amount); emit Staked(msg.sender, amount); }
// stake visibility is public as overriding LPTokenWrapper's stake() function
LineComment
v0.5.16+commit.9c3226ce
{ "func_code_index": [ 2480, 3026 ] }
56,270
PopulousTokenRewardPool
/Users/nemitariajienka/Desktop/DeFi_backup/DeFi/contracts/reward/PopulousTokenRewardPool.sol
0xabc607f40ca9225117c83e3f03bbe15df8bb93a4
Solidity
PopulousTokenRewardPool
contract PopulousTokenRewardPool is Ownable { using SafeMath for uint256; using Address for address; ERC20 public pToken; ERC20 public rewardToken; uint256 public duration; uint256 public periodFinish = 0; uint256 public totalDeposit = 0; uint256 public totalRewardPaid = 0; uint256 public rewardRate = 0; uint256 public lastUpdateTime; uint256 public rewardPerTokenStored; mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; mapping(address => uint256) internal userInfo; event RewardAdded(uint256 reward); event Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardPaid(address indexed user, uint256 reward); //event RewardDenied(address indexed user, uint256 reward); modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; } constructor(address _pToken, address _rewardToken, uint256 _duration) public { pToken = ERC20(_pToken); rewardToken = ERC20(_rewardToken); duration = _duration; } function lastTimeRewardApplicable() public view returns (uint256) { return Math.min(block.timestamp, periodFinish); } function rewardPerToken() public view returns (uint256) { uint256 PTokenSupply = pToken.balanceOf(address(this)); if (PTokenSupply == 0) { return rewardPerTokenStored; } return rewardPerTokenStored.add( lastTimeRewardApplicable() .sub(lastUpdateTime) .mul(rewardRate) .mul(1e18) .div(PTokenSupply) ); } function getuserinfo(address _user) public view returns(uint256 ){ return userInfo[_user]; } function earned(address account) public view returns (uint256) { return userInfo[account] .mul(rewardPerToken().sub(userRewardPerTokenPaid[account])) .div(1e18) .add(rewards[account]); } // stake visibility is public as overriding LPTokenWrapper's stake() function function stake(uint256 amount) public updateReward(msg.sender) { //require(msg.sender == exclusiveAddress, "Must be the exclusiveAddress to stake"); require(amount > 0, "Cannot stake 0"); //UserInfo storage user = userInfo[msg.sender]; pToken.transferFrom(address(msg.sender), address(this), amount); //user.amount = user.amount.add(amount); userInfo[msg.sender] = userInfo[msg.sender].add(amount); totalDeposit = totalDeposit.add(amount); emit Staked(msg.sender, amount); } function withdraw(uint256 amount) public updateReward(msg.sender) { require(amount > 0, "Cannot withdraw 0"); userInfo[msg.sender] = userInfo[msg.sender].sub(amount); totalDeposit = totalDeposit.sub(amount); pToken.transfer(address(msg.sender), amount); emit Withdrawn(msg.sender, amount); } function exit() external { withdraw(userInfo[msg.sender]); getReward(); } function withdrawAll() external { withdraw(userInfo[msg.sender]); } function getTotalDeposit() public view returns(uint256) { return totalDeposit; } function getTotalRewardPaid() public view returns(uint256) { return totalRewardPaid; } /** * A push mechanism for accounts that have not claimed their rewards for a long time. * The implementation is semantically analogous to getReward(), but uses a push pattern * instead of pull pattern. */ function pushReward(address recipient) public updateReward(recipient) onlyOwner { uint256 reward = earned(recipient); if (reward > 0) { rewards[recipient] = 0; totalRewardPaid = totalRewardPaid.add(reward); rewardToken.transfer(recipient, reward); emit RewardPaid(recipient, reward); } } function getReward() public updateReward(msg.sender) { uint256 reward = earned(msg.sender); if (reward > 0) { rewards[msg.sender] = 0; totalRewardPaid = totalRewardPaid.add(reward); rewardToken.transfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } } function notifyRewardAmount(uint256 reward) external onlyOwner updateReward(address(0)) { // overflow fix according to https://sips.synthetix.io/sips/sip-77 require(reward < uint(-1) / 1e18, "the notified reward cannot invoke multiplication overflow"); if (block.timestamp >= periodFinish) { rewardRate = reward.div(duration); } else { uint256 remaining = periodFinish.sub(block.timestamp); uint256 leftover = remaining.mul(rewardRate); rewardRate = reward.add(leftover).div(duration); } lastUpdateTime = block.timestamp; periodFinish = block.timestamp.add(duration); emit RewardAdded(reward); } }
pushReward
function pushReward(address recipient) public updateReward(recipient) onlyOwner { uint256 reward = earned(recipient); if (reward > 0) { rewards[recipient] = 0; totalRewardPaid = totalRewardPaid.add(reward); rewardToken.transfer(recipient, reward); emit RewardPaid(recipient, reward); } }
/** * A push mechanism for accounts that have not claimed their rewards for a long time. * The implementation is semantically analogous to getReward(), but uses a push pattern * instead of pull pattern. */
NatSpecMultiLine
v0.5.16+commit.9c3226ce
{ "func_code_index": [ 3985, 4352 ] }
56,271
EURsToken
EURsToken.sol
0x90d647e0e8c97e37f4bc09e16d804ecd1e5a5fb8
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/* * Copyright © 2018 by Capital Trust Group Limited * Author : [email protected] */
Comment
totalSupply
function totalSupply() constant returns (uint256 supply) {}
/// @return total amount of tokens
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://3057ddddd5d1ea9bd45205ad6cbcb697465b8a355a09392d20b8a9c3d66bc813
{ "func_code_index": [ 60, 124 ] }
56,272
EURsToken
EURsToken.sol
0x90d647e0e8c97e37f4bc09e16d804ecd1e5a5fb8
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/* * Copyright © 2018 by Capital Trust Group Limited * Author : [email protected] */
Comment
balanceOf
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @param _owner The address from which the balance will be retrieved /// @return The balance
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://3057ddddd5d1ea9bd45205ad6cbcb697465b8a355a09392d20b8a9c3d66bc813
{ "func_code_index": [ 232, 309 ] }
56,273
EURsToken
EURsToken.sol
0x90d647e0e8c97e37f4bc09e16d804ecd1e5a5fb8
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/* * Copyright © 2018 by Capital Trust Group Limited * Author : [email protected] */
Comment
transfer
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://3057ddddd5d1ea9bd45205ad6cbcb697465b8a355a09392d20b8a9c3d66bc813
{ "func_code_index": [ 546, 623 ] }
56,274
EURsToken
EURsToken.sol
0x90d647e0e8c97e37f4bc09e16d804ecd1e5a5fb8
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/* * Copyright © 2018 by Capital Trust Group Limited * Author : [email protected] */
Comment
transferFrom
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://3057ddddd5d1ea9bd45205ad6cbcb697465b8a355a09392d20b8a9c3d66bc813
{ "func_code_index": [ 946, 1042 ] }
56,275
EURsToken
EURsToken.sol
0x90d647e0e8c97e37f4bc09e16d804ecd1e5a5fb8
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/* * Copyright © 2018 by Capital Trust Group Limited * Author : [email protected] */
Comment
approve
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://3057ddddd5d1ea9bd45205ad6cbcb697465b8a355a09392d20b8a9c3d66bc813
{ "func_code_index": [ 1326, 1407 ] }
56,276
EURsToken
EURsToken.sol
0x90d647e0e8c97e37f4bc09e16d804ecd1e5a5fb8
Solidity
Token
contract Token { /// @return total amount of tokens function totalSupply() constant returns (uint256 supply) {} /// @param _owner The address from which the balance will be retrieved /// @return The balance function balanceOf(address _owner) constant returns (uint256 balance) {} /// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transfer(address _to, uint256 _value) returns (bool success) {} /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} /// @notice `msg.sender` approves `_addr` to spend `_value` tokens /// @param _spender The address of the account able to transfer the tokens /// @param _value The amount of wei to be approved for transfer /// @return Whether the approval was successful or not function approve(address _spender, uint256 _value) returns (bool success) {} /// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
/* * Copyright © 2018 by Capital Trust Group Limited * Author : [email protected] */
Comment
allowance
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
/// @param _owner The address of the account owning tokens /// @param _spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://3057ddddd5d1ea9bd45205ad6cbcb697465b8a355a09392d20b8a9c3d66bc813
{ "func_code_index": [ 1615, 1712 ] }
56,277
EURsToken
EURsToken.sol
0x90d647e0e8c97e37f4bc09e16d804ecd1e5a5fb8
Solidity
EURsToken
contract EURsToken is StandardToken { function () { //if ether is sent to this address, send it back. throw; } /* Public variables of the token */ string public name; uint8 public decimals; string public symbol; string public version = 'H1.0'; function EURsToken( ) { balances[msg.sender] = 100000000000 * 1000000000000000000; // Give the creator all initial tokens, 18 zero is 18 Decimals totalSupply = 100000000000 * 1000000000000000000; // Update total supply, , 18 zero is 18 Decimals name = "Schenken EUR"; // Token Name decimals = 18; // Amount of decimals for display purposes symbol = "EURs"; // Token Symbol } /* Approves and then calls the receiving contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; } }
approveAndCall
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } return true; }
/* Approves and then calls the receiving contract */
Comment
v0.4.24+commit.e67f0147
bzzr://3057ddddd5d1ea9bd45205ad6cbcb697465b8a355a09392d20b8a9c3d66bc813
{ "func_code_index": [ 981, 1365 ] }
56,278
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
ERC721
contract ERC721 { // ERC20 compatible functions // use variable getter // function name() constant returns (string name); // function symbol() constant returns (string symbol); function totalSupply() public constant returns (uint256); function balanceOf(address _owner) public constant returns (uint balance); function ownerOf(uint256 _tokenId) public constant returns (address owner); function approve(address _to, uint256 _tokenId) public ; function allowance(address _owner, address _spender) public constant returns (uint256 tokenId); function transfer(address _to, uint256 _tokenId) external ; function transferFrom(address _from, address _to, uint256 _tokenId) external; // Optional // function takeOwnership(uint256 _tokenId) public ; // function tokenOfOwnerByIndex(address _owner, uint256 _index) external constant returns (uint tokenId); // function tokenMetadata(uint256 _tokenId) public constant returns (string infoUrl); // Events event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); }
totalSupply
function totalSupply() public constant returns (uint256);
// ERC20 compatible functions // use variable getter // function name() constant returns (string name); // function symbol() constant returns (string symbol);
LineComment
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 198, 260 ] }
56,279
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
ERC20
contract ERC20 { // Get the total token supply function totalSupply() public constant returns (uint256 _totalSupply); // Get the account balance of another account with address _owner function balanceOf(address _owner) public constant returns (uint256 balance); // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) public returns (bool success); // transfer _value amount of token approved by address _from function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); // approve an address with _value amount of tokens function approve(address _spender, uint256 _value) public returns (bool success); // get remaining token approved by _owner to _spender function allowance(address _owner, address _spender) public constant returns (uint256 remaining); // Triggered when tokens are transferred. event Transfer(address indexed _from, address indexed _to, uint256 _value); // Triggered whenever approve(address _spender, uint256 _value) is called. event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
totalSupply
function totalSupply() public constant returns (uint256 _totalSupply);
// Get the total token supply
LineComment
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 53, 128 ] }
56,280
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
ERC20
contract ERC20 { // Get the total token supply function totalSupply() public constant returns (uint256 _totalSupply); // Get the account balance of another account with address _owner function balanceOf(address _owner) public constant returns (uint256 balance); // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) public returns (bool success); // transfer _value amount of token approved by address _from function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); // approve an address with _value amount of tokens function approve(address _spender, uint256 _value) public returns (bool success); // get remaining token approved by _owner to _spender function allowance(address _owner, address _spender) public constant returns (uint256 remaining); // Triggered when tokens are transferred. event Transfer(address indexed _from, address indexed _to, uint256 _value); // Triggered whenever approve(address _spender, uint256 _value) is called. event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
balanceOf
function balanceOf(address _owner) public constant returns (uint256 balance);
// Get the account balance of another account with address _owner
LineComment
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 203, 285 ] }
56,281
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
ERC20
contract ERC20 { // Get the total token supply function totalSupply() public constant returns (uint256 _totalSupply); // Get the account balance of another account with address _owner function balanceOf(address _owner) public constant returns (uint256 balance); // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) public returns (bool success); // transfer _value amount of token approved by address _from function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); // approve an address with _value amount of tokens function approve(address _spender, uint256 _value) public returns (bool success); // get remaining token approved by _owner to _spender function allowance(address _owner, address _spender) public constant returns (uint256 remaining); // Triggered when tokens are transferred. event Transfer(address indexed _from, address indexed _to, uint256 _value); // Triggered whenever approve(address _spender, uint256 _value) is called. event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
transfer
function transfer(address _to, uint256 _value) public returns (bool success);
// Send _value amount of tokens to address _to
LineComment
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 341, 423 ] }
56,282
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
ERC20
contract ERC20 { // Get the total token supply function totalSupply() public constant returns (uint256 _totalSupply); // Get the account balance of another account with address _owner function balanceOf(address _owner) public constant returns (uint256 balance); // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) public returns (bool success); // transfer _value amount of token approved by address _from function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); // approve an address with _value amount of tokens function approve(address _spender, uint256 _value) public returns (bool success); // get remaining token approved by _owner to _spender function allowance(address _owner, address _spender) public constant returns (uint256 remaining); // Triggered when tokens are transferred. event Transfer(address indexed _from, address indexed _to, uint256 _value); // Triggered whenever approve(address _spender, uint256 _value) is called. event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
// transfer _value amount of token approved by address _from
LineComment
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 496, 597 ] }
56,283
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
ERC20
contract ERC20 { // Get the total token supply function totalSupply() public constant returns (uint256 _totalSupply); // Get the account balance of another account with address _owner function balanceOf(address _owner) public constant returns (uint256 balance); // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) public returns (bool success); // transfer _value amount of token approved by address _from function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); // approve an address with _value amount of tokens function approve(address _spender, uint256 _value) public returns (bool success); // get remaining token approved by _owner to _spender function allowance(address _owner, address _spender) public constant returns (uint256 remaining); // Triggered when tokens are transferred. event Transfer(address indexed _from, address indexed _to, uint256 _value); // Triggered whenever approve(address _spender, uint256 _value) is called. event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
approve
function approve(address _spender, uint256 _value) public returns (bool success);
// approve an address with _value amount of tokens
LineComment
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 660, 746 ] }
56,284
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
ERC20
contract ERC20 { // Get the total token supply function totalSupply() public constant returns (uint256 _totalSupply); // Get the account balance of another account with address _owner function balanceOf(address _owner) public constant returns (uint256 balance); // Send _value amount of tokens to address _to function transfer(address _to, uint256 _value) public returns (bool success); // transfer _value amount of token approved by address _from function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); // approve an address with _value amount of tokens function approve(address _spender, uint256 _value) public returns (bool success); // get remaining token approved by _owner to _spender function allowance(address _owner, address _spender) public constant returns (uint256 remaining); // Triggered when tokens are transferred. event Transfer(address indexed _from, address indexed _to, uint256 _value); // Triggered whenever approve(address _spender, uint256 _value) is called. event Approval(address indexed _owner, address indexed _spender, uint256 _value); }
allowance
function allowance(address _owner, address _spender) public constant returns (uint256 remaining);
// get remaining token approved by _owner to _spender
LineComment
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 808, 910 ] }
56,285
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
VirtualGift
function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); }
/// @dev constructor
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 1750, 2531 ] }
56,286
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
changeGTOAddress
function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); }
/// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 2751, 2870 ] }
56,287
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
getGTOAddress
function getGTOAddress() public constant returns (address) { return address(GTO); }
/// @dev return current GTO address
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 2918, 3035 ] }
56,288
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
totalSupply
function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; }
/// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 3148, 3305 ] }
56,289
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
buy
function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); }
/// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 3404, 3986 ] }
56,290
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
sendGift
function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); }
/// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 4163, 4497 ] }
56,291
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
balanceOf
function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; }
/// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 4624, 4765 ] }
56,292
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
ownerOf
function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; }
/// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 5038, 5225 ] }
56,293
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
approve
function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); }
/// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 5380, 5663 ] }
56,294
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
allowance
function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; }
/// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 5853, 6021 ] }
56,295
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
takeOwnership
function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); }
/// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 6162, 6813 ] }
56,296
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
_transfer
function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); }
/// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 7010, 7520 ] }
56,297
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
transfer
function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); }
/// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 7675, 8155 ] }
56,298
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
transferFrom
function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); }
/// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 8345, 9120 ] }
56,299
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
GiftsOfOwner
function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } }
/// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 9494, 10457 ] }
56,300
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
giftOwnerByIndex
function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; }
/// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 10905, 11132 ] }
56,301
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
GiftMetadata
function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; }
/// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 11265, 11409 ] }
56,302
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
createGift
function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; }
/// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 11563, 12403 ] }
56,303
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
getGift
function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); }
/// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 12514, 12805 ] }
56,304
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
updateGift
function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; }
/// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 13010, 13389 ] }
56,305
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
removeGift
function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; }
/// @dev remove gift /// @param GiftId : gift id to remove
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 13466, 13630 ] }
56,306
VirtualGift
VirtualGift.sol
0xa4b01cc6f2fde9d5d84da419bee4359819ae210b
Solidity
VirtualGift
contract VirtualGift is ERC721 { // load GTO to Virtual Gift contract, to interact with GTO ERC20 GTO = ERC20(0x00C5bBaE50781Be1669306b9e001EFF57a2957b09d); // Gift data struct Gift { // gift price uint256 price; // gift description string description; } address public owner; event Transfer(address indexed _from, address indexed _to, uint256 _GiftId); event Approval(address indexed _owner, address indexed _approved, uint256 _GiftId); event Creation(address indexed _owner, uint256 indexed GiftId); string public constant name = "VirtualGift"; string public constant symbol = "VTG"; // Gift object storage in array Gift[] giftStorage; // total Gift of an address mapping(address => uint256) private balances; // index of Gift array to Owner mapping(uint256 => address) private GiftIndexToOwners; // Gift exist or not mapping(uint256 => bool) private GiftExists; // mapping from owner and approved address to GiftId mapping(address => mapping (address => uint256)) private allowed; // mapping from owner and index Gift of owner to GiftId mapping(address => mapping(uint256 => uint256)) private ownerIndexToGifts; // Gift metadata mapping(uint256 => string) GiftLinks; modifier onlyOwner(){ require(msg.sender == owner); _; } modifier onlyGiftOwner(uint256 GiftId){ require(msg.sender == GiftIndexToOwners[GiftId]); _; } modifier validGift(uint256 GiftId){ require(GiftExists[GiftId]); _; } /// @dev constructor function VirtualGift() public{ owner = msg.sender; // save temporaryly new Gift Gift memory newGift = Gift({ price: 0, description: "MYTHICAL" }); // push to array and return the length is the id of new Gift uint256 mythicalGift = giftStorage.push(newGift) - 1; // id = 0 // mythical Gift is not exist GiftExists[mythicalGift] = false; // assign url for Gift GiftLinks[mythicalGift] = "mythicalGift"; // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, mythicalGift); // event create new Gift for msg.sender Creation(msg.sender, mythicalGift); } /// @dev this function change GTO address, this mean you can use many token to buy gift /// by change GTO address to BNB address /// @param newAddress is new address of GTO or another Gift like BNB function changeGTOAddress(address newAddress) public onlyOwner{ GTO = ERC20(newAddress); } /// @dev return current GTO address function getGTOAddress() public constant returns (address) { return address(GTO); } /// @dev return total supply of Gift /// @return length of Gift storage array, except Gift Zero function totalSupply() public constant returns (uint256){ // exclusive Gift Zero return giftStorage.length - 1; } /// @dev allow people to buy Gift /// @param GiftId : id of gift user want to buy function buy(uint256 GiftId) validGift(GiftId) public { // get old owner of Gift address oldowner = ownerOf(GiftId); // tell gifto transfer GTO from new owner to oldowner // NOTE: new owner MUST approve for Virtual Gift contract to take his balance require(GTO.transferFrom(msg.sender, oldowner, giftStorage[GiftId].price) == true); // assign new owner for GiftId // TODO: old owner should have something to confirm that he want to sell this Gift _transfer(oldowner, msg.sender, GiftId); } /// @dev owner send gift to recipient when VG was approved /// @param recipient : received gift /// @param GiftId : id of gift which recipient want to buy function sendGift(address recipient, uint256 GiftId) onlyGiftOwner(GiftId) validGift(GiftId) public { // transfer GTO to owner // require(GTO.transfer(msg.sender, giftStorage[GiftId].price) == true); // transfer gift to recipient _transfer(msg.sender, recipient, GiftId); } /// @dev get total Gift of an address /// @param _owner to get balance /// @return balance of an address function balanceOf(address _owner) public constant returns (uint256 balance){ return balances[_owner]; } function isExist(uint256 GiftId) public constant returns(bool){ return GiftExists[GiftId]; } /// @dev get owner of an Gift id /// @param _GiftId : id of Gift to get owner /// @return owner : owner of an Gift id function ownerOf(uint256 _GiftId) public constant returns (address _owner) { require(GiftExists[_GiftId]); return GiftIndexToOwners[_GiftId]; } /// @dev approve Gift id from msg.sender to an address /// @param _to : address is approved /// @param _GiftId : id of Gift in array function approve(address _to, uint256 _GiftId) validGift(_GiftId) public { require(msg.sender == ownerOf(_GiftId)); require(msg.sender != _to); allowed[msg.sender][_to] = _GiftId; Approval(msg.sender, _to, _GiftId); } /// @dev get id of Gift was approved from owner to spender /// @param _owner : address owner of Gift /// @param _spender : spender was approved /// @return GiftId function allowance(address _owner, address _spender) public constant returns (uint256 GiftId) { return allowed[_owner][_spender]; } /// @dev a spender take owner ship of Gift id, when he was approved /// @param _GiftId : id of Gift has being takeOwnership function takeOwnership(uint256 _GiftId) validGift(_GiftId) public { // get oldowner of Giftid address oldOwner = ownerOf(_GiftId); // new owner is msg sender address newOwner = msg.sender; require(newOwner != oldOwner); // newOwner must be approved by oldOwner require(allowed[oldOwner][newOwner] == _GiftId); // transfer Gift for new owner _transfer(oldOwner, newOwner, _GiftId); // delete approve when being done take owner ship delete allowed[oldOwner][newOwner]; Transfer(oldOwner, newOwner, _GiftId); } /// @dev transfer ownership of a specific Gift to an address. /// @param _from : address owner of Giftid /// @param _to : address's received /// @param _GiftId : Gift id function _transfer(address _from, address _to, uint256 _GiftId) internal { // Since the number of Gift is capped to 2^32 we can't overflow this balances[_to]++; // transfer ownership GiftIndexToOwners[_GiftId] = _to; // When creating new Gift _from is 0x0, but we can't account that address. if (_from != address(0)) { balances[_from]--; } // Emit the transfer event. Transfer(_from, _to, _GiftId); } /// @dev transfer ownership of Giftid from msg sender to an address /// @param _to : address's received /// @param _GiftId : Gift id function transfer(address _to, uint256 _GiftId) validGift(_GiftId) external { // not transfer to zero require(_to != 0x0); // address received different from sender require(msg.sender != _to); // sender must be owner of Giftid require(msg.sender == ownerOf(_GiftId)); // do not send to Gift contract require(_to != address(this)); _transfer(msg.sender, _to, _GiftId); } /// @dev transfer Giftid was approved by _from to _to /// @param _from : address owner of Giftid /// @param _to : address is received /// @param _GiftId : Gift id function transferFrom(address _from, address _to, uint256 _GiftId) validGift(_GiftId) external { require(_from == ownerOf(_GiftId)); // Check for approval and valid ownership require(allowance(_from, msg.sender) == _GiftId); // address received different from _owner require(_from != _to); // Safety check to prevent against an unexpected 0x0 default. require(_to != address(0)); // Disallow transfers to this contract to prevent accidental misuse. // The contract should never own any Gift require(_to != address(this)); // Reassign ownership (also clears pending approvals and emits Transfer event). _transfer(_from, _to, _GiftId); } /// @dev Returns a list of all Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// @return ownerGifts : list Gift of owner function GiftsOfOwner(address _owner) public view returns(uint256[] ownerGifts) { uint256 GiftCount = balanceOf(_owner); if (GiftCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](GiftCount); uint256 total = totalSupply(); uint256 resultIndex = 0; // We count on the fact that all Gift have IDs starting at 1 and increasing // sequentially up to the totalCat count. uint256 GiftId; // scan array and filter Gift of owner for (GiftId = 0; GiftId <= total; GiftId++) { if (GiftIndexToOwners[GiftId] == _owner) { result[resultIndex] = GiftId; resultIndex++; } } return result; } } /// @dev Returns a Gift IDs assigned to an address. /// @param _owner The owner whose Gift we are interested in. /// @param _index to owner Gift list /// @notice This method MUST NEVER be called by smart contract code. First, it's fairly /// expensive (it walks the entire Gift array looking for Gift belonging to owner), /// it is only supported for web3 calls, and /// not contract-to-contract calls. function giftOwnerByIndex(address _owner, uint256 _index) external constant returns (uint256 GiftId) { uint256[] memory ownerGifts = GiftsOfOwner(_owner); return ownerGifts[_index]; } /// @dev get Gift metadata (url) from GiftLinks /// @param _GiftId : Gift id /// @return infoUrl : url of Gift function GiftMetadata(uint256 _GiftId) public constant returns (string infoUrl) { return GiftLinks[_GiftId]; } /// @dev function create new Gift /// @param _price : Gift property /// @param _description : Gift property /// @return GiftId function createGift(uint256 _price, string _description, string _url) public onlyOwner returns (uint256) { // save temporarily new Gift Gift memory newGift = Gift({ price: _price, description: _description }); // push to array and return the length is the id of new Gift uint256 newGiftId = giftStorage.push(newGift) - 1; // turn on existen GiftExists[newGiftId] = true; // assin gift url GiftLinks[newGiftId] = _url; // event create new Gift for msg.sender Creation(msg.sender, newGiftId); // This will assign ownership, and also emit the Transfer event as // per ERC721 draft _transfer(0, msg.sender, newGiftId); return newGiftId; } /// @dev get Gift property /// @param GiftId : id of Gift /// @return properties of Gift function getGift(uint256 GiftId) public constant returns (uint256, string){ if(GiftId > giftStorage.length){ return (0, ""); } Gift memory newGift = giftStorage[GiftId]; return (newGift.price, newGift.description); } /// @dev change gift properties /// @param GiftId : to change /// @param _price : new price of gift /// @param _description : new description /// @param _giftUrl : new url function updateGift(uint256 GiftId, uint256 _price, string _description, string _giftUrl) public onlyOwner { // check Gift exist First require(GiftExists[GiftId]); // setting new properties giftStorage[GiftId].price = _price; giftStorage[GiftId].description = _description; GiftLinks[GiftId] = _giftUrl; } /// @dev remove gift /// @param GiftId : gift id to remove function removeGift(uint256 GiftId) public onlyOwner { // just setting GiftExists equal to false GiftExists[GiftId] = false; } /// @dev withdraw GTO in this contract function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); } }
withdrawGTO
function withdrawGTO() onlyOwner public { GTO.transfer(owner, GTO.balanceOf(address(this))); }
/// @dev withdraw GTO in this contract
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://a2e49411b8b3459abd2801f8b6271c168d85abe5aa91b462fbbc9efdfcd46734
{ "func_code_index": [ 13681, 13804 ] }
56,307
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
IBEP20
interface IBEP20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 158, 230 ] }
56,308
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
IBEP20
interface IBEP20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 446, 527 ] }
56,309
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
IBEP20
interface IBEP20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 798, 885 ] }
56,310
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
IBEP20
interface IBEP20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 1534, 1612 ] }
56,311
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
IBEP20
interface IBEP20 { function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 1915, 2016 ] }
56,312
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
add
function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; }
/** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 248, 428 ] }
56,313
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); }
/** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 695, 833 ] }
56,314
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; }
/** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 1120, 1311 ] }
56,315
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mul
function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; }
/** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 1554, 2017 ] }
56,316
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
div
function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); }
/** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 2475, 2609 ] }
56,317
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
div
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; }
/** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 3087, 3363 ] }
56,318
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mod
function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 3810, 3942 ] }
56,319
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mod
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 4409, 4576 ] }
56,320
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an BNB balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
isContract
function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); }
/** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 588, 1202 ] }
56,321
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an BNB balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
sendValue
function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); }
/** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 2115, 2510 ] }
56,322
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an BNB balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCall
function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); }
/** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 3247, 3422 ] }
56,323
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an BNB balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCall
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 3640, 3838 ] }
56,324
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an BNB balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an BNB balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 4196, 4424 ] }
56,325
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an BNB balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); }
/** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 4668, 4985 ] }
56,326
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Ownable
contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = now + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(now > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
owner
function owner() public view returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 547, 628 ] }
56,327
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Ownable
contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = now + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(now > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 1171, 1320 ] }
56,328
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Ownable
contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = now + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(now > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 1465, 1709 ] }
56,329
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Ownable
contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = now + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(now > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
lock
function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = now + time; emit OwnershipTransferred(_owner, address(0)); }
//Locks the contract for owner for the amount of time provided
LineComment
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 1871, 2084 ] }
56,330
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Ownable
contract Ownable is Context { address private _owner; address private _previousOwner; uint256 private _lockTime; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } function geUnlockTime() public view returns (uint256) { return _lockTime; } //Locks the contract for owner for the amount of time provided function lock(uint256 time) public virtual onlyOwner { _previousOwner = _owner; _owner = address(0); _lockTime = now + time; emit OwnershipTransferred(_owner, address(0)); } //Unlocks the contract for owner when _lockTime is exceeds function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(now > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
unlock
function unlock() public virtual { require(_previousOwner == msg.sender, "You don't have permission to unlock"); require(now > _lockTime , "Contract is locked until 7 days"); emit OwnershipTransferred(_owner, _previousOwner); _owner = _previousOwner; }
//Unlocks the contract for owner when _lockTime is exceeds
LineComment
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 2153, 2445 ] }
56,331
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Token
contract Token is Context, IBEP20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 1000000000 * 10**6 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private _name = "Roronoa Zoro"; string private _symbol = "RZ"; uint8 private _decimals = 9; address public treasury; uint256 public _taxFee = 1; uint256 private _previousTaxFee = _taxFee; uint256 public _liquidityFee = 5; uint256 private _previousLiquidityFee = _liquidityFee; uint256 public _treasuryFee = 4; uint256 private _previousTreasuryFee = _treasuryFee; IPancakeRouter02 public immutable pancakeRouter; address public immutable pancakePair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; uint256 public _maxTxAmount = 20000000 * 10**6 * 10**9; uint256 private numTokensSellToAddToLiquidity = 5000000 * 10**6 * 10**9; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity ); modifier lockTheSwap { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } constructor (address pancakeRouter_, address treasury_) public { _rOwned[_msgSender()] = _rTotal; treasury = treasury_; IPancakeRouter02 _pancakeRouter = IPancakeRouter02(pancakeRouter_); // Create a pancake pair for this new token pancakePair = IPancakeFactory(_pancakeRouter.factory()) .createPair(address(this), _pancakeRouter.WETH()); // set the rest of the contract variables pancakeRouter = _pancakeRouter; //exclude owner, treasury and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[treasury] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "BEP20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "BEP20: decreased allowance below zero")); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner() { require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function setTaxFeePercent(uint256 taxFee) external onlyOwner() { _taxFee = taxFee; } function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { _liquidityFee = liquidityFee; } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { _maxTxAmount = _tTotal.mul(maxTxPercent).div( 10**2 ); } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } //to recieve BNB from pancakeRouter when swaping receive() external payable {} function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity, tTreasury); } function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateLiquidityFee(tAmount); uint256 tTreasury = calculateTreasuryFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity).sub(tTreasury); return (tTransferAmount, tFee, tLiquidity, tTreasury); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function _takeTreasury(uint256 tTreasury) private { uint256 currentRate = _getRate(); uint256 rTreasury = tTreasury.mul(currentRate); _rOwned[treasury] = _rOwned[treasury].add(rTreasury); if(_isExcluded[treasury]) _tOwned[treasury] = _tOwned[treasury].add(rTreasury); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div( 10**2 ); } function calculateTreasuryFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_treasuryFee).div( 10**2 ); } function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_liquidityFee).div( 10**2 ); } function removeAllFee() private { if(_taxFee == 0 && _liquidityFee == 0 && _treasuryFee == 0) return; _previousTaxFee = _taxFee; _previousLiquidityFee = _liquidityFee; _previousTreasuryFee = _treasuryFee; _taxFee = 0; _liquidityFee = 0; _treasuryFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _liquidityFee = _previousLiquidityFee; _treasuryFee = _previousTreasuryFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "BEP20: approve from the zero address"); require(spender != address(0), "BEP20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "BEP20: transfer from the zero address"); require(to != address(0), "BEP20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if(from != owner() && to != owner()) require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap + liquidity lock? // also, don't get caught in a circular liquidity event. // also, don't swap & liquify if sender is pancake pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if ( overMinTokenBalance && !inSwapAndLiquify && from != pancakePair && swapAndLiquifyEnabled ) { contractTokenBalance = numTokensSellToAddToLiquidity; //add liquidity swapAndLiquify(contractTokenBalance); } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } //transfer amount, it will take tax, burn, liquidity fee _tokenTransfer(from,to,amount,takeFee); } function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves uint256 half = contractTokenBalance.div(2); uint256 otherHalf = contractTokenBalance.sub(half); // capture the contract's current BNB balance. // this is so that we can capture exactly the amount of BNB that the // swap creates, and not make the liquidity event include any BNB that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for BNB swapTokensForEth(half); // <- this breaks the BNB -> HATE swap when swap+liquify is triggered // how much BNB did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); // add liquidity to pancake addLiquidity(otherHalf, newBalance); emit SwapAndLiquify(half, newBalance, otherHalf); } function swapTokensForEth(uint256 tokenAmount) private { // generate the pancake pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = pancakeRouter.WETH(); _approve(address(this), address(pancakeRouter), tokenAmount); // make the swap pancakeRouter.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of BNB path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(pancakeRouter), tokenAmount); // add the liquidity pancakeRouter.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable owner(), block.timestamp ); } //this method is responsible for taking all fee, if takeFee is true function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } }
//to recieve BNB from pancakeRouter when swaping
LineComment
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 8020, 8053 ] }
56,332
Token
contracts/Token.sol
0x846024eb1aed2cf3df30d592509b63fa54f96a03
Solidity
Token
contract Token is Context, IBEP20, Ownable { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcludedFromFee; mapping (address => bool) private _isExcluded; address[] private _excluded; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 1000000000 * 10**6 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; string private _name = "Roronoa Zoro"; string private _symbol = "RZ"; uint8 private _decimals = 9; address public treasury; uint256 public _taxFee = 1; uint256 private _previousTaxFee = _taxFee; uint256 public _liquidityFee = 5; uint256 private _previousLiquidityFee = _liquidityFee; uint256 public _treasuryFee = 4; uint256 private _previousTreasuryFee = _treasuryFee; IPancakeRouter02 public immutable pancakeRouter; address public immutable pancakePair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; uint256 public _maxTxAmount = 20000000 * 10**6 * 10**9; uint256 private numTokensSellToAddToLiquidity = 5000000 * 10**6 * 10**9; event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify( uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity ); modifier lockTheSwap { inSwapAndLiquify = true; _; inSwapAndLiquify = false; } constructor (address pancakeRouter_, address treasury_) public { _rOwned[_msgSender()] = _rTotal; treasury = treasury_; IPancakeRouter02 _pancakeRouter = IPancakeRouter02(pancakeRouter_); // Create a pancake pair for this new token pancakePair = IPancakeFactory(_pancakeRouter.factory()) .createPair(address(this), _pancakeRouter.WETH()); // set the rest of the contract variables pancakeRouter = _pancakeRouter; //exclude owner, treasury and this contract from fee _isExcludedFromFee[owner()] = true; _isExcludedFromFee[treasury] = true; _isExcludedFromFee[address(this)] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } function totalSupply() public view override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "BEP20: transfer amount exceeds allowance")); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "BEP20: decreased allowance below zero")); return true; } function isExcludedFromReward(address account) public view returns (bool) { return _isExcluded[account]; } function totalFees() public view returns (uint256) { return _tFeeTotal; } function deliver(uint256 tAmount) public { address sender = _msgSender(); require(!_isExcluded[sender], "Excluded addresses cannot call this function"); (uint256 rAmount,,,,,,) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rTotal = _rTotal.sub(rAmount); _tFeeTotal = _tFeeTotal.add(tAmount); } function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) { require(tAmount <= _tTotal, "Amount must be less than supply"); if (!deductTransferFee) { (uint256 rAmount,,,,,,) = _getValues(tAmount); return rAmount; } else { (,uint256 rTransferAmount,,,,,) = _getValues(tAmount); return rTransferAmount; } } function tokenFromReflection(uint256 rAmount) public view returns(uint256) { require(rAmount <= _rTotal, "Amount must be less than total reflections"); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function excludeFromReward(address account) public onlyOwner() { require(!_isExcluded[account], "Account is already excluded"); if(_rOwned[account] > 0) { _tOwned[account] = tokenFromReflection(_rOwned[account]); } _isExcluded[account] = true; _excluded.push(account); } function includeInReward(address account) external onlyOwner() { require(_isExcluded[account], "Account is already excluded"); for (uint256 i = 0; i < _excluded.length; i++) { if (_excluded[i] == account) { _excluded[i] = _excluded[_excluded.length - 1]; _tOwned[account] = 0; _isExcluded[account] = false; _excluded.pop(); break; } } } function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function excludeFromFee(address account) public onlyOwner { _isExcludedFromFee[account] = true; } function includeInFee(address account) public onlyOwner { _isExcludedFromFee[account] = false; } function setTaxFeePercent(uint256 taxFee) external onlyOwner() { _taxFee = taxFee; } function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() { _liquidityFee = liquidityFee; } function setMaxTxPercent(uint256 maxTxPercent) external onlyOwner() { _maxTxAmount = _tTotal.mul(maxTxPercent).div( 10**2 ); } function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner { swapAndLiquifyEnabled = _enabled; emit SwapAndLiquifyEnabledUpdated(_enabled); } //to recieve BNB from pancakeRouter when swaping receive() external payable {} function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getTValues(tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate()); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity, tTreasury); } function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256) { uint256 tFee = calculateTaxFee(tAmount); uint256 tLiquidity = calculateLiquidityFee(tAmount); uint256 tTreasury = calculateTreasuryFee(tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity).sub(tTreasury); return (tTransferAmount, tFee, tLiquidity, tTreasury); } function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rLiquidity = tLiquidity.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; for (uint256 i = 0; i < _excluded.length; i++) { if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(_rOwned[_excluded[i]]); tSupply = tSupply.sub(_tOwned[_excluded[i]]); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function _takeLiquidity(uint256 tLiquidity) private { uint256 currentRate = _getRate(); uint256 rLiquidity = tLiquidity.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity); if(_isExcluded[address(this)]) _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } function _takeTreasury(uint256 tTreasury) private { uint256 currentRate = _getRate(); uint256 rTreasury = tTreasury.mul(currentRate); _rOwned[treasury] = _rOwned[treasury].add(rTreasury); if(_isExcluded[treasury]) _tOwned[treasury] = _tOwned[treasury].add(rTreasury); } function calculateTaxFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_taxFee).div( 10**2 ); } function calculateTreasuryFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_treasuryFee).div( 10**2 ); } function calculateLiquidityFee(uint256 _amount) private view returns (uint256) { return _amount.mul(_liquidityFee).div( 10**2 ); } function removeAllFee() private { if(_taxFee == 0 && _liquidityFee == 0 && _treasuryFee == 0) return; _previousTaxFee = _taxFee; _previousLiquidityFee = _liquidityFee; _previousTreasuryFee = _treasuryFee; _taxFee = 0; _liquidityFee = 0; _treasuryFee = 0; } function restoreAllFee() private { _taxFee = _previousTaxFee; _liquidityFee = _previousLiquidityFee; _treasuryFee = _previousTreasuryFee; } function isExcludedFromFee(address account) public view returns(bool) { return _isExcludedFromFee[account]; } function _approve(address owner, address spender, uint256 amount) private { require(owner != address(0), "BEP20: approve from the zero address"); require(spender != address(0), "BEP20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "BEP20: transfer from the zero address"); require(to != address(0), "BEP20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if(from != owner() && to != owner()) require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount."); // is the token balance of this contract address over the min number of // tokens that we need to initiate a swap + liquidity lock? // also, don't get caught in a circular liquidity event. // also, don't swap & liquify if sender is pancake pair. uint256 contractTokenBalance = balanceOf(address(this)); if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity; if ( overMinTokenBalance && !inSwapAndLiquify && from != pancakePair && swapAndLiquifyEnabled ) { contractTokenBalance = numTokensSellToAddToLiquidity; //add liquidity swapAndLiquify(contractTokenBalance); } //indicates if fee should be deducted from transfer bool takeFee = true; //if any account belongs to _isExcludedFromFee account then remove the fee if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){ takeFee = false; } //transfer amount, it will take tax, burn, liquidity fee _tokenTransfer(from,to,amount,takeFee); } function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap { // split the contract balance into halves uint256 half = contractTokenBalance.div(2); uint256 otherHalf = contractTokenBalance.sub(half); // capture the contract's current BNB balance. // this is so that we can capture exactly the amount of BNB that the // swap creates, and not make the liquidity event include any BNB that // has been manually sent to the contract uint256 initialBalance = address(this).balance; // swap tokens for BNB swapTokensForEth(half); // <- this breaks the BNB -> HATE swap when swap+liquify is triggered // how much BNB did we just swap into? uint256 newBalance = address(this).balance.sub(initialBalance); // add liquidity to pancake addLiquidity(otherHalf, newBalance); emit SwapAndLiquify(half, newBalance, otherHalf); } function swapTokensForEth(uint256 tokenAmount) private { // generate the pancake pair path of token -> weth address[] memory path = new address[](2); path[0] = address(this); path[1] = pancakeRouter.WETH(); _approve(address(this), address(pancakeRouter), tokenAmount); // make the swap pancakeRouter.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, // accept any amount of BNB path, address(this), block.timestamp ); } function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private { // approve token transfer to cover all possible scenarios _approve(address(this), address(pancakeRouter), tokenAmount); // add the liquidity pancakeRouter.addLiquidityETH{value: ethAmount}( address(this), tokenAmount, 0, // slippage is unavoidable 0, // slippage is unavoidable owner(), block.timestamp ); } //this method is responsible for taking all fee, if takeFee is true function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); } function _transferStandard(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferToExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private { (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tTreasury) = _getValues(tAmount); _tOwned[sender] = _tOwned[sender].sub(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeLiquidity(tLiquidity); _takeTreasury(tTreasury); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } }
_tokenTransfer
function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) private { if(!takeFee) removeAllFee(); if (_isExcluded[sender] && !_isExcluded[recipient]) { _transferFromExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && _isExcluded[recipient]) { _transferToExcluded(sender, recipient, amount); } else if (!_isExcluded[sender] && !_isExcluded[recipient]) { _transferStandard(sender, recipient, amount); } else if (_isExcluded[sender] && _isExcluded[recipient]) { _transferBothExcluded(sender, recipient, amount); } else { _transferStandard(sender, recipient, amount); } if(!takeFee) restoreAllFee(); }
//this method is responsible for taking all fee, if takeFee is true
LineComment
v0.6.12+commit.27d51765
GNU GPLv3
{ "func_code_index": [ 16299, 17119 ] }
56,333
NIFTYFRIENDS
@openzeppelin/contracts/access/Ownable.sol
0x079d1091bb4b37da98a3b326bfb0443f71f8aa9f
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
owner
function owner() public view virtual returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://c9e444f64315dc9599cbc7ab35ec1fc6bb20f4e178d40d08e0a8c7cfc2a0a2c2
{ "func_code_index": [ 399, 491 ] }
56,334
NIFTYFRIENDS
@openzeppelin/contracts/access/Ownable.sol
0x079d1091bb4b37da98a3b326bfb0443f71f8aa9f
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); }
/** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://c9e444f64315dc9599cbc7ab35ec1fc6bb20f4e178d40d08e0a8c7cfc2a0a2c2
{ "func_code_index": [ 1050, 1149 ] }
56,335
NIFTYFRIENDS
@openzeppelin/contracts/access/Ownable.sol
0x079d1091bb4b37da98a3b326bfb0443f71f8aa9f
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.8.7+commit.e28d00a7
None
ipfs://c9e444f64315dc9599cbc7ab35ec1fc6bb20f4e178d40d08e0a8c7cfc2a0a2c2
{ "func_code_index": [ 1299, 1496 ] }
56,336
NIFTYFRIENDS
@openzeppelin/contracts/access/Ownable.sol
0x079d1091bb4b37da98a3b326bfb0443f71f8aa9f
Solidity
NIFTYFRIENDS
contract NIFTYFRIENDS is ERC721Enumerable, Ownable { using Strings for uint256; string baseURI; string public baseExtension = ".json"; uint256 public cost = 0.00 ether; uint256 public maxSupply = 10000; uint256 public maxMintAmount = 5; bool public paused = false; bool public revealed = true; string public notRevealedUri; constructor( string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri ) ERC721(_name, _symbol) { setBaseURI(_initBaseURI); setNotRevealedURI(_initNotRevealedUri); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(uint256 _mintAmount) public payable { uint256 supply = totalSupply(); require(!paused); require(_mintAmount > 0); require(_mintAmount <= maxMintAmount); require(supply + _mintAmount <= maxSupply); if (msg.sender != owner()) { require(msg.value >= cost * _mintAmount); } for (uint256 i = 1; i <= _mintAmount; i++) { _safeMint(msg.sender, supply + i); } } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory tokenIds = new uint256[](ownerTokenCount); for (uint256 i; i < ownerTokenCount; i++) { tokenIds[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIds; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if(revealed == false) { return notRevealedUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)) : ""; } //only owner function reveal() public onlyOwner { revealed = true; } function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner { maxMintAmount = _newmaxMintAmount; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function pause(bool _state) public onlyOwner { paused = _state; } function withdraw() public payable onlyOwner { // This will pay 5% of the initial sale to whoever you share it with. // You can remove this if you want, or keep it in. // ============================================================================= (bool hs, ) = payable(0xEAdA96BF164643bDFe3e657a9f380854694a49DD).call{value: address(this).balance * 5 / 100}(""); require(hs); // ============================================================================= // This will payout the owner 95% of the contract balance. // Do not remove this otherwise you will not be able to withdraw the funds. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } }
_baseURI
function _baseURI() internal view virtual override returns (string memory) { return baseURI; }
// internal
LineComment
v0.8.7+commit.e28d00a7
None
ipfs://c9e444f64315dc9599cbc7ab35ec1fc6bb20f4e178d40d08e0a8c7cfc2a0a2c2
{ "func_code_index": [ 626, 731 ] }
56,337
NIFTYFRIENDS
@openzeppelin/contracts/access/Ownable.sol
0x079d1091bb4b37da98a3b326bfb0443f71f8aa9f
Solidity
NIFTYFRIENDS
contract NIFTYFRIENDS is ERC721Enumerable, Ownable { using Strings for uint256; string baseURI; string public baseExtension = ".json"; uint256 public cost = 0.00 ether; uint256 public maxSupply = 10000; uint256 public maxMintAmount = 5; bool public paused = false; bool public revealed = true; string public notRevealedUri; constructor( string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri ) ERC721(_name, _symbol) { setBaseURI(_initBaseURI); setNotRevealedURI(_initNotRevealedUri); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(uint256 _mintAmount) public payable { uint256 supply = totalSupply(); require(!paused); require(_mintAmount > 0); require(_mintAmount <= maxMintAmount); require(supply + _mintAmount <= maxSupply); if (msg.sender != owner()) { require(msg.value >= cost * _mintAmount); } for (uint256 i = 1; i <= _mintAmount; i++) { _safeMint(msg.sender, supply + i); } } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory tokenIds = new uint256[](ownerTokenCount); for (uint256 i; i < ownerTokenCount; i++) { tokenIds[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIds; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if(revealed == false) { return notRevealedUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)) : ""; } //only owner function reveal() public onlyOwner { revealed = true; } function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner { maxMintAmount = _newmaxMintAmount; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function pause(bool _state) public onlyOwner { paused = _state; } function withdraw() public payable onlyOwner { // This will pay 5% of the initial sale to whoever you share it with. // You can remove this if you want, or keep it in. // ============================================================================= (bool hs, ) = payable(0xEAdA96BF164643bDFe3e657a9f380854694a49DD).call{value: address(this).balance * 5 / 100}(""); require(hs); // ============================================================================= // This will payout the owner 95% of the contract balance. // Do not remove this otherwise you will not be able to withdraw the funds. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } }
mint
function mint(uint256 _mintAmount) public payable { uint256 supply = totalSupply(); require(!paused); require(_mintAmount > 0); require(_mintAmount <= maxMintAmount); require(supply + _mintAmount <= maxSupply); if (msg.sender != owner()) { require(msg.value >= cost * _mintAmount); } for (uint256 i = 1; i <= _mintAmount; i++) { _safeMint(msg.sender, supply + i); } }
// public
LineComment
v0.8.7+commit.e28d00a7
None
ipfs://c9e444f64315dc9599cbc7ab35ec1fc6bb20f4e178d40d08e0a8c7cfc2a0a2c2
{ "func_code_index": [ 747, 1183 ] }
56,338
NIFTYFRIENDS
@openzeppelin/contracts/access/Ownable.sol
0x079d1091bb4b37da98a3b326bfb0443f71f8aa9f
Solidity
NIFTYFRIENDS
contract NIFTYFRIENDS is ERC721Enumerable, Ownable { using Strings for uint256; string baseURI; string public baseExtension = ".json"; uint256 public cost = 0.00 ether; uint256 public maxSupply = 10000; uint256 public maxMintAmount = 5; bool public paused = false; bool public revealed = true; string public notRevealedUri; constructor( string memory _name, string memory _symbol, string memory _initBaseURI, string memory _initNotRevealedUri ) ERC721(_name, _symbol) { setBaseURI(_initBaseURI); setNotRevealedURI(_initNotRevealedUri); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(uint256 _mintAmount) public payable { uint256 supply = totalSupply(); require(!paused); require(_mintAmount > 0); require(_mintAmount <= maxMintAmount); require(supply + _mintAmount <= maxSupply); if (msg.sender != owner()) { require(msg.value >= cost * _mintAmount); } for (uint256 i = 1; i <= _mintAmount; i++) { _safeMint(msg.sender, supply + i); } } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory tokenIds = new uint256[](ownerTokenCount); for (uint256 i; i < ownerTokenCount; i++) { tokenIds[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIds; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if(revealed == false) { return notRevealedUri; } string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)) : ""; } //only owner function reveal() public onlyOwner { revealed = true; } function setCost(uint256 _newCost) public onlyOwner { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner { maxMintAmount = _newmaxMintAmount; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function pause(bool _state) public onlyOwner { paused = _state; } function withdraw() public payable onlyOwner { // This will pay 5% of the initial sale to whoever you share it with. // You can remove this if you want, or keep it in. // ============================================================================= (bool hs, ) = payable(0xEAdA96BF164643bDFe3e657a9f380854694a49DD).call{value: address(this).balance * 5 / 100}(""); require(hs); // ============================================================================= // This will payout the owner 95% of the contract balance. // Do not remove this otherwise you will not be able to withdraw the funds. // ============================================================================= (bool os, ) = payable(owner()).call{value: address(this).balance}(""); require(os); // ============================================================================= } }
reveal
function reveal() public onlyOwner { revealed = true; }
//only owner
LineComment
v0.8.7+commit.e28d00a7
None
ipfs://c9e444f64315dc9599cbc7ab35ec1fc6bb20f4e178d40d08e0a8c7cfc2a0a2c2
{ "func_code_index": [ 2059, 2127 ] }
56,339
cmBondVault
cmBondVault.sol
0x1432836593443b413f86a1d2721af8f09b4d29d7
Solidity
Context
contract Context { constructor () internal { } // solhint-disable-previous-line no-empty-blocks function _msgSender() internal view returns (address payable) { return msg.sender; } function _msgData() internal view returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
_msgSender
function _msgSender() internal view returns (address payable) { return msg.sender; }
// solhint-disable-previous-line no-empty-blocks
LineComment
v0.5.17+commit.d19bba13
None
bzzr://dd2f077cf973b8c156cfef368ef2aeff5f9de8fbd3d925bb7099c69b8d64ce50
{ "func_code_index": [ 109, 212 ] }
56,340
cmBondVault
cmBondVault.sol
0x1432836593443b413f86a1d2721af8f09b4d29d7
Solidity
cmBondVault
contract cmBondVault is ERC20, ERC20Detailed { using SafeERC20 for IERC20; using Address for address; using SafeMath for uint256; IERC20 public token; uint public min = 9500; uint public constant max = 10000; uint public earnLowerlimit; //池内空余资金到这个值就自动earn uint public bondRatio = 1; address public governance; address public controller; constructor (address _token,uint _earnLowerlimit,uint _bondratio,string memory _bondcode) public ERC20Detailed( string(abi.encodePacked("contractmint.bond.", ERC20Detailed(_token).symbol())), string(abi.encodePacked("cmbond.", _bondcode)), ERC20Detailed(_token).decimals() ) { token = IERC20(_token); governance = tx.origin; controller = 0x03Cc018e952Ee7d0F4Ea3444785F0fA910cc73A6; earnLowerlimit = _earnLowerlimit; bondRatio = _bondratio; } function balance() public view returns (uint) { return token.balanceOf(address(this)).add(Controller(controller).balanceOf(address(token))); } function balanceController() public view returns (uint) { return Controller(controller).balanceOf(address(token)); } function balanceAddress() public view returns (uint) { return token.balanceOf(address(this)); } function setMin(uint _min) external { require(msg.sender == governance, "!governance"); min = _min; } function setGovernance(address _governance) public { require(msg.sender == governance, "!governance"); governance = _governance; } function setController(address _controller) public { require(msg.sender == governance, "!governance"); controller = _controller; } function setEarnLowerlimit(uint256 _earnLowerlimit) public{ require(msg.sender == governance, "!governance"); earnLowerlimit = _earnLowerlimit; } // Custom logic in here for how much the vault allows to be borrowed // Sets minimum required on-hand to keep small withdrawals cheap function available() public view returns (uint) { return token.balanceOf(address(this)).mul(min).div(max); } function earn() public { uint _bal = available(); token.safeTransfer(controller, _bal); //USDT发送 controller Controller(controller).earn(address(token), _bal); } function depositAll() external { deposit(token.balanceOf(msg.sender)); } function deposit(uint _amount) public { uint _pool = balance(); uint _before = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), _amount); uint _after = token.balanceOf(address(this)); _amount = _after.sub(_before); // Additional check for deflationary tokens uint shares = 0; uint shares_amount = _amount; //兑换比例 if (totalSupply() == 0) { shares = shares_amount; } else { shares = (shares_amount.mul(totalSupply())).div(_pool); } _mint(msg.sender, shares); //返回存款凭据 cmBondUSDT if (token.balanceOf(address(this))>earnLowerlimit){ earn(); } } function withdrawAll() external { withdraw(balanceOf(msg.sender)); } // No rebalance implementation for lower fees and faster swaps function withdraw(uint _shares) public { //r=实际可得到的USDT uint r = (balance().mul(_shares)).div(totalSupply()); //每个iUSDT值多少USDT:公式=总的USDT/总的iUSDT _burn(msg.sender, _shares); //burn iUSST // Check balance uint b = token.balanceOf(address(this)); //b=0.15 // 超过超过缓冲池,从策略的矿池取 if (b < r) { uint _withdraw = r.sub(b); Controller(controller).withdraw(address(token), _withdraw); uint _after = token.balanceOf(address(this)); uint _diff = _after.sub(b); if (_diff < _withdraw) { r = b.add(_diff); } } token.safeTransfer(msg.sender, r); } function getPricePerFullShare() public view returns (uint) { if (totalSupply()>0) { return balance().mul(1e18).div(totalSupply()); } else { return 0; } } function tokenMove(uint _amount) public { require(msg.sender == governance, "!governance"); token.safeTransfer(msg.sender, _amount); } }
available
function available() public view returns (uint) { return token.balanceOf(address(this)).mul(min).div(max); }
// Custom logic in here for how much the vault allows to be borrowed // Sets minimum required on-hand to keep small withdrawals cheap
LineComment
v0.5.17+commit.d19bba13
None
bzzr://dd2f077cf973b8c156cfef368ef2aeff5f9de8fbd3d925bb7099c69b8d64ce50
{ "func_code_index": [ 2177, 2304 ] }
56,341
cmBondVault
cmBondVault.sol
0x1432836593443b413f86a1d2721af8f09b4d29d7
Solidity
cmBondVault
contract cmBondVault is ERC20, ERC20Detailed { using SafeERC20 for IERC20; using Address for address; using SafeMath for uint256; IERC20 public token; uint public min = 9500; uint public constant max = 10000; uint public earnLowerlimit; //池内空余资金到这个值就自动earn uint public bondRatio = 1; address public governance; address public controller; constructor (address _token,uint _earnLowerlimit,uint _bondratio,string memory _bondcode) public ERC20Detailed( string(abi.encodePacked("contractmint.bond.", ERC20Detailed(_token).symbol())), string(abi.encodePacked("cmbond.", _bondcode)), ERC20Detailed(_token).decimals() ) { token = IERC20(_token); governance = tx.origin; controller = 0x03Cc018e952Ee7d0F4Ea3444785F0fA910cc73A6; earnLowerlimit = _earnLowerlimit; bondRatio = _bondratio; } function balance() public view returns (uint) { return token.balanceOf(address(this)).add(Controller(controller).balanceOf(address(token))); } function balanceController() public view returns (uint) { return Controller(controller).balanceOf(address(token)); } function balanceAddress() public view returns (uint) { return token.balanceOf(address(this)); } function setMin(uint _min) external { require(msg.sender == governance, "!governance"); min = _min; } function setGovernance(address _governance) public { require(msg.sender == governance, "!governance"); governance = _governance; } function setController(address _controller) public { require(msg.sender == governance, "!governance"); controller = _controller; } function setEarnLowerlimit(uint256 _earnLowerlimit) public{ require(msg.sender == governance, "!governance"); earnLowerlimit = _earnLowerlimit; } // Custom logic in here for how much the vault allows to be borrowed // Sets minimum required on-hand to keep small withdrawals cheap function available() public view returns (uint) { return token.balanceOf(address(this)).mul(min).div(max); } function earn() public { uint _bal = available(); token.safeTransfer(controller, _bal); //USDT发送 controller Controller(controller).earn(address(token), _bal); } function depositAll() external { deposit(token.balanceOf(msg.sender)); } function deposit(uint _amount) public { uint _pool = balance(); uint _before = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), _amount); uint _after = token.balanceOf(address(this)); _amount = _after.sub(_before); // Additional check for deflationary tokens uint shares = 0; uint shares_amount = _amount; //兑换比例 if (totalSupply() == 0) { shares = shares_amount; } else { shares = (shares_amount.mul(totalSupply())).div(_pool); } _mint(msg.sender, shares); //返回存款凭据 cmBondUSDT if (token.balanceOf(address(this))>earnLowerlimit){ earn(); } } function withdrawAll() external { withdraw(balanceOf(msg.sender)); } // No rebalance implementation for lower fees and faster swaps function withdraw(uint _shares) public { //r=实际可得到的USDT uint r = (balance().mul(_shares)).div(totalSupply()); //每个iUSDT值多少USDT:公式=总的USDT/总的iUSDT _burn(msg.sender, _shares); //burn iUSST // Check balance uint b = token.balanceOf(address(this)); //b=0.15 // 超过超过缓冲池,从策略的矿池取 if (b < r) { uint _withdraw = r.sub(b); Controller(controller).withdraw(address(token), _withdraw); uint _after = token.balanceOf(address(this)); uint _diff = _after.sub(b); if (_diff < _withdraw) { r = b.add(_diff); } } token.safeTransfer(msg.sender, r); } function getPricePerFullShare() public view returns (uint) { if (totalSupply()>0) { return balance().mul(1e18).div(totalSupply()); } else { return 0; } } function tokenMove(uint _amount) public { require(msg.sender == governance, "!governance"); token.safeTransfer(msg.sender, _amount); } }
withdraw
function withdraw(uint _shares) public { //r=实际可得到的USDT uint r = (balance().mul(_shares)).div(totalSupply()); //每个iUSDT值多少USDT:公式=总的USDT/总的iUSDT _burn(msg.sender, _shares); //burn iUSST // Check balance uint b = token.balanceOf(address(this)); //b=0.15 // 超过超过缓冲池,从策略的矿池取 if (b < r) { uint _withdraw = r.sub(b); Controller(controller).withdraw(address(token), _withdraw); uint _after = token.balanceOf(address(this)); uint _diff = _after.sub(b); if (_diff < _withdraw) { r = b.add(_diff); } } token.safeTransfer(msg.sender, r); }
// No rebalance implementation for lower fees and faster swaps
LineComment
v0.5.17+commit.d19bba13
None
bzzr://dd2f077cf973b8c156cfef368ef2aeff5f9de8fbd3d925bb7099c69b8d64ce50
{ "func_code_index": [ 3589, 4348 ] }
56,342
MainContract
contracts/interface/ERC20Interface.sol
0x4c717a5fa94adce745dbdd1c485c0666d2656444
Solidity
ERC20Interface
interface ERC20Interface { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.5.1+commit.c8a2cb62
Apache-2.0
bzzr://e69bf3fbe12f60a6837416c5c1a771f6422a9d3f697f417d79b5104dcbaa0719
{ "func_code_index": [ 102, 162 ] }
56,343
MainContract
contracts/interface/ERC20Interface.sol
0x4c717a5fa94adce745dbdd1c485c0666d2656444
Solidity
ERC20Interface
interface ERC20Interface { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.5.1+commit.c8a2cb62
Apache-2.0
bzzr://e69bf3fbe12f60a6837416c5c1a771f6422a9d3f697f417d79b5104dcbaa0719
{ "func_code_index": [ 245, 318 ] }
56,344
MainContract
contracts/interface/ERC20Interface.sol
0x4c717a5fa94adce745dbdd1c485c0666d2656444
Solidity
ERC20Interface
interface ERC20Interface { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */
NatSpecMultiLine
v0.5.1+commit.c8a2cb62
Apache-2.0
bzzr://e69bf3fbe12f60a6837416c5c1a771f6422a9d3f697f417d79b5104dcbaa0719
{ "func_code_index": [ 542, 624 ] }
56,345
MainContract
contracts/interface/ERC20Interface.sol
0x4c717a5fa94adce745dbdd1c485c0666d2656444
Solidity
ERC20Interface
interface ERC20Interface { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */
NatSpecMultiLine
v0.5.1+commit.c8a2cb62
Apache-2.0
bzzr://e69bf3fbe12f60a6837416c5c1a771f6422a9d3f697f417d79b5104dcbaa0719
{ "func_code_index": [ 903, 991 ] }
56,346
MainContract
contracts/interface/ERC20Interface.sol
0x4c717a5fa94adce745dbdd1c485c0666d2656444
Solidity
ERC20Interface
interface ERC20Interface { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */
NatSpecMultiLine
v0.5.1+commit.c8a2cb62
Apache-2.0
bzzr://e69bf3fbe12f60a6837416c5c1a771f6422a9d3f697f417d79b5104dcbaa0719
{ "func_code_index": [ 1646, 1725 ] }
56,347
MainContract
contracts/interface/ERC20Interface.sol
0x4c717a5fa94adce745dbdd1c485c0666d2656444
Solidity
ERC20Interface
interface ERC20Interface { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */
NatSpecMultiLine
v0.5.1+commit.c8a2cb62
Apache-2.0
bzzr://e69bf3fbe12f60a6837416c5c1a771f6422a9d3f697f417d79b5104dcbaa0719
{ "func_code_index": [ 2038, 2140 ] }
56,348
Factory
Factory.sol
0x8e6fff605143f9f274f7fc676f0366e4a2a43258
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } }
transfer
function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; }
/** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://d949078960924e5f41ba9d7e157eb8b5cf17ba6f8582067b31943077b3fbbbc9
{ "func_code_index": [ 268, 659 ] }
56,349
Factory
Factory.sol
0x8e6fff605143f9f274f7fc676f0366e4a2a43258
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; } }
balanceOf
function balanceOf(address _owner) public constant returns (uint256 balance) { return balances[_owner]; }
/** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://d949078960924e5f41ba9d7e157eb8b5cf17ba6f8582067b31943077b3fbbbc9
{ "func_code_index": [ 865, 981 ] }
56,350
Factory
Factory.sol
0x8e6fff605143f9f274f7fc676f0366e4a2a43258
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; }
/** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://d949078960924e5f41ba9d7e157eb8b5cf17ba6f8582067b31943077b3fbbbc9
{ "func_code_index": [ 401, 853 ] }
56,351
Factory
Factory.sol
0x8e6fff605143f9f274f7fc676f0366e4a2a43258
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
approve
function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; }
/** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://d949078960924e5f41ba9d7e157eb8b5cf17ba6f8582067b31943077b3fbbbc9
{ "func_code_index": [ 1485, 1675 ] }
56,352
Factory
Factory.sol
0x8e6fff605143f9f274f7fc676f0366e4a2a43258
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
allowance
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; }
/** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://d949078960924e5f41ba9d7e157eb8b5cf17ba6f8582067b31943077b3fbbbc9
{ "func_code_index": [ 1999, 2144 ] }
56,353
Factory
Factory.sol
0x8e6fff605143f9f274f7fc676f0366e4a2a43258
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
increaseApproval
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; }
/** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://d949078960924e5f41ba9d7e157eb8b5cf17ba6f8582067b31943077b3fbbbc9
{ "func_code_index": [ 2389, 2662 ] }
56,354
SolidarityDnToken
SolidarityDnToken.sol
0x299bdf0e6878e958177a4cde76411fc17138a2b0
Solidity
SolidarityDnToken
contract SolidarityDnToken is ERC20Mintable { // name of the token string private _name = "SolidarityDnToken"; // symbol of the token string private _symbol = "SOLDN"; // decimals of the token uint8 private _decimals = 18; // limit of emission (minting) uint256 public emissionLimit = 1000000000000* 10 ** 18; // if additional minting of tokens is impossible bool public mintingFinished; // registered contracts (to prevent loss of token via transfer function) mapping (address => bool) private _contracts; // prevent minting of tokens when it is finished. // prevent total supply to exceed the limit of emission. modifier canMint(uint256 amount) { require(amount > 0); require(!mintingFinished); require(totalSupply().add(amount) <= emissionLimit); _; } /** * @dev constructor function that is called once at deployment of the contract. * @param initialOwner Address of owner. */ constructor(address initialOwner) public Ownable(initialOwner) { } /** * @dev ERC20 mint function (available only to the minters). * @param account Address to mint token. * @param amount Amount of tokens to mint. */ function mint(address account, uint256 amount) public onlyMinter canMint(amount) returns (bool) { _mint(account, amount); return true; } /** * @dev Stop any additional minting of tokens forever. * Available only to the minters. */ function finishMinting() external onlyMinter { mintingFinished = true; } /** * @dev Allows to send tokens (via Approve and TransferFrom) to other smart contract. * @param spender Address of smart contracts to work with. * @param amount Amount of tokens to send. * @param extraData Any extra data. */ function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) { require(approve(spender, amount)); IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData); return true; } /** * @dev Allows to register other smart contracts (to prevent loss of tokens via transfer function). * @param addr Address of smart contracts to work with. */ function registerContract(address addr) public onlyOwner { require(_isContract(addr)); _contracts[addr] = true; } /** * @dev Allows to unregister registered smart contracts. * @param addr Address of smart contracts to work with. */ function unregisterContract(address addr) external onlyOwner { _contracts[addr] = false; } /** * @dev modified transfer function that allows to safely send tokens to smart contract. * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { if (_contracts[to]) { approveAndCall(to, value, new bytes(0)); } else { super.transfer(to, value); } return true; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } /** * @return true if the address is a сontract */ function _isContract(address addr) internal view returns (bool) { uint size; assembly { size := extcodesize(addr) } return size > 0; } }
/** * @title The main project contract. * @author https://grox.solutions */
NatSpecMultiLine
mint
function mint(address account, uint256 amount) public onlyMinter canMint(amount) returns (bool) { _mint(account, amount); return true; }
/** * @dev ERC20 mint function (available only to the minters). * @param account Address to mint token. * @param amount Amount of tokens to mint. */
NatSpecMultiLine
v0.5.12+commit.7709ece9
None
bzzr://241cf645f2f5629c7849fdd192492ef5387929b54ac35e8c200ba9deebc3443f
{ "func_code_index": [ 1292, 1456 ] }
56,355
SolidarityDnToken
SolidarityDnToken.sol
0x299bdf0e6878e958177a4cde76411fc17138a2b0
Solidity
SolidarityDnToken
contract SolidarityDnToken is ERC20Mintable { // name of the token string private _name = "SolidarityDnToken"; // symbol of the token string private _symbol = "SOLDN"; // decimals of the token uint8 private _decimals = 18; // limit of emission (minting) uint256 public emissionLimit = 1000000000000* 10 ** 18; // if additional minting of tokens is impossible bool public mintingFinished; // registered contracts (to prevent loss of token via transfer function) mapping (address => bool) private _contracts; // prevent minting of tokens when it is finished. // prevent total supply to exceed the limit of emission. modifier canMint(uint256 amount) { require(amount > 0); require(!mintingFinished); require(totalSupply().add(amount) <= emissionLimit); _; } /** * @dev constructor function that is called once at deployment of the contract. * @param initialOwner Address of owner. */ constructor(address initialOwner) public Ownable(initialOwner) { } /** * @dev ERC20 mint function (available only to the minters). * @param account Address to mint token. * @param amount Amount of tokens to mint. */ function mint(address account, uint256 amount) public onlyMinter canMint(amount) returns (bool) { _mint(account, amount); return true; } /** * @dev Stop any additional minting of tokens forever. * Available only to the minters. */ function finishMinting() external onlyMinter { mintingFinished = true; } /** * @dev Allows to send tokens (via Approve and TransferFrom) to other smart contract. * @param spender Address of smart contracts to work with. * @param amount Amount of tokens to send. * @param extraData Any extra data. */ function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) { require(approve(spender, amount)); IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData); return true; } /** * @dev Allows to register other smart contracts (to prevent loss of tokens via transfer function). * @param addr Address of smart contracts to work with. */ function registerContract(address addr) public onlyOwner { require(_isContract(addr)); _contracts[addr] = true; } /** * @dev Allows to unregister registered smart contracts. * @param addr Address of smart contracts to work with. */ function unregisterContract(address addr) external onlyOwner { _contracts[addr] = false; } /** * @dev modified transfer function that allows to safely send tokens to smart contract. * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { if (_contracts[to]) { approveAndCall(to, value, new bytes(0)); } else { super.transfer(to, value); } return true; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } /** * @return true if the address is a сontract */ function _isContract(address addr) internal view returns (bool) { uint size; assembly { size := extcodesize(addr) } return size > 0; } }
/** * @title The main project contract. * @author https://grox.solutions */
NatSpecMultiLine
finishMinting
function finishMinting() external onlyMinter { mintingFinished = true; }
/** * @dev Stop any additional minting of tokens forever. * Available only to the minters. */
NatSpecMultiLine
v0.5.12+commit.7709ece9
None
bzzr://241cf645f2f5629c7849fdd192492ef5387929b54ac35e8c200ba9deebc3443f
{ "func_code_index": [ 1576, 1667 ] }
56,356
SolidarityDnToken
SolidarityDnToken.sol
0x299bdf0e6878e958177a4cde76411fc17138a2b0
Solidity
SolidarityDnToken
contract SolidarityDnToken is ERC20Mintable { // name of the token string private _name = "SolidarityDnToken"; // symbol of the token string private _symbol = "SOLDN"; // decimals of the token uint8 private _decimals = 18; // limit of emission (minting) uint256 public emissionLimit = 1000000000000* 10 ** 18; // if additional minting of tokens is impossible bool public mintingFinished; // registered contracts (to prevent loss of token via transfer function) mapping (address => bool) private _contracts; // prevent minting of tokens when it is finished. // prevent total supply to exceed the limit of emission. modifier canMint(uint256 amount) { require(amount > 0); require(!mintingFinished); require(totalSupply().add(amount) <= emissionLimit); _; } /** * @dev constructor function that is called once at deployment of the contract. * @param initialOwner Address of owner. */ constructor(address initialOwner) public Ownable(initialOwner) { } /** * @dev ERC20 mint function (available only to the minters). * @param account Address to mint token. * @param amount Amount of tokens to mint. */ function mint(address account, uint256 amount) public onlyMinter canMint(amount) returns (bool) { _mint(account, amount); return true; } /** * @dev Stop any additional minting of tokens forever. * Available only to the minters. */ function finishMinting() external onlyMinter { mintingFinished = true; } /** * @dev Allows to send tokens (via Approve and TransferFrom) to other smart contract. * @param spender Address of smart contracts to work with. * @param amount Amount of tokens to send. * @param extraData Any extra data. */ function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) { require(approve(spender, amount)); IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData); return true; } /** * @dev Allows to register other smart contracts (to prevent loss of tokens via transfer function). * @param addr Address of smart contracts to work with. */ function registerContract(address addr) public onlyOwner { require(_isContract(addr)); _contracts[addr] = true; } /** * @dev Allows to unregister registered smart contracts. * @param addr Address of smart contracts to work with. */ function unregisterContract(address addr) external onlyOwner { _contracts[addr] = false; } /** * @dev modified transfer function that allows to safely send tokens to smart contract. * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { if (_contracts[to]) { approveAndCall(to, value, new bytes(0)); } else { super.transfer(to, value); } return true; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } /** * @return true if the address is a сontract */ function _isContract(address addr) internal view returns (bool) { uint size; assembly { size := extcodesize(addr) } return size > 0; } }
/** * @title The main project contract. * @author https://grox.solutions */
NatSpecMultiLine
approveAndCall
function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) { require(approve(spender, amount)); IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData); return true; }
/** * @dev Allows to send tokens (via Approve and TransferFrom) to other smart contract. * @param spender Address of smart contracts to work with. * @param amount Amount of tokens to send. * @param extraData Any extra data. */
NatSpecMultiLine
v0.5.12+commit.7709ece9
None
bzzr://241cf645f2f5629c7849fdd192492ef5387929b54ac35e8c200ba9deebc3443f
{ "func_code_index": [ 1932, 2223 ] }
56,357
SolidarityDnToken
SolidarityDnToken.sol
0x299bdf0e6878e958177a4cde76411fc17138a2b0
Solidity
SolidarityDnToken
contract SolidarityDnToken is ERC20Mintable { // name of the token string private _name = "SolidarityDnToken"; // symbol of the token string private _symbol = "SOLDN"; // decimals of the token uint8 private _decimals = 18; // limit of emission (minting) uint256 public emissionLimit = 1000000000000* 10 ** 18; // if additional minting of tokens is impossible bool public mintingFinished; // registered contracts (to prevent loss of token via transfer function) mapping (address => bool) private _contracts; // prevent minting of tokens when it is finished. // prevent total supply to exceed the limit of emission. modifier canMint(uint256 amount) { require(amount > 0); require(!mintingFinished); require(totalSupply().add(amount) <= emissionLimit); _; } /** * @dev constructor function that is called once at deployment of the contract. * @param initialOwner Address of owner. */ constructor(address initialOwner) public Ownable(initialOwner) { } /** * @dev ERC20 mint function (available only to the minters). * @param account Address to mint token. * @param amount Amount of tokens to mint. */ function mint(address account, uint256 amount) public onlyMinter canMint(amount) returns (bool) { _mint(account, amount); return true; } /** * @dev Stop any additional minting of tokens forever. * Available only to the minters. */ function finishMinting() external onlyMinter { mintingFinished = true; } /** * @dev Allows to send tokens (via Approve and TransferFrom) to other smart contract. * @param spender Address of smart contracts to work with. * @param amount Amount of tokens to send. * @param extraData Any extra data. */ function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) { require(approve(spender, amount)); IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData); return true; } /** * @dev Allows to register other smart contracts (to prevent loss of tokens via transfer function). * @param addr Address of smart contracts to work with. */ function registerContract(address addr) public onlyOwner { require(_isContract(addr)); _contracts[addr] = true; } /** * @dev Allows to unregister registered smart contracts. * @param addr Address of smart contracts to work with. */ function unregisterContract(address addr) external onlyOwner { _contracts[addr] = false; } /** * @dev modified transfer function that allows to safely send tokens to smart contract. * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { if (_contracts[to]) { approveAndCall(to, value, new bytes(0)); } else { super.transfer(to, value); } return true; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } /** * @return true if the address is a сontract */ function _isContract(address addr) internal view returns (bool) { uint size; assembly { size := extcodesize(addr) } return size > 0; } }
/** * @title The main project contract. * @author https://grox.solutions */
NatSpecMultiLine
registerContract
function registerContract(address addr) public onlyOwner { require(_isContract(addr)); _contracts[addr] = true; }
/** * @dev Allows to register other smart contracts (to prevent loss of tokens via transfer function). * @param addr Address of smart contracts to work with. */
NatSpecMultiLine
v0.5.12+commit.7709ece9
None
bzzr://241cf645f2f5629c7849fdd192492ef5387929b54ac35e8c200ba9deebc3443f
{ "func_code_index": [ 2410, 2551 ] }
56,358
SolidarityDnToken
SolidarityDnToken.sol
0x299bdf0e6878e958177a4cde76411fc17138a2b0
Solidity
SolidarityDnToken
contract SolidarityDnToken is ERC20Mintable { // name of the token string private _name = "SolidarityDnToken"; // symbol of the token string private _symbol = "SOLDN"; // decimals of the token uint8 private _decimals = 18; // limit of emission (minting) uint256 public emissionLimit = 1000000000000* 10 ** 18; // if additional minting of tokens is impossible bool public mintingFinished; // registered contracts (to prevent loss of token via transfer function) mapping (address => bool) private _contracts; // prevent minting of tokens when it is finished. // prevent total supply to exceed the limit of emission. modifier canMint(uint256 amount) { require(amount > 0); require(!mintingFinished); require(totalSupply().add(amount) <= emissionLimit); _; } /** * @dev constructor function that is called once at deployment of the contract. * @param initialOwner Address of owner. */ constructor(address initialOwner) public Ownable(initialOwner) { } /** * @dev ERC20 mint function (available only to the minters). * @param account Address to mint token. * @param amount Amount of tokens to mint. */ function mint(address account, uint256 amount) public onlyMinter canMint(amount) returns (bool) { _mint(account, amount); return true; } /** * @dev Stop any additional minting of tokens forever. * Available only to the minters. */ function finishMinting() external onlyMinter { mintingFinished = true; } /** * @dev Allows to send tokens (via Approve and TransferFrom) to other smart contract. * @param spender Address of smart contracts to work with. * @param amount Amount of tokens to send. * @param extraData Any extra data. */ function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) { require(approve(spender, amount)); IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData); return true; } /** * @dev Allows to register other smart contracts (to prevent loss of tokens via transfer function). * @param addr Address of smart contracts to work with. */ function registerContract(address addr) public onlyOwner { require(_isContract(addr)); _contracts[addr] = true; } /** * @dev Allows to unregister registered smart contracts. * @param addr Address of smart contracts to work with. */ function unregisterContract(address addr) external onlyOwner { _contracts[addr] = false; } /** * @dev modified transfer function that allows to safely send tokens to smart contract. * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { if (_contracts[to]) { approveAndCall(to, value, new bytes(0)); } else { super.transfer(to, value); } return true; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } /** * @return true if the address is a сontract */ function _isContract(address addr) internal view returns (bool) { uint size; assembly { size := extcodesize(addr) } return size > 0; } }
/** * @title The main project contract. * @author https://grox.solutions */
NatSpecMultiLine
unregisterContract
function unregisterContract(address addr) external onlyOwner { _contracts[addr] = false; }
/** * @dev Allows to unregister registered smart contracts. * @param addr Address of smart contracts to work with. */
NatSpecMultiLine
v0.5.12+commit.7709ece9
None
bzzr://241cf645f2f5629c7849fdd192492ef5387929b54ac35e8c200ba9deebc3443f
{ "func_code_index": [ 2695, 2804 ] }
56,359
SolidarityDnToken
SolidarityDnToken.sol
0x299bdf0e6878e958177a4cde76411fc17138a2b0
Solidity
SolidarityDnToken
contract SolidarityDnToken is ERC20Mintable { // name of the token string private _name = "SolidarityDnToken"; // symbol of the token string private _symbol = "SOLDN"; // decimals of the token uint8 private _decimals = 18; // limit of emission (minting) uint256 public emissionLimit = 1000000000000* 10 ** 18; // if additional minting of tokens is impossible bool public mintingFinished; // registered contracts (to prevent loss of token via transfer function) mapping (address => bool) private _contracts; // prevent minting of tokens when it is finished. // prevent total supply to exceed the limit of emission. modifier canMint(uint256 amount) { require(amount > 0); require(!mintingFinished); require(totalSupply().add(amount) <= emissionLimit); _; } /** * @dev constructor function that is called once at deployment of the contract. * @param initialOwner Address of owner. */ constructor(address initialOwner) public Ownable(initialOwner) { } /** * @dev ERC20 mint function (available only to the minters). * @param account Address to mint token. * @param amount Amount of tokens to mint. */ function mint(address account, uint256 amount) public onlyMinter canMint(amount) returns (bool) { _mint(account, amount); return true; } /** * @dev Stop any additional minting of tokens forever. * Available only to the minters. */ function finishMinting() external onlyMinter { mintingFinished = true; } /** * @dev Allows to send tokens (via Approve and TransferFrom) to other smart contract. * @param spender Address of smart contracts to work with. * @param amount Amount of tokens to send. * @param extraData Any extra data. */ function approveAndCall(address spender, uint256 amount, bytes memory extraData) public returns (bool) { require(approve(spender, amount)); IApproveAndCallFallBack(spender).receiveApproval(msg.sender, amount, address(this), extraData); return true; } /** * @dev Allows to register other smart contracts (to prevent loss of tokens via transfer function). * @param addr Address of smart contracts to work with. */ function registerContract(address addr) public onlyOwner { require(_isContract(addr)); _contracts[addr] = true; } /** * @dev Allows to unregister registered smart contracts. * @param addr Address of smart contracts to work with. */ function unregisterContract(address addr) external onlyOwner { _contracts[addr] = false; } /** * @dev modified transfer function that allows to safely send tokens to smart contract. * @param to The address to transfer to. * @param value The amount to be transferred. */ function transfer(address to, uint256 value) public returns (bool) { if (_contracts[to]) { approveAndCall(to, value, new bytes(0)); } else { super.transfer(to, value); } return true; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } /** * @return true if the address is a сontract */ function _isContract(address addr) internal view returns (bool) { uint size; assembly { size := extcodesize(addr) } return size > 0; } }
/** * @title The main project contract. * @author https://grox.solutions */
NatSpecMultiLine
transfer
function transfer(address to, uint256 value) public returns (bool) { if (_contracts[to]) { approveAndCall(to, value, new bytes(0)); } else { super.transfer(to, value); } return true; }
/** * @dev modified transfer function that allows to safely send tokens to smart contract. * @param to The address to transfer to. * @param value The amount to be transferred. */
NatSpecMultiLine
v0.5.12+commit.7709ece9
None
bzzr://241cf645f2f5629c7849fdd192492ef5387929b54ac35e8c200ba9deebc3443f
{ "func_code_index": [ 3015, 3277 ] }
56,360