From 29740dc80d8acf6e68d3a76c5a0edb0351722d4a Mon Sep 17 00:00:00 2001 From: arlbibek <53701945+arlbibek@users.noreply.github.com> Date: Fri, 5 Mar 2021 17:46:42 +0545 Subject: [PATCH] Made tutorial 2 work with the Solidity ^0.7.0 version title self-explanatory --- tutorial-02/myfirstcontract.sol | 34 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tutorial-02/myfirstcontract.sol b/tutorial-02/myfirstcontract.sol index f94fce1..3f63618 100644 --- a/tutorial-02/myfirstcontract.sol +++ b/tutorial-02/myfirstcontract.sol @@ -1,57 +1,51 @@ -pragma solidity ^0.5.0; +pragma solidity ^0.7.0; -interface Regulator { +interface Regulator{ function checkValue(uint amount) external returns (bool); function loan() external returns (bool); } contract Bank is Regulator { uint private value; - - constructor(uint amount) public { + + constructor(uint amount) { value = amount; } - function deposit(uint amount) public { value += amount; } - function withdraw(uint amount) public { if (checkValue(amount)) { - value -= amount; + value -= amount; } } - function balance() public view returns (uint) { return value; } - - function checkValue(uint amount) public returns (bool) { + function checkValue(uint amount) override view public returns (bool) { // Classic mistake in the tutorial value should be above the amount return value >= amount; } - - function loan() public returns (bool) { + function loan() override view public returns (bool) { return value > 0; } } -contract MyFirstContract is Bank(10) { +// Tutorial 01 +contract myFirstContract is Bank(10) { + string private name; uint private age; - + function setName(string memory newName) public { name = newName; } - - function getName() public view returns (string memory) { - return name; - } - function setAge(uint newAge) public { age = newAge; } - + function getName() public view returns (string memory) { + return name; + } function getAge() public view returns (uint) { return age; }