ABI encoded asset data

This commit is contained in:
Remco Bloemen
2018-06-21 20:00:48 +02:00
committed by Amir Bandeali
parent f7337c1a05
commit a98ecc05af
9 changed files with 51 additions and 29 deletions

View File

@@ -30,14 +30,14 @@ contract ERC20Proxy is
MixinERC20Transfer
{
// Id of this proxy.
uint8 constant PROXY_ID = 1;
bytes4 constant PROXY_ID = 1;
/// @dev Gets the proxy id associated with the proxy address.
/// @return Proxy id.
function getProxyId()
external
view
returns (uint8)
returns (bytes4)
{
return PROXY_ID;
}

View File

@@ -30,14 +30,14 @@ contract ERC721Proxy is
MixinERC721Transfer
{
// Id of this proxy.
uint8 constant PROXY_ID = 2;
bytes4 constant PROXY_ID = 2;
/// @dev Gets the proxy id associated with the proxy address.
/// @return Proxy id.
function getProxyId()
external
view
returns (uint8)
returns (bytes4)
{
return PROXY_ID;
}

View File

@@ -42,7 +42,7 @@ contract MixinERC20Transfer is
internal
{
// Decode asset data.
address token = assetData.readAddress(0);
address token = assetData.readAddress(16);
// Transfer tokens.
// We do a raw call so we can check the success separate

View File

@@ -79,11 +79,9 @@ contract MixinERC721Transfer is
)
{
// Decode asset data.
token = assetData.readAddress(0);
tokenId = assetData.readUint256(20);
if (assetData.length > 52) {
receiverData = assetData.readBytesWithLength(52);
}
token = assetData.readAddress(16);
tokenId = assetData.readUint256(36);
receiverData = assetData.readBytesWithLength(100);
return (
token,

View File

@@ -0,0 +1,33 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.4.23;
interface IAssetData {
function ERC20Token(
address tokenContract)
external pure;
function ERC721Token(
address tokenContract,
uint256 tokenId,
bytes receiverData)
external pure;
}

View File

@@ -56,6 +56,5 @@ contract IAssetProxy is
function getProxyId()
external
view
returns (uint8);
returns (bytes4);
}

View File

@@ -32,7 +32,7 @@ contract MixinAssetProxyDispatcher is
using LibBytes for bytes;
// Mapping from Asset Proxy Id's to their respective Asset Proxy
mapping (uint8 => IAssetProxy) public assetProxies;
mapping (bytes4 => IAssetProxy) public assetProxies;
/// @dev Registers an asset proxy to an asset proxy id.
/// An id can only be assigned to a single proxy at a given time.
@@ -40,7 +40,7 @@ contract MixinAssetProxyDispatcher is
/// @param newAssetProxy Address of new asset proxy to register, or 0x0 to unset assetProxyId.
/// @param oldAssetProxy Existing asset proxy to overwrite, or 0x0 if assetProxyId is currently unused.
function registerAssetProxy(
uint8 assetProxyId,
bytes4 assetProxyId,
address newAssetProxy,
address oldAssetProxy
)
@@ -58,7 +58,7 @@ contract MixinAssetProxyDispatcher is
// Ensure that the id of newAssetProxy matches the passed in assetProxyId, unless it is being reset to 0.
if (newAssetProxy != address(0)) {
uint8 newAssetProxyId = assetProxy.getProxyId();
bytes4 newAssetProxyId = assetProxy.getProxyId();
require(
newAssetProxyId == assetProxyId,
ASSET_PROXY_ID_MISMATCH
@@ -77,7 +77,7 @@ contract MixinAssetProxyDispatcher is
/// @dev Gets an asset proxy.
/// @param assetProxyId Id of the asset proxy.
/// @return The asset proxy registered to assetProxyId. Returns 0x0 if no proxy is registered.
function getAssetProxy(uint8 assetProxyId)
function getAssetProxy(bytes4 assetProxyId)
external
view
returns (address)
@@ -101,15 +101,7 @@ contract MixinAssetProxyDispatcher is
// Do nothing if no amount should be transferred.
if (amount > 0) {
// Lookup assetProxy
uint8 assetProxyId = uint8(assetData[assetData.length - 1]);
bytes memory assetDataP = new bytes(assetData.length - 1);
LibBytes.memCopy(
assetDataP.contentAddress(),
assetData.contentAddress(),
assetDataP.length
);
bytes4 assetProxyId = assetData.readBytes4(0);
IAssetProxy assetProxy = assetProxies[assetProxyId];
// Ensure that assetProxy exists
require(
@@ -118,7 +110,7 @@ contract MixinAssetProxyDispatcher is
);
// transferFrom will either succeed or throw.
assetProxy.transferFrom(
assetDataP,
assetData,
from,
to,
amount

View File

@@ -26,7 +26,7 @@ contract IAssetProxyDispatcher {
/// @param newAssetProxy Address of new asset proxy to register, or 0x0 to unset assetProxyId.
/// @param oldAssetProxy Existing asset proxy to overwrite, or 0x0 if assetProxyId is currently unused.
function registerAssetProxy(
uint8 assetProxyId,
bytes4 assetProxyId,
address newAssetProxy,
address oldAssetProxy
)
@@ -35,7 +35,7 @@ contract IAssetProxyDispatcher {
/// @dev Gets an asset proxy.
/// @param assetProxyId Id of the asset proxy.
/// @return The asset proxy registered to assetProxyId. Returns 0x0 if no proxy is registered.
function getAssetProxy(uint8 assetProxyId)
function getAssetProxy(bytes4 assetProxyId)
external
view
returns (address);

View File

@@ -27,7 +27,7 @@ contract MAssetProxyDispatcher is
// Logs registration of new asset proxy
event AssetProxySet(
uint8 id, // Id of new registered AssetProxy.
bytes4 id, // Id of new registered AssetProxy.
address newAssetProxy, // Address of new registered AssetProxy.
address oldAssetProxy // Address of AssetProxy that was overwritten at given id (or null address).
);