From e80f203efc70ef5787a78626a9f10cf5517b178e Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Tue, 17 Apr 2018 13:36:11 -0700 Subject: Inlined decodeMetadata in the proxies and removed encodeMetadata (already exists in Typescript). This simplifies the code. --- .../AssetProxyDispatcher/proxies/ERC20Proxy.sol | 34 +---------------- .../AssetProxyDispatcher/proxies/ERC721Proxy.sol | 43 ++-------------------- 2 files changed, 5 insertions(+), 72 deletions(-) (limited to 'packages/contracts/src') diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol index b327eb7b6..e785bd26d 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC20Proxy.sol @@ -42,39 +42,9 @@ contract ERC20Proxy is external onlyAuthorized { - address token = decodeMetadata(assetMetadata); + require(assetMetadata.length == 21); + address token = readAddress(assetMetadata, 1); bool success = ERC20Token(token).transferFrom(from, to, amount); require(success == true); } - - /// @dev Decodes ERC20-encoded byte array. - /// @param assetMetadata ERC20-encoded byte array. - /// @return tokenAddress Address of ERC20 token. - function decodeMetadata(bytes memory assetMetadata) - public pure - returns (address tokenAddress) - { - require(assetMetadata.length == 21); - return readAddress(assetMetadata, 1); - } - - /// @dev Encodes ERC20 byte array. - /// @param assetProxyId Id of the asset proxy. - /// @param tokenAddress Address of the asset. - /// @return assetMetadata ERC20-encoded byte. - function encodeMetadata( - uint8 assetProxyId, - address tokenAddress) - public pure - returns (bytes memory assetMetadata) - { - // 0 is reserved as invalid proxy id - require(assetProxyId != 0); - - // Encode fields into a byte array - assetMetadata = new bytes(21); - assetMetadata[0] = byte(assetProxyId); - writeAddress(assetMetadata, 1, tokenAddress); - return assetMetadata; - } } 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 404d1ca6e..9021acd40 100644 --- a/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol +++ b/packages/contracts/src/contracts/current/protocol/AssetProxyDispatcher/proxies/ERC721Proxy.sol @@ -46,50 +46,13 @@ contract ERC721Proxy is require(amount == 1); // Decode metadata - address token; - uint256 tokenId; - (token, tokenId) = decodeMetadata(assetMetadata); + require(assetMetadata.length == 53); + address token = readAddress(assetMetadata, 1); + uint256 tokenId = readUint256(assetMetadata, 21); // Either succeeds or throws. // @TODO: Call safeTransferFrom if there is additional // data stored in `assetMetadata`. ERC721Token(token).transferFrom(from, to, tokenId); } - - /// @dev Decodes ERC721-encoded byte array. - /// @param assetMetadata ERC721-encoded byte array. - /// @return tokenAddress Address of ERC721 token. - /// @return tokenId Id of ERC721 token. - function decodeMetadata(bytes memory assetMetadata) - public pure - returns (address tokenAddress, uint256 tokenId) - { - require(assetMetadata.length == 53); - tokenAddress = readAddress(assetMetadata, 1); - tokenId = readUint256(assetMetadata, 21); - return (tokenAddress, tokenId); - } - - /// @dev Encodes ERC721 byte array. - /// @param assetProxyId Id of the asset proxy. - /// @param tokenAddress Address of the asset. - /// @param tokenId Id of ERC721 token. - /// @return assetMetadata ERC721-encoded byte array. - function encodeMetadata( - uint8 assetProxyId, - address tokenAddress, - uint256 tokenId) - public pure - returns (bytes memory assetMetadata) - { - // 0 is reserved as invalid proxy id - require(assetProxyId != 0); - - // Encode fields into a byte array - assetMetadata = new bytes(53); - assetMetadata[0] = byte(assetProxyId); - writeAddress(assetMetadata, 1, tokenAddress); - writeUint256(assetMetadata, 21, tokenId); - return assetMetadata; - } } -- cgit v1.2.3