Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

Commit

Permalink
refactor: solidity version update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nipol committed Feb 25, 2019
1 parent 6c61219 commit f04e8ff
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 87 deletions.
48 changes: 28 additions & 20 deletions packages/vvisp-contracts/libs/BytesLib.sol
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
pragma solidity ^0.4.24;
pragma solidity >=0.5.0 <0.6.0;


/**
* @dev https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol
*/
library BytesLib {
function slice(bytes _bytes, uint _start, uint _length) internal pure returns (bytes) {
function slice(
bytes memory _bytes,
uint _start,
uint _length
)
internal
pure
returns (bytes memory)
{
require(_bytes.length >= (_start + _length));

bytes memory tempBytes;

assembly {
switch iszero(_length)
case 0 {
// Get a location of some free memory and store it in tempBytes as
// Solidity does for memory variables.
// Get a location of some free memory and store it in tempBytes as
// Solidity does for memory variables.
tempBytes := mload(0x40)

// The first word of the slice result is potentially a partial
// word read from the original array. To read it, we calculate
// the length of that partial word and start copying that many
// bytes into the array. The first word we copy will start with
// data we don't care about, but the last `lengthmod` bytes will
// land at the beginning of the contents of the new array. When
// we're done copying, we overwrite the full first word with
// the actual length of the slice.
// The first word of the slice result is potentially a partial
// word read from the original array. To read it, we calculate
// the length of that partial word and start copying that many
// bytes into the array. The first word we copy will start with
// data we don't care about, but the last `lengthmod` bytes will
// land at the beginning of the contents of the new array. When
// we're done copying, we overwrite the full first word with
// the actual length of the slice.
let lengthmod := and(_length, 31)

// The multiplication in the next line is necessary
// because when slicing multiples of 32 bytes (lengthmod == 0)
// the following copy loop was copying the origin's length
// and then ending prematurely not copying everything it should.
// The multiplication in the next line is necessary
// because when slicing multiples of 32 bytes (lengthmod == 0)
// the following copy loop was copying the origin's length
// and then ending prematurely not copying everything it should.
let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
let end := add(mc, _length)

for {
// The multiplication in the next line has the same exact purpose
// as the one above.
// The multiplication in the next line has the same exact purpose
// as the one above.
let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
} lt(mc, end) {
mc := add(mc, 0x20)
Expand All @@ -47,8 +55,8 @@ library BytesLib {

mstore(tempBytes, _length)

//update free-memory pointer
//allocating the array padded to 32 bytes like the compiler does now
//update free-memory pointer
//allocating the array padded to 32 bytes like the compiler does now
mstore(0x40, and(add(mc, 31), not(31)))
}
//if we want a zero-length slice let's just return a zero-length array
Expand Down
4 changes: 2 additions & 2 deletions packages/vvisp-contracts/upgradeable/Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity >=0.5.0 <0.6.0;


/**
Expand All @@ -11,7 +11,7 @@ contract Proxy {
* @dev Fallback function allowing to perform a delegatecall to the given implementation.
* This function will return whatever the implementation call returns
*/
function() payable public {
function() external payable {
address _impl = implementation();
require(_impl != address(0));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity >=0.5.0 <0.6.0;

import "./Proxy.sol";

Expand Down
27 changes: 21 additions & 6 deletions packages/vvisp-contracts/upgradeable/VvispLibraryRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity >=0.5.0 <0.6.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
Expand All @@ -11,7 +11,7 @@ contract VvispLibraryRegistry is Ownable {
using BytesLib for bytes;

event ProxyCreated(address _proxy, string _name);
event UpgradeAll(address[] _proxies, address[] _implementations);
event UpgradeAll(address payable[] _proxies, address[] _implementations);
event UpgradeToAndCallData(bytes _data, uint256 _index, uint256 _length);
event SetNonUpgradeable(address _address, string _name, string _fileName);
event SetFileName(address _address, string _fileName);
Expand All @@ -34,7 +34,15 @@ contract VvispLibraryRegistry is Ownable {
mapping(address => UpgradeableSet) public upgradeableSets;
mapping(address => NonUpgradeableSet) public nonUpgradeableSets;

function setNonUpgradeables(address[] _addresses, string _names, uint256[] _nameLength, string _fileNames, uint256[] _fileNameLength) public onlyOwner {
function setNonUpgradeables(
address[] memory _addresses,
string memory _names,
uint256[] memory _nameLength,
string memory _fileNames,
uint256[] memory _fileNameLength
)
public onlyOwner
{
require(_addresses.length != 0);
require(_addresses.length == _nameLength.length);
require(_addresses.length == _fileNameLength.length);
Expand All @@ -56,7 +64,7 @@ contract VvispLibraryRegistry is Ownable {
}
}

function updateFileNames(address[] _keyAddresses, string _fileNames, uint256[] _fileNameLength) public onlyOwner {
function updateFileNames(address[] memory _keyAddresses, string memory _fileNames, uint256[] memory _fileNameLength) public onlyOwner {
require(_keyAddresses.length != 0);
require(_keyAddresses.length == _fileNameLength.length);

Expand All @@ -75,14 +83,21 @@ contract VvispLibraryRegistry is Ownable {
}
}

function createProxy(string name) public onlyOwner {
function createProxy(string memory name) public onlyOwner {
VvispProxy proxy = new VvispProxy();
upgradeableKeyAddresses.push(address(proxy));
upgradeableSets[address(proxy)].name = name;
emit ProxyCreated(address(proxy), name);
}

function upgradeToAndCalls(address[] _proxies, address[] _business, bytes _data, uint256[] _length) public onlyOwner {
function upgradeToAndCalls(
address payable[] memory _proxies,
address[] memory _business,
bytes memory _data,
uint256[] memory _length
)
public onlyOwner
{
require(_proxies.length != 0);
require(_proxies.length == _business.length);
require(_proxies.length == _length.length);
Expand Down
9 changes: 5 additions & 4 deletions packages/vvisp-contracts/upgradeable/VvispProxy.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity >=0.5.0 <0.6.0;

import "./UpgradeabilityProxy.sol";

Expand Down Expand Up @@ -70,10 +70,11 @@ contract VvispProxy is UpgradeabilityProxy {
* @param data represents the msg.data to bet sent in the low level call. This parameter may include the function
* signature of the implementation to be called with the needed payload
*/
function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner {
function upgradeToAndCall(address implementation, bytes memory data) public payable onlyProxyOwner {
upgradeTo(implementation);
// solium-disable-next-line security/no-call-value
require(address(this).call.value(msg.value)(data));
// solium-disable-next-line security/no-low-level-calls
(bool success, ) = implementation.delegatecall(data);
require(success);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp-utils/contracts/DependencyA.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract DependencyA {
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp-utils/contracts/DependencyB.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract DependencyB {
Expand Down
4 changes: 2 additions & 2 deletions packages/vvisp-utils/contracts/DependencyD.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract DependencyD {
uint[] integers;
address token;
constructor(uint[] _integers, address _token) public {
constructor(uint[] memory _integers, address _token) public {
integers = _integers;
token = _token;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp-utils/contracts/ErrorContract.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.0;
pragma solidity >=0.5.0 <0.6.0;

contract ErrorContract {
function ErrorContract(){
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp-utils/contracts/MyNFT.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.24;
pragma solidity >=0.5.0 <0.6.0;

import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol';
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol';
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp-utils/contracts/SecondB.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract SecondB {
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp-utils/src/compile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = async function(filePath, options) {
const DEFAULT_COMPILER_VERSION = '0.4.24';
const DEFAULT_COMPILER_VERSION = '0.5.0';

const fs = require('fs');
const path = require('path');
Expand Down
14 changes: 7 additions & 7 deletions packages/vvisp/contracts/test/Attachment.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
Expand Down Expand Up @@ -32,8 +32,8 @@ contract Attachment is Ownable {

function upsertAttachment(
bytes32 _fileHash,
string _fileType,
string _fileName,
string memory _fileType,
string memory _fileName,
uint256 _registrationDate) public onlyOwner
{
require(_fileHash != 0);
Expand All @@ -55,20 +55,20 @@ contract Attachment is Ownable {
emit RemoveAttachment(_fileHash, beforeFileTypes, beforeFileNames, beforeRegistrationDate);
}

function upsertFileType(bytes32 _fileHash, string _fileType) internal {
function upsertFileType(bytes32 _fileHash, string memory _fileType) internal {
fileTypes[_fileHash] = _fileType;
}

function removeFileType(bytes32 _fileHash) internal returns (string before) {
function removeFileType(bytes32 _fileHash) internal returns (string memory before) {
before = fileTypes[_fileHash];
delete fileTypes[_fileHash];
}

function upsertFileName(bytes32 _fileHash, string _fileName) internal {
function upsertFileName(bytes32 _fileHash, string memory _fileName) internal {
fileNames[_fileHash] = _fileName;
}

function removeFileName(bytes32 _fileHash) internal returns (string before) {
function removeFileName(bytes32 _fileHash) internal returns (string memory before) {
before = fileNames[_fileHash];
delete fileNames[_fileHash];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp/contracts/test/DependencyA.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract DependencyA {
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp/contracts/test/DependencyB.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract DependencyB {
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp/contracts/test/DependencyC.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract DependencyC {
Expand Down
4 changes: 2 additions & 2 deletions packages/vvisp/contracts/test/DependencyD.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract DependencyD {
uint[] integers;
address token;
constructor(uint[] _integers, address _token) public {
constructor(uint[] memory _integers, address _token) public {
integers = _integers;
token = _token;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vvisp/contracts/test/Flattened.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;


contract Foo {
Expand Down
26 changes: 13 additions & 13 deletions packages/vvisp/contracts/test/Loan.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity >=0.5.0 <0.6.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
Expand Down Expand Up @@ -85,16 +85,16 @@ contract Loan is Ownable {
*/
function upsertLoan(
bytes32 _loanHash,
string _loanName,
string memory _loanName,
uint256 _loanTypeCode,
uint256 _loanAmount,
uint256[3] _rate,
uint256[3] memory _rate,
uint256 _repaymentMethodCode,
uint256[2] _fundStartEndTime,
uint256[2] _loanStartEndDate,
uint256[2] memory _fundStartEndTime,
uint256[2] memory _loanStartEndDate,
uint256 _repaymentNumber,
string _loanSummary,
string _detailHTML,
string memory _loanSummary,
string memory _detailHTML,
uint256 _stateCode,
uint256 _registrationDate)
public onlyOwner
Expand Down Expand Up @@ -186,11 +186,11 @@ contract Loan is Ownable {
beforeRegistrationDate);
}

function upsertLoanName(bytes32 _loanHash, string _loanName) internal {
function upsertLoanName(bytes32 _loanHash, string memory _loanName) internal {
loanNames[_loanHash] = _loanName;
}

function removeLoanName(bytes32 _loanHash) internal returns (string before) {
function removeLoanName(bytes32 _loanHash) internal returns (string memory before) {
before = loanNames[_loanHash];
delete loanNames[_loanHash];
}
Expand Down Expand Up @@ -294,20 +294,20 @@ contract Loan is Ownable {
delete repaymentNumbers[_loanHash];
}

function upsertLoanSummary(bytes32 _loanHash, string _loanSummary) internal {
function upsertLoanSummary(bytes32 _loanHash, string memory _loanSummary) internal {
loanSummaries[_loanHash] = _loanSummary;
}

function removeLoanSummary(bytes32 _loanHash) internal returns (string before) {
function removeLoanSummary(bytes32 _loanHash) internal returns (string memory before) {
before = loanSummaries[_loanHash];
delete loanSummaries[_loanHash];
}

function upsertDetailHTML(bytes32 _loanHash, string _detailHTML) internal {
function upsertDetailHTML(bytes32 _loanHash, string memory _detailHTML) internal {
detailHTMLs[_loanHash] = _detailHTML;
}

function removeDetailHTML(bytes32 _loanHash) internal returns (string before) {
function removeDetailHTML(bytes32 _loanHash) internal returns (string memory before) {
before = detailHTMLs[_loanHash];
delete detailHTMLs[_loanHash];
}
Expand Down
Loading

0 comments on commit f04e8ff

Please sign in to comment.