aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-04-26 07:21:55 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-27 01:56:44 +0800
commit9ddec32260981e714c332651ae292221e06ebc1e (patch)
treed80e8b1cbf8a0d69452f17e857491df6b644450b /packages/contracts/src
parent185e7d43fbf308cd6b2c6032adb5e8160a206d89 (diff)
downloaddexon-sol-tools-9ddec32260981e714c332651ae292221e06ebc1e.tar
dexon-sol-tools-9ddec32260981e714c332651ae292221e06ebc1e.tar.gz
dexon-sol-tools-9ddec32260981e714c332651ae292221e06ebc1e.tar.bz2
dexon-sol-tools-9ddec32260981e714c332651ae292221e06ebc1e.tar.lz
dexon-sol-tools-9ddec32260981e714c332651ae292221e06ebc1e.tar.xz
dexon-sol-tools-9ddec32260981e714c332651ae292221e06ebc1e.tar.zst
dexon-sol-tools-9ddec32260981e714c332651ae292221e06ebc1e.zip
Add tests and comments
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol11
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol21
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/mixins/MTransactions.sol7
-rw-r--r--packages/contracts/src/utils/crypto.ts2
4 files changed, 25 insertions, 16 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
index 97c1f1541..80120bc74 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
@@ -18,7 +18,6 @@
pragma solidity ^0.4.21;
pragma experimental ABIEncoderV2;
-pragma experimental "v0.5.0";
import "./mixins/MExchangeCore.sol";
import "./mixins/MSettlement.sol";
@@ -117,13 +116,13 @@ contract MixinExchangeCore is
require(isValidSignature(orderHash, order.makerAddress, signature));
}
- // Validate sender
+ // Validate sender is allowed to fill this order
if (order.senderAddress != address(0)) {
require(order.senderAddress == msg.sender);
}
- // Validate transaction signed by taker
- address takerAddress = getSignerAddress();
+ // Validate taker is allowed to fill this order
+ address takerAddress = getCurrentContextAddress();
if (order.takerAddress != address(0)) {
require(order.takerAddress == takerAddress);
}
@@ -177,13 +176,13 @@ contract MixinExchangeCore is
require(order.makerAssetAmount > 0);
require(order.takerAssetAmount > 0);
- // Validate sender
+ // Validate sender is allowed to cancel this order
if (order.senderAddress != address(0)) {
require(order.senderAddress == msg.sender);
}
// Validate transaction signed by maker
- address makerAddress = getSignerAddress();
+ address makerAddress = getCurrentContextAddress();
require(order.makerAddress == makerAddress);
if (block.timestamp >= order.expirationTimeSeconds) {
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
index e4fc4767b..9edb1694f 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
@@ -27,10 +27,11 @@ contract MixinTransactions is
{
// Mapping of transaction hash => executed
+ // This prevents transactions from being executed more than once.
mapping (bytes32 => bool) public transactions;
// Address of current transaction signer
- address currentSigner;
+ address public currentContextAddress;
/// @dev Executes an exchange method call in the context of signer.
/// @param salt Arbitrary number to ensure uniqueness of transaction hash.
@@ -45,7 +46,7 @@ contract MixinTransactions is
external
{
// Prevent reentrancy
- require(currentSigner == address(0));
+ require(currentContextAddress == address(0));
// Calculate transaction hash
bytes32 transactionHash = keccak256(
@@ -63,7 +64,7 @@ contract MixinTransactions is
require(isValidSignature(transactionHash, signer, signature));
// Set the current transaction signer
- currentSigner = signer;
+ currentContextAddress = signer;
}
// Execute transaction
@@ -71,15 +72,21 @@ contract MixinTransactions is
require(address(this).delegatecall(data));
// Reset current transaction signer
- currentSigner = address(0);
+ // TODO: Check if gas is paid when currentContextAddress is already 0.
+ currentContextAddress = address(0);
}
- function getSignerAddress()
+ /// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
+ /// If calling a fill function, this address will represent the taker.
+ /// If calling a cancel function, this address will represent the maker.
+ /// @return Signer of 0x transaction if entry point is `executeTransaction`.
+ /// `msg.sender` if entry point is any other function.
+ function getCurrentContextAddress()
internal
view
returns (address)
{
- address signerAddress = currentSigner == address(0) ? msg.sender : currentSigner;
- return signerAddress;
+ address contextAddress = currentContextAddress == address(0) ? msg.sender : currentContextAddress;
+ return contextAddress;
}
}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MTransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MTransactions.sol
index 31209de02..10bfcb035 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MTransactions.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MTransactions.sol
@@ -34,7 +34,12 @@ contract MTransactions is MSignatureValidator {
bytes signature)
external;
- function getSignerAddress()
+ /// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
+ /// If calling a fill function, this address will represent the taker.
+ /// If calling a cancel function, this address will represent the maker.
+ /// @return Signer of 0x transaction if entry point is `executeTransaction`.
+ /// `msg.sender` if entry point is any other function.
+ function getCurrentContextAddress()
internal
view
returns (address);
diff --git a/packages/contracts/src/utils/crypto.ts b/packages/contracts/src/utils/crypto.ts
index 85a37122a..222cb7cca 100644
--- a/packages/contracts/src/utils/crypto.ts
+++ b/packages/contracts/src/utils/crypto.ts
@@ -29,8 +29,6 @@ export const crypto = {
args[i] = new BN(arg.toString(10), 10);
} else if (ethUtil.isValidAddress(arg)) {
argTypes.push('address');
- } else if (arg instanceof Buffer) {
- argTypes.push('bytes');
} else if (_.isString(arg)) {
argTypes.push('string');
} else if (_.isBuffer(arg)) {