-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle edge case during feature extraction (#1811)
* Update requirements.txt * use eth-abi * Update requirements.txt * Handle edge case during feature extraction
- Loading branch information
Showing
3 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
contract Regression_1 { | ||
mapping (address => uint256) private userBalances; | ||
|
||
uint256 public constant TOKEN_PRICE = 1 ether; | ||
string public constant name = "Moon Token"; | ||
string public constant symbol = "MOON"; | ||
|
||
// The token is non-divisible | ||
// You can buy/sell/transfer 1, 2, 3, or 46 tokens but not 33.5 | ||
uint8 public constant decimals = 0; | ||
|
||
uint256 public totalSupply; | ||
|
||
function buy(uint256 _amount) external payable { | ||
require( | ||
msg.value == _amount * TOKEN_PRICE, | ||
"Ether submitted and Token amount to buy mismatch" | ||
); | ||
|
||
userBalances[msg.sender] += _amount; | ||
totalSupply += _amount; | ||
} | ||
|
||
function sell(uint256 _amount) external { | ||
require(userBalances[msg.sender] >= _amount, "Insufficient balance"); | ||
|
||
userBalances[msg.sender] -= _amount; | ||
totalSupply -= _amount; | ||
|
||
(bool success, ) = msg.sender.call{value: _amount * TOKEN_PRICE}(""); | ||
require(success, "Failed to send Ether"); | ||
|
||
assert(getEtherBalance() == totalSupply * TOKEN_PRICE); | ||
} | ||
|
||
function transfer(address _to, uint256 _amount) external { | ||
require(_to != address(0), "_to address is not valid"); | ||
require(userBalances[msg.sender] >= _amount, "Insufficient balance"); | ||
|
||
userBalances[msg.sender] -= _amount; | ||
userBalances[_to] += _amount; | ||
} | ||
|
||
function getEtherBalance() public view returns (uint256) { | ||
return address(this).balance; | ||
} | ||
|
||
function getUserBalance(address _user) external view returns (uint256) { | ||
return userBalances[_user]; | ||
} | ||
} |