Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #14 from wibsonorg/ca-changes
Browse files Browse the repository at this point in the history
Delete IdentityManager Logic
  • Loading branch information
crisadamo authored Apr 18, 2018
2 parents d67dc33 + 7280ca6 commit 49501c9
Show file tree
Hide file tree
Showing 8 changed files with 546 additions and 7,004 deletions.
57 changes: 16 additions & 41 deletions contracts/DataExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "zeppelin-solidity/contracts/ECRecovery.sol";

import "./DataOrder.sol";
import "./IdentityManager.sol";
import "./Wibcoin.sol";
import "./lib/MultiMap.sol";
import "./lib/ArrayUtils.sol";
Expand Down Expand Up @@ -44,14 +43,11 @@ contract DataExchange is Ownable, Destructible, ModifierUtils {
mapping(address => address[]) public ordersByBuyer;
mapping(address => NotaryInfo) internal notaryInfo;

// @dev buyerBalance Keeps track of the buyer's balance per order.
mapping(address => mapping(address => uint256)) public buyerBalance;

// @dev idManager Handles the users that are not yet certified by a
// Identity Notary, in which case, the funds that such user receive
// will be held by the `IdentityManager` until he pass the KYC process
// and ultimately receive the certification.
IdentityManager idManager;
// @dev buyerBalance Keeps track of the buyer's balance per order-seller.
// TODO(cristian): Is there any batter way to do this?
mapping(
address => mapping(address => mapping(address => uint256))
) public buyerBalance;

// @dev token A Wibcoin implementation of an ERC20 standard token.
Wibcoin token;
Expand Down Expand Up @@ -85,19 +81,6 @@ contract DataExchange is Ownable, Destructible, ModifierUtils {
return true;
}

/**
* @dev Set a Identity Manager.
* @notice This is needed in order to allow new orders on the `DataExchange`.
* @param identityManagerAddr Address of the given Identity Manager.
* @return Whether the IdManager was successfully added or not.
*/
function setIdentityManager(
address identityManagerAddr
) public onlyOwner returns (bool) {
idManager = IdentityManager(identityManagerAddr);
return true;
}

/**
* @dev Creates a New Order.
* @notice The `msg.sender` will become the buyer of the order.
Expand All @@ -124,7 +107,6 @@ contract DataExchange is Ownable, Destructible, ModifierUtils {
string publicKey
) public returns (address) {
require(notaries.length > 0);
require(idManager != address(0));
require(allowedNotaries.length() > 0);
// TODO(cristian): validate that notaries are within the allowed notaries
// and that are unique. This must be done here or in the
Expand All @@ -141,6 +123,10 @@ contract DataExchange is Ownable, Destructible, ModifierUtils {
);

for (uint i = 0; i < notaries.length; i++) {
if (ordersByNotary[notaries[i]].length > 0 ||
!allowedNotaries.exist(notaries[i])) {
continue;
}
ordersByNotary[notaries[i]].push(newOrderAddr);
}

Expand Down Expand Up @@ -225,7 +211,7 @@ contract DataExchange is Ownable, Destructible, ModifierUtils {
);

if (okay) {
buyerBalance[buyer][orderAddr].add(orderPrice);
buyerBalance[buyer][orderAddr][seller].add(orderPrice);
ordersBySeller[seller].push(orderAddr);
token.transferFrom(buyer, this, orderPrice);
emit DataAdded(order, seller);
Expand Down Expand Up @@ -293,14 +279,14 @@ contract DataExchange is Ownable, Destructible, ModifierUtils {
DataOrder order = DataOrder(orderAddr);
uint256 orderPrice = order.price();
address buyer = order.buyer();
address notary = order.getNotaryForSeller(seller);

require(msg.sender == buyer);
require(msg.sender == buyer || msg.sender == notary);
require(
order.hasSellerBeenAccepted(seller) ||
order.hasSellerBeenApproved(seller)
);

address notary = order.getNotaryForSeller(seller);
bytes32 hash = CryptoUtils.hashData(
orderAddr,
seller,
Expand All @@ -310,26 +296,15 @@ contract DataExchange is Ownable, Destructible, ModifierUtils {
require(CryptoUtils.isSignedBy(hash, notary, notarySignature));

if (order.closeDataResponse(seller)) {
require(buyerBalance[buyer][orderAddr] >= orderPrice);
buyerBalance[buyer][orderAddr] = buyerBalance[buyer][orderAddr].sub(orderPrice);
require(buyerBalance[buyer][orderAddr][seller] >= orderPrice);

address dest = seller;
if (!isOrderVerified) {
dest = buyer;
}

if ((idManager.isCertified(seller) && dest == seller) || dest == buyer) {
token.transfer(dest, orderPrice);
} else {
// TODO(cristian): Check possible attack/race-condition surface.
if (token.allowance(this, idManager) == 0) {
token.approve(idManager, orderPrice);
} else {
token.increaseApproval(idManager, orderPrice);
}

idManager.addFunds(dest, orderPrice);
}
buyerBalance[buyer][orderAddr][seller] =
buyerBalance[buyer][orderAddr][seller].sub(orderPrice);
token.transfer(dest, orderPrice);

emit TransactionCompleted(order, seller);
return true;
Expand Down
42 changes: 21 additions & 21 deletions contracts/DataOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
// --- Notary Information ---
struct NotaryInfo {
bool accepted;
uint acceptedAt;
uint32 acceptedAt;
}

// --- Seller Information ---
struct SellerInfo {
address notary;
string hash;
string signature;
uint closedAt;
uint createdAt;
uint notarizedAt;
uint32 closedAt;
uint32 createdAt;
uint32 notarizedAt;
DataResponseStatus status;
}

Expand All @@ -52,9 +52,9 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
string public buyerURL;
string public publicKey;
uint256 public price;
uint public createdAt;
uint public dataAddedAt;
uint public transactionCompletedAt;
uint32 public createdAt;
uint32 public dataAddedAt;
uint32 public transactionCompletedAt;
OrderStatus public orderStatus;

mapping(address => SellerInfo) public sellerInfo;
Expand Down Expand Up @@ -102,7 +102,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
buyerURL = _buyerURL;
publicKey = _publicKey;
orderStatus = OrderStatus.OrderCreated;
createdAt = block.timestamp;
createdAt = uint32(block.timestamp);
}

/**
Expand All @@ -124,7 +124,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
}

if (notaryInfo[notary].accepted != true) {
notaryInfo[notary] = NotaryInfo(true, block.timestamp);
notaryInfo[notary] = NotaryInfo(true, uint32(block.timestamp));
acceptedNotaries.push(notary);
orderStatus = OrderStatus.NotaryAccepted;
}
Expand Down Expand Up @@ -160,6 +160,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
string signature
) public onlyOwner validAddress(seller) validAddress(notary) returns (bool) {
require(notaryInfo[notary].accepted == true);
require(sellerInfo[seller].createdAt == 0);
require(orderStatus == OrderStatus.NotaryAccepted);
require(price > 0);

Expand All @@ -168,7 +169,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
hash,
signature,
0,
block.timestamp,
uint32(block.timestamp),
0,
DataResponseStatus.DataResponseAdded
);
Expand Down Expand Up @@ -199,7 +200,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
approved ? DataResponseStatus.DataResponseApproved
: DataResponseStatus.DataResponseRejected
);
sellerInfo[seller].notarizedAt = block.timestamp;
sellerInfo[seller].notarizedAt = uint32(block.timestamp);
return true;
}

Expand All @@ -215,7 +216,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {

if (hasSellerBeenAccepted(seller) || hasSellerBeenApproved(seller)) {
sellerInfo[seller].status = DataResponseStatus.TransactionCompleted;
sellerInfo[seller].closedAt = block.timestamp;
sellerInfo[seller].closedAt = uint32(block.timestamp);
return true;
}
return false;
Expand All @@ -229,7 +230,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
*/
function close() public onlyOwner returns (bool) {
orderStatus = OrderStatus.TransactionCompleted;
transactionCompletedAt = block.timestamp;
transactionCompletedAt = uint32(block.timestamp);
return true;
}

Expand Down Expand Up @@ -307,9 +308,9 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
uint256,
string,
string,
uint,
uint,
uint,
uint32,
uint32,
uint32,
bytes32
) {
SellerInfo memory info = sellerInfo[seller];
Expand All @@ -319,9 +320,9 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
price,
info.hash,
info.signature,
info.closedAt,
info.createdAt,
info.notarizedAt,
uint32(info.closedAt),
uint32(info.createdAt),
uint32(info.notarizedAt),
getDataResponseStatusAsString(info.status)
);
}
Expand All @@ -332,8 +333,7 @@ contract DataOrder is Ownable, Destructible, ModifierUtils {
* @return Address of the notary assigned to the given seller.
*/
function getNotaryForSeller(address seller) public view returns (address) {
SellerInfo memory info = sellerInfo[seller];
return info.notary;
return sellerInfo[seller].notary;
}

/**
Expand Down
120 changes: 0 additions & 120 deletions contracts/IdentityManager.sol

This file was deleted.

1 change: 0 additions & 1 deletion contracts/lib/CryptoUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ library CryptoUtils {
bytes signature
) public pure returns (bool) {
require(signer != 0x0);
// TODO(cristian): FIXME! This is a hack to satisfy geth.
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 prefixedHash = keccak256(prefix, hash);
address recovered = ECRecovery.recover(prefixedHash, signature);
Expand Down
Loading

0 comments on commit 49501c9

Please sign in to comment.