Skip to content

Commit 14ca2bd

Browse files
authored
v0.0.7 - Upgrade to Solidity v0.5.0 (#22)
* (WIP) Upgrade to Solidity v0.5.0 (#21) * (refactor) Changed codebase to Solidity v0.5.0 * Style changes * Added `memory` everywhere to bytes and strings * `target.call(data)` now returns a tuple * Adding note about compiler support in the README + typo fix * Replaced the ThrowProxy pattern for a better v0.5.x one ThrowProxy was giving problems while testing with the JS-VM with the Constantinople hard-fork. So I changed the tests to stop using that pattern and use function selectors since that's now a thing. It is cleaner now. * Update package-lock.json * Bump version to v0.0.7 * Bump version in package-lock.json * Update dependency versions * Fix typo in package-lock.json
1 parent 9776282 commit 14ca2bd

9 files changed

+910
-1249
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ The library lets you concatenate, slice and type cast bytes arrays both in memor
88

99
Given this library has an all-internal collection of methods it doesn't make sense having it reside in the mainnet. Instead it will only be available in EPM as an installable package.
1010

11+
_Note_: Since version `v0.0.7` the library will only compile on Solidity versions `>0.4.22` so, if you need `v0.4.x` support for your project just use `v0.0.6` of the library with:
12+
```
13+
$ truffle install [email protected]
14+
```
15+
or
16+
```
17+
$ npm install [email protected]
18+
```
19+
1120
## Usage
1221

1322
You can use the library here present by direct download and importing with:
@@ -61,7 +70,6 @@ Contributions are more than welcome in any way shape or form! 😄
6170

6271
TODOs:
6372
* Two storage bytes arrays concatenation
64-
* Two storage bytes arrays concatenation
6573
* Slicing directly from storage
6674
* Implement inline assembly functions for better readability
6775

contracts/AssertBytes.sol

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* This library is compliant with the test event convention that the Truffle suite uses.
77
*/
88

9-
pragma solidity ^0.4.21;
9+
pragma solidity ^0.5.0;
1010

1111

1212
library AssertBytes {
@@ -69,15 +69,15 @@ library AssertBytes {
6969
return returnBool;
7070
}
7171

72-
function equal(bytes memory _a, bytes memory _b, string message) internal returns (bool) {
72+
function equal(bytes memory _a, bytes memory _b, string memory message) internal returns (bool) {
7373
bool returnBool = _equal(_a, _b);
7474

7575
_report(returnBool, message);
7676

7777
return returnBool;
7878
}
7979

80-
function notEqual(bytes memory _a, bytes memory _b, string message) internal returns (bool) {
80+
function notEqual(bytes memory _a, bytes memory _b, string memory message) internal returns (bool) {
8181
bool returnBool = _equal(_a, _b);
8282

8383
_report(!returnBool, message);
@@ -162,15 +162,15 @@ library AssertBytes {
162162
return returnBool;
163163
}
164164

165-
function equalStorage(bytes storage _a, bytes memory _b, string message) internal returns (bool) {
165+
function equalStorage(bytes storage _a, bytes memory _b, string memory message) internal returns (bool) {
166166
bool returnBool = _equalStorage(_a, _b);
167167

168168
_report(returnBool, message);
169169

170170
return returnBool;
171171
}
172172

173-
function notEqualStorage(bytes storage _a, bytes memory _b, string message) internal returns (bool) {
173+
function notEqualStorage(bytes storage _a, bytes memory _b, string memory message) internal returns (bool) {
174174
bool returnBool = _equalStorage(_a, _b);
175175

176176
_report(!returnBool, message);
@@ -191,10 +191,10 @@ library AssertBytes {
191191
message (string) - The message that is sent if the assertion fails.
192192
*/
193193

194-
function _report(bool result, string message) internal {
194+
function _report(bool result, string memory message) internal {
195195
if (result)
196196
emit TestEvent(true, "");
197197
else
198198
emit TestEvent(false, message);
199199
}
200-
}
200+
}

contracts/BytesLib.sol

+32-10
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
* The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
77
*/
88

9-
pragma solidity ^0.4.19;
9+
pragma solidity ^0.5.0;
1010

1111

1212
library BytesLib {
13-
function concat(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bytes) {
13+
function concat(
14+
bytes memory _preBytes,
15+
bytes memory _postBytes
16+
)
17+
internal
18+
pure
19+
returns (bytes memory)
20+
{
1421
bytes memory tempBytes;
1522

1623
assembly {
@@ -218,7 +225,15 @@ library BytesLib {
218225
}
219226
}
220227

221-
function slice(bytes _bytes, uint _start, uint _length) internal pure returns (bytes) {
228+
function slice(
229+
bytes memory _bytes,
230+
uint _start,
231+
uint _length
232+
)
233+
internal
234+
pure
235+
returns (bytes memory)
236+
{
222237
require(_bytes.length >= (_start + _length));
223238

224239
bytes memory tempBytes;
@@ -275,7 +290,7 @@ library BytesLib {
275290
return tempBytes;
276291
}
277292

278-
function toAddress(bytes _bytes, uint _start) internal pure returns (address) {
293+
function toAddress(bytes memory _bytes, uint _start) internal pure returns (address) {
279294
require(_bytes.length >= (_start + 20));
280295
address tempAddress;
281296

@@ -286,7 +301,7 @@ library BytesLib {
286301
return tempAddress;
287302
}
288303

289-
function toUint8(bytes _bytes, uint _start) internal pure returns (uint8) {
304+
function toUint8(bytes memory _bytes, uint _start) internal pure returns (uint8) {
290305
require(_bytes.length >= (_start + 1));
291306
uint8 tempUint;
292307

@@ -297,7 +312,7 @@ library BytesLib {
297312
return tempUint;
298313
}
299314

300-
function toUint16(bytes _bytes, uint _start) internal pure returns (uint16) {
315+
function toUint16(bytes memory _bytes, uint _start) internal pure returns (uint16) {
301316
require(_bytes.length >= (_start + 2));
302317
uint16 tempUint;
303318

@@ -308,7 +323,7 @@ library BytesLib {
308323
return tempUint;
309324
}
310325

311-
function toUint32(bytes _bytes, uint _start) internal pure returns (uint32) {
326+
function toUint32(bytes memory _bytes, uint _start) internal pure returns (uint32) {
312327
require(_bytes.length >= (_start + 4));
313328
uint32 tempUint;
314329

@@ -319,7 +334,7 @@ library BytesLib {
319334
return tempUint;
320335
}
321336

322-
function toUint(bytes _bytes, uint _start) internal pure returns (uint256) {
337+
function toUint(bytes memory _bytes, uint _start) internal pure returns (uint256) {
323338
require(_bytes.length >= (_start + 32));
324339
uint256 tempUint;
325340

@@ -330,7 +345,7 @@ library BytesLib {
330345
return tempUint;
331346
}
332347

333-
function toBytes32(bytes _bytes, uint _start) internal pure returns (bytes32) {
348+
function toBytes32(bytes memory _bytes, uint _start) internal pure returns (bytes32) {
334349
require(_bytes.length >= (_start + 32));
335350
bytes32 tempBytes32;
336351

@@ -384,7 +399,14 @@ library BytesLib {
384399
return success;
385400
}
386401

387-
function equalStorage(bytes storage _preBytes, bytes memory _postBytes) internal view returns (bool) {
402+
function equalStorage(
403+
bytes storage _preBytes,
404+
bytes memory _postBytes
405+
)
406+
internal
407+
view
408+
returns (bool)
409+
{
388410
bool success = true;
389411

390412
assembly {

contracts/Migrations.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.4.4;
1+
pragma solidity ^0.5.0;
22

33
contract Migrations {
44
address public owner;
@@ -8,7 +8,7 @@ contract Migrations {
88
if (msg.sender == owner) _;
99
}
1010

11-
function Migrations() public {
11+
constructor () public {
1212
owner = msg.sender;
1313
}
1414

ethpm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"package_name": "bytes",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Solidity bytes tightly packed arrays utility library.",
55
"authors": [
66
"Gonçalo Sá <[email protected]>"

0 commit comments

Comments
 (0)