From 1707f1940d27c5de4fac65dfd5d7ef86f8a0efcf Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Wed, 11 Apr 2018 10:51:55 -0700 Subject: Replaced read/write Uint256 with generic bytes32, plus casting --- .../AssetProxyDispatcher/AssetProxyDispatcher.sol | 2 +- .../AssetProxyDispatcher/IAssetProxyDispatcher.sol | 2 +- .../AssetProxyDispatcher/proxies/ERC721Proxy.sol | 4 ++-- .../contracts/current/utils/LibBytes/LibBytes.sol | 24 +++++++++++----------- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/AssetProxyDispatcher.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/AssetProxyDispatcher.sol index b8a1fb4fe..bf5001575 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/AssetProxyDispatcher.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/AssetProxyDispatcher.sol @@ -54,7 +54,7 @@ contract AssetProxyDispatcher is assetProxy.transferFrom(assetMetadata, from, to, amount); } - /// @dev Registers a new asset proxy. + /// @dev Adds a new asset proxy. /// @param assetProxyId Id of the asset proxy. /// @param newAssetProxyAddress Address of the asset proxy contract to register. /// @param currentAssetProxyAddress Address of existing asset proxy to overwrite. diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxyDispatcher.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxyDispatcher.sol index fcd1d2d65..534be6114 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxyDispatcher.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/IAssetProxyDispatcher.sol @@ -30,7 +30,7 @@ contract IAssetProxyDispatcher is address oldAssetClassAddress ); - /// @dev Sets a new asset proxy. + /// @dev Adds a new asset proxy. /// @param assetProxyId Id of the asset proxy. /// @param newAssetProxyAddress Address of the asset proxy contract to register. /// @param currentAssetProxyAddress Address of existing asset proxy to overwrite. diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol index d4c548e62..bbad8b392 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol @@ -76,7 +76,7 @@ contract ERC721Proxy is assetMetadata = new bytes(53); assetMetadata[0] = byte(assetProxyId); writeAddress(assetMetadata, 1, tokenAddress); - writeUint256(assetMetadata, 21, tokenId); + writeBytes32(assetMetadata, 21, bytes32(tokenId)); return assetMetadata; } @@ -90,7 +90,7 @@ contract ERC721Proxy is { require(assetMetadata.length == 53); tokenAddress = readAddress(assetMetadata, 1); - tokenId = readUint256(assetMetadata, 21); + tokenId = uint256(readBytes32(assetMetadata, 21)); return (tokenAddress, tokenId); } } diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol index 59017d159..a1eca7f45 100644 --- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol +++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol @@ -81,36 +81,36 @@ contract LibBytes { } } - /// @dev Reads a uint256 value from a position in a byte array. - /// @param b Byte array containing a uint256 value. - /// @param index Index in byte array of uint256 value. - /// @return uint256 value from byte array. - function readUint256( + /// @dev Reads a bytes32 value from a position in a byte array. + /// @param b Byte array containing a bytes32 value. + /// @param index Index in byte array of bytes32 value. + /// @return bytes32 value from byte array. + function readBytes32( bytes b, uint256 index) public pure - returns (uint256 result) + returns (bytes32 result) { require(b.length >= index + 32); // Arrays are prefixed by a 256 bit length parameter index += 32; - // Read the uint256 from array memory + // Read the bytes32 from array memory assembly { result := mload(add(b, index)) } return result; } - /// @dev Writes a uint256 into a specific position in a byte array. + /// @dev Writes a bytes32 into a specific position in a byte array. /// @param b Byte array to insert into. /// @param index Index in byte array of . - /// @param input uint256 to put into byte array. - function writeUint256( + /// @param input bytes32 to put into byte array. + function writeBytes32( bytes b, uint256 index, - uint256 input) + bytes32 input) public pure { require(b.length >= index + 32); @@ -118,7 +118,7 @@ contract LibBytes { // Arrays are prefixed by a 256 bit length parameter index += 32; - // Read the uint256 from array memory + // Read the bytes32 from array memory assembly { mstore(add(b, index), input) } -- cgit v1.2.3