From 036f1fc355b82acf1170cbdadad22e4d69eef4a3 Mon Sep 17 00:00:00 2001 From: Joseph Delong Date: Thu, 13 Dec 2018 01:13:59 -0600 Subject: [PATCH 1/2] update greeter contract for modern solc --- src/main/solidity/greeter/Greeter.sol | 33 ++++++++------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/main/solidity/greeter/Greeter.sol b/src/main/solidity/greeter/Greeter.sol index 2a2ea98..996ada5 100644 --- a/src/main/solidity/greeter/Greeter.sol +++ b/src/main/solidity/greeter/Greeter.sol @@ -1,40 +1,27 @@ -pragma solidity ^0.4.25; - -// Modified Greeter contract. Based on example at https://www.ethereum.org/greeter. +pragma solidity >=0.4.22 <0.6.0; contract Mortal { - /* Define variable owner of the type address*/ + /* Define variable owner of the type address */ address owner; - /* this function is executed at initialization and sets the owner of the contract */ - constructor () public { owner = msg.sender; } + /* This constructor is executed at initialization and sets the owner of the contract */ + constructor() public { owner = msg.sender; } /* Function to recover the funds on the contract */ - function kill() public { if (msg.sender == owner) selfdestruct(owner); } + function kill() public { if (msg.sender == owner) selfdestruct(msg.sender); } } contract Greeter is Mortal { - /* define variable greeting of the type string */ + /* Define variable greeting of the type string */ string greeting; - /* this runs when the contract is executed */ - constructor (string _greeting) public { + /* This runs when the contract is executed */ + constructor(string memory _greeting) public { greeting = _greeting; } - function newGreeting(string _greeting) public { - emit Modified(greeting, _greeting, greeting, _greeting); - greeting = _greeting; - } - - /* main function */ - function greet() public constant returns (string) { + /* Main function */ + function greet() public view returns (string memory) { return greeting; } - - /* we include indexed events to demonstrate the difference that can be - captured versus non-indexed */ - event Modified( - string indexed oldGreetingIdx, string indexed newGreetingIdx, - string oldGreeting, string newGreeting); } From d623f4f91bed4c0755e24bd612ee410cb94c6cd2 Mon Sep 17 00:00:00 2001 From: Joseph Delong Date: Thu, 13 Dec 2018 09:55:17 -0600 Subject: [PATCH 2/2] add event methods and newGreeting method --- src/main/solidity/greeter/Greeter.sol | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/solidity/greeter/Greeter.sol b/src/main/solidity/greeter/Greeter.sol index 996ada5..38c98d0 100644 --- a/src/main/solidity/greeter/Greeter.sol +++ b/src/main/solidity/greeter/Greeter.sol @@ -20,8 +20,19 @@ contract Greeter is Mortal { greeting = _greeting; } + function newGreeting(string memory _greeting) public { + emit Modified(greeting, _greeting, greeting, _greeting); + greeting = _greeting; + } + /* Main function */ function greet() public view returns (string memory) { return greeting; } -} + + /* we include indexed events to demonstrate the difference that can be +captured versus non-indexed */ + event Modified( + string indexed oldGreetingIdx, string indexed newGreetingIdx, + string oldGreeting, string newGreeting); +} \ No newline at end of file