Skip to content

Commit

Permalink
fixation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJonaseb11 committed Jul 2, 2023
1 parent 3983f90 commit 5188713
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 57 deletions.
6 changes: 5 additions & 1 deletion ADVANCING/Math.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
pragma solidity ^o.8.0;
//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;


contract MyContract {
uint256 public value;

function calculate( uint _value1, uint _value2 ) public {
value = _value1 / _value2;
Math.divide( _value1, _value2); //does ilike the above
value = _value1.div(_value2);




Expand Down
107 changes: 52 additions & 55 deletions ADVANCING/MyContract.sol
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.4.22 <0.9.0;


import "./Math.sol";
import "./Math.sol";
import "./SafeMath.sol";

//Libraries in solidity
library Math {
function divide(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // to avoid erros
uint256 c = a / b;
return c;
}
}

contract ERC20Token {
string public name;
mapping(address => uint256) public balances;

constructor (string memory _name ) {
constructor(string memory _name) {
name = _name;

}

function mint () public {
balances[tx.origin] ++;

function mint() public {
balances[tx.origin]++;
}
}

//Inheritance of a token
contract MyToken is ERC20Token {

string public symbol;
address public owners;
uint256 ownerCount;

constructor ( string memory _name, string memory _symbol ) ERC20Token(_name) {
constructor(string memory _name, string memory _symbol) ERC20Token(_name) {
_symbol = _symbol;
}

function mint() public {
super.mint();
ownerCount ++;

owner.push( msg.sender );
}
ownerCount++;

owner.push(msg.sender);
}
}


contract MyContract {
string public value = 'My contract value';
bool public myBool = true;
int public myInt = -1;
uint public myUint = 1; //Unsigned int
uint public myUint = 1; //Unsigned int
uint8 public myUint8 = 100;
uint256 public peopleCount = 0;
mapping (uint => Person) public people;
mapping(uint => Person) public people;
address owner;
uint256 openingTime = 1687984697; //we use epoch time
address public token;
uint256 public value;


enum State { Waiting, Ready, Active }
enum State {
Waiting,
Ready,
Active
}
State public state;

using SafeMath for uint256;

function activate() public {
Expand All @@ -66,18 +72,21 @@ contract MyContract {
return state == State.Active;
}

function getContract() public view returns (string memory, bool, int, uint, uint8, State) {
return (
value,
myBool,
myInt,
myUint,
myUint8,
state
);
function getContract()
public
view
returns (string memory, bool, int, uint, uint8, State)
{
return (value, myBool, myInt, myUint, myUint8, state);
}

function setContract(string memory _value, bool _myBool, int _myInt, uint _myUint, uint8 _myUint8) public {
function setContract(
string memory _value,
bool _myBool,
int _myInt,
uint _myUint,
uint8 _myUint8
) public {
value = _value;
myBool = _myBool;
myInt = _myInt;
Expand All @@ -99,6 +108,7 @@ contract MyContract {

struct Person {
string _firstName;
uint256 value;
string _lastName;
uint _id;
}
Expand All @@ -110,7 +120,10 @@ contract MyContract {
token = _token;
}

function addPerson(string memory _firstName, string memory _lastName) public onlyOwner onlyWhileOpen {
function addPerson(
string memory _firstName,
string memory _lastName
) public onlyOwner onlyWhileOpen {
incrementCount();
people[peopleCount] = Person(_firstName, _lastName, peopleCount);
}
Expand All @@ -123,22 +136,18 @@ contract MyContract {
mapping(address => uint256) public balances;
address payable wallet;

event Purchase (
address _buyer,
uint _amount
);
event Purchase(address _buyer, uint _amount);

function buyToken() public payable {
// Buy token
balances[msg.sender] += 1;
//getting token from the ERC20 contract
//getting token from the ERC20 contract
ERC20Token _token = ERC20Token(address(token)); //.mint();
_token.mint(); //remove
// Send ether
wallet.transfer(msg.value);
//Trigger event Purchase
emit Purchase( msg.sender, 1);

emit Purchase(msg.sender, 1);
}

// Creating a fallback function
Expand All @@ -152,23 +161,11 @@ contract MyContract {
buyToken();
}

//Libraries in solidity
library Math {
function divide( uint256 a, uint256 b) internal pure returns ( uint256 ) {
require( b > 0); // to avoid erros
uint256 c = a / b;
return c;

}
}
function calculate( uint _value1, uint _value2 ) public {
function calculate(uint _value1, uint _value2) public {
value = _value1 / _value2;
Math.divide( _value1, _value2); //does ilike the above
value = SafeMath.divide( _value1, _value2);
//or
value = _value1.div(_value2);

Math.divide(_value1, _value2); //does ilike the above
value = SafeMath.divide(_value1, _value2);
//or
value = _value1.div(_value2);
}
}

a
4 changes: 3 additions & 1 deletion ADVANCING/SafeMath.sol
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
//code tp be gotten from zepplin.com

0 comments on commit 5188713

Please sign in to comment.