From 399dee289cc9080e87d843be44c0ab03de7871c6 Mon Sep 17 00:00:00 2001 From: Howard Yeh Date: Thu, 27 Jun 2019 11:11:40 +0800 Subject: [PATCH] fixes to contracts --- contracts/A.sol | 4 ++-- contracts/AB.sol | 12 ++++++------ contracts/ContractCreation.sol | 6 +++--- contracts/Logger.sol | 6 +++--- contracts/LoggerWithIndex.sol | 6 +++--- contracts/QtumTest.sol | 14 +++++++------- contracts/Set.sol | 8 ++++---- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/contracts/A.sol b/contracts/A.sol index a5aed96..ba75a0b 100644 --- a/contracts/A.sol +++ b/contracts/A.sol @@ -1,9 +1,9 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.5.8; contract A { uint256 a; - function A(uint256 _a) { + constructor(uint256 _a) public { a = _a; } } \ No newline at end of file diff --git a/contracts/AB.sol b/contracts/AB.sol index 2d98e20..92a6941 100644 --- a/contracts/AB.sol +++ b/contracts/AB.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.5.8; contract AB { uint256 a; @@ -6,7 +6,7 @@ contract AB { uint256 fund; - function AB(uint256 _a, int256 _b) public { + constructor(uint256 _a, int256 _b) public { a = _a; b = _b; } @@ -15,7 +15,7 @@ contract AB { fund += msg.value; } - function getBurnedFund() public constant returns(uint256) { + function getBurnedFund() public view returns(uint256) { return fund; } @@ -32,15 +32,15 @@ contract AB { b = _b; } - function getA() public constant returns(uint256) { + function getA() public view returns(uint256) { return a; } - function getB() public constant returns(int256) { + function getB() public view returns(int256) { return b; } - function getAB() public constant returns(uint256, int256) { + function getAB() public view returns(uint256, int256) { return (a, b); } } \ No newline at end of file diff --git a/contracts/ContractCreation.sol b/contracts/ContractCreation.sol index e8447d2..4af1585 100644 --- a/contracts/ContractCreation.sol +++ b/contracts/ContractCreation.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.5.1; import "./Set.sol"; @@ -8,11 +8,11 @@ contract C1 { using Set for Set.Data; // this is the crucial change Set.Data knownValues; - function C1() { + constructor() { c2 = new C2(); } - function register(uint value) { + function register(uint value) public { // Here, all variables of type Set.Data have // corresponding member functions. // The following function call is identical to diff --git a/contracts/Logger.sol b/contracts/Logger.sol index e72033d..2643bc8 100644 --- a/contracts/Logger.sol +++ b/contracts/Logger.sol @@ -1,8 +1,8 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.5.1; contract Logger { event EventLog(uint256 a, uint256 b); - function log(uint256 a, uint256 b) { - EventLog(a, b); + function log(uint256 a, uint256 b) public { + emit EventLog(a, b); } } \ No newline at end of file diff --git a/contracts/LoggerWithIndex.sol b/contracts/LoggerWithIndex.sol index 834c515..a19e1d3 100644 --- a/contracts/LoggerWithIndex.sol +++ b/contracts/LoggerWithIndex.sol @@ -1,8 +1,8 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.5.1; contract LoggerWithIndex { event EventLog(uint256 a, uint256 indexed b, uint256 c); - function log(uint256 a, uint256 b, uint256 c) { - EventLog(a, b, c); + function log(uint256 a, uint256 b, uint256 c) public { + emit EventLog(a, b, c); } } \ No newline at end of file diff --git a/contracts/QtumTest.sol b/contracts/QtumTest.sol index 1b52e0f..9f8b1e1 100644 --- a/contracts/QtumTest.sol +++ b/contracts/QtumTest.sol @@ -1,28 +1,28 @@ -pragma solidity ^0.4.0; +pragma solidity ^0.5.1; contract QtumTest { uint storedNumber; - function QtumTest() { - storedNumber=1; + constructor() public { + storedNumber = 1; } function setNumber(uint number) public{ storedNumber = number; } - function logNumber() constant public{ + function logNumber() view public{ log1("storedNumber", uintToBytes(storedNumber)); } - function returnNumber() constant public returns (uint){ + function returnNumber() view public returns (uint){ return storedNumber; } function deposit() public payable{ } function withdraw() public{ if(!msg.sender.send(this.balance)){ - throw; + revert(); } } //utility function - function uintToBytes(uint v) constant returns (bytes32 ret) { + function uintToBytes(uint v) view public returns (bytes32 ret) { if (v == 0) { ret = '0'; } diff --git a/contracts/Set.sol b/contracts/Set.sol index 1e4ddfd..38ef09e 100644 --- a/contracts/Set.sol +++ b/contracts/Set.sol @@ -1,10 +1,10 @@ -pragma solidity ^0.4.11; +pragma solidity ^0.5.1; // This is the same code as before, just without comments library Set { struct Data { mapping(uint => bool) flags; } - function insert(Data storage self, uint value) + function insert(Data storage self, uint value) public returns (bool) { if (self.flags[value]) @@ -13,7 +13,7 @@ library Set { return true; } - function remove(Data storage self, uint value) + function remove(Data storage self, uint value) public returns (bool) { if (!self.flags[value]) @@ -22,7 +22,7 @@ library Set { return true; } - function contains(Data storage self, uint value) + function contains(Data storage self, uint value) public view returns (bool) { return self.flags[value];