diff options
author | Remco Bloemen <remco@wicked.ventures> | 2018-06-14 00:28:11 +0800 |
---|---|---|
committer | Remco Bloemen <remco@wicked.ventures> | 2018-06-23 19:53:38 +0800 |
commit | 943e556f43a328dbb606567b06392851ba4ec3de (patch) | |
tree | cbafa8d8ab8e323683b0e31ee7ba34b19a2a67c3 /packages/contracts/src | |
parent | 4bf4f96f478ba8e08bf2d44817294ddd5fe895c5 (diff) | |
download | dexon-sol-tools-943e556f43a328dbb606567b06392851ba4ec3de.tar dexon-sol-tools-943e556f43a328dbb606567b06392851ba4ec3de.tar.gz dexon-sol-tools-943e556f43a328dbb606567b06392851ba4ec3de.tar.bz2 dexon-sol-tools-943e556f43a328dbb606567b06392851ba4ec3de.tar.lz dexon-sol-tools-943e556f43a328dbb606567b06392851ba4ec3de.tar.xz dexon-sol-tools-943e556f43a328dbb606567b06392851ba4ec3de.tar.zst dexon-sol-tools-943e556f43a328dbb606567b06392851ba4ec3de.zip |
Refactor LibBytes.readBytes4 for consistency
Diffstat (limited to 'packages/contracts/src')
3 files changed, 18 insertions, 11 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol index 261ce8f34..50c538cea 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol @@ -104,7 +104,7 @@ contract AssetProxyOwner is pure returns (bool) { - bytes4 first4Bytes = data.readFirst4(); + bytes4 first4Bytes = data.readBytes4(0); require(REMOVE_AUTHORIZED_ADDRESS_SELECTOR == first4Bytes); return true; } diff --git a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol index d14022a64..5421045a0 100644 --- a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol +++ b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol @@ -187,15 +187,19 @@ contract TestLibBytes { return b; } - /// @dev Reads the first 4 bytes from a byte array of arbitrary length. - /// @param b Byte array to read first 4 bytes from. - /// @return First 4 bytes of data. - function publicReadFirst4(bytes memory b) + /// @dev Reads an unpadded bytes4 value from a position in a byte array. + /// @param b Byte array containing a bytes4 value. + /// @param index Index in byte array of bytes4 value. + /// @return bytes4 value from byte array. + function publicReadBytes4( + bytes memory b, + uint256 index + ) public pure returns (bytes4 result) { - result = b.readFirst4(); + result = b.readBytes4(index); return result; } diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol index 3149a47e5..cbe4f3be1 100644 --- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol +++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol @@ -430,16 +430,19 @@ library LibBytes { writeBytes32(b, index, bytes32(input)); } - /// @dev Reads the first 4 bytes from a byte array of arbitrary length. - /// @param b Byte array to read first 4 bytes from. - /// @return First 4 bytes of data. - function readFirst4(bytes memory b) + /// @dev Reads an unpadded bytes4 value from a position in a byte array. + /// @param b Byte array containing a bytes4 value. + /// @param index Index in byte array of bytes4 value. + /// @return bytes4 value from byte array. + function readBytes4( + bytes memory b, + uint256 index) internal pure returns (bytes4 result) { require( - b.length >= 4, + b.length >= index + 4, GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED ); assembly { |