Skip to content

Commit 8fb97a6

Browse files
authored
New type cast method + NPM publishing capabilities (#17)
* Adding test to account for #13 * Fix for #13 Multiples of 32 bytes can now be safely sliced * More tests for #13 * Bump version to v0.0.5 * Vanity updates * Add type cast method to `bytes32` * Update to the natSpec comment on top of both libraries 😄 Though I really like Nick Johnson's string library this has been built entirely by me (as opposed to what the NatSpec comment in the top said since the last commit 😄) I just copied the comment layout on top of his library and forgot to change the author 😂 * Adding Solidity highlight to gitattribute 🎉 😄 * Update package versions & prepare for NPM publish * Create a NPM ignore file to keep `truffle.js` from being published * Syntax & pragmas updates for v0.5.0
1 parent cdaba01 commit 8fb97a6

File tree

8 files changed

+721
-743
lines changed

8 files changed

+721
-743
lines changed

.gitattribute

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sol linguist-language=Solidity

.npmignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# secret stuff
2+
# ================================================
3+
secrets.json
4+
5+
# Generated stuff
6+
# ================================================
7+
build/*
8+
node_modules/*
9+
10+
# Unneeded files for NPM deployment
11+
# ================================================
12+
truffle.js

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Solidity Bytes Arrays Utils
44

5-
Bytes tightly packed arrays utility library for ethereum contracts written.
5+
Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
66

77
The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
88

contracts/AssertBytes.sol

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
pragma solidity ^0.4.19;
1+
/*
2+
* @title Solidity Bytes Assertion Library
3+
* @author Gonçalo Sá <[email protected]>
4+
*
5+
* @dev A Solidity library built to complete assertions in Solidity unit tests.
6+
* This library is compliant with the test event convention that the Truffle suite uses.
7+
*/
8+
9+
pragma solidity ^0.4.21;
210

311

412
library AssertBytes {
@@ -185,8 +193,8 @@ library AssertBytes {
185193

186194
function _report(bool result, string message) internal {
187195
if (result)
188-
TestEvent(true, "");
196+
emit TestEvent(true, "");
189197
else
190-
TestEvent(false, message);
198+
emit TestEvent(false, message);
191199
}
192200
}

contracts/BytesLib.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* @title Solidity Bytes Arrays Utils
3+
* @author Gonçalo Sá <[email protected]>
4+
*
5+
* @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
6+
* The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
7+
*/
8+
19
pragma solidity ^0.4.19;
210

311

@@ -289,6 +297,17 @@ library BytesLib {
289297
return tempUint;
290298
}
291299

300+
function toBytes32(bytes _bytes, uint _start) internal pure returns (bytes32) {
301+
require(_bytes.length >= (_start + 32));
302+
bytes32 tempBytes32;
303+
304+
assembly {
305+
tempBytes32 := mload(add(add(_bytes, 0x20), _start))
306+
}
307+
308+
return tempBytes32;
309+
}
310+
292311
function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
293312
bool success = true;
294313

0 commit comments

Comments
 (0)