From 787102e0b1feb3cd622f592f0b4a671ac0b82ef5 Mon Sep 17 00:00:00 2001 From: Matheus Alencar Date: Mon, 19 Nov 2018 11:05:32 -0200 Subject: [PATCH] fix(t2cr): simplify item status --- .../TwoPartyArbitrableEscrowPayment.sol | 67 +++++++++++++++++++ .../permission/ArbitrableTokenList.sol | 11 ++- 2 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 contracts/standard/arbitration/TwoPartyArbitrableEscrowPayment.sol diff --git a/contracts/standard/arbitration/TwoPartyArbitrableEscrowPayment.sol b/contracts/standard/arbitration/TwoPartyArbitrableEscrowPayment.sol new file mode 100644 index 00000000..cee0f001 --- /dev/null +++ b/contracts/standard/arbitration/TwoPartyArbitrableEscrowPayment.sol @@ -0,0 +1,67 @@ +pragma solidity ^0.4.24; + +import "./Arbitrable.sol"; + +contract TwoPartyArbitrableEscrowPayment is Arbitrable { + address public sender; + address public receiver; + uint public value; + bytes public extraData; + Arbitrator public arbitrator; + uint public disputeID; + bool public disputed; + bool public appealed; + bool public executed; + uint public createdAt; + uint public timeOut; + + modifier onlySenderOrReceiver{ + require(msg.sender == sender || msg.sender == receiver, "Can only be called by the sender or the receiver."); + _; + } + + constructor(address _receiver, bytes _extraData, Arbitrator _arbitrator, uint _timeOut, string _metaEvidence) public payable { + sender = msg.sender; + receiver = _receiver; + value = msg.value; + extraData = _extraData; + arbitrator = _arbitrator; + createdAt = now; + timeOut = _timeOut; + emit MetaEvidence(0, _metaEvidence); + } + + function raiseDispute() public payable onlySenderOrReceiver { + disputeID = arbitrator.createDispute.value(msg.value)(2, extraData); + emit Dispute(arbitrator, disputeID, 0); + } + + function submitEvidence(string _evidence) public onlySenderOrReceiver { + require(disputed, "The payment has to be disputed."); + require(!appealed, "The payment can not be appealed."); + emit Evidence(arbitrator, disputeID, msg.sender, _evidence); + } + + function appeal() public payable onlySenderOrReceiver { + arbitrator.appeal.value(msg.value)(disputeID, extraData); + if (!appealed) appealed = true; + } + + function executePayment() public onlySenderOrReceiver { + require(now - createdAt > timeOut, "The timeout time has not passed yet."); + require(!disputed, "The payment is disputed."); + require(!executed, "The payment was already executed."); + executed = true; + receiver.send(value); + } + + function executeRuling(uint _disputeID, uint _ruling) internal { + require(disputed, "The payment is not disputed."); + require(_disputeID == disputeID, "Wrong dispute ID."); + require(!executed, "The payment was already executed."); + executed = true; + if (_ruling == 2) receiver.send(value); + else sender.send(value); + emit Ruling(arbitrator, disputeID, _ruling); + } +} diff --git a/contracts/standard/permission/ArbitrableTokenList.sol b/contracts/standard/permission/ArbitrableTokenList.sol index 2a12476d..dcd8bf46 100644 --- a/contracts/standard/permission/ArbitrableTokenList.sol +++ b/contracts/standard/permission/ArbitrableTokenList.sol @@ -17,13 +17,10 @@ contract ArbitrableTokenList is PermissionInterface, Arbitrable { /* Enums */ enum ItemStatus { - Absent, // The item has never been submitted. - Cleared, // The item has been submitted and the dispute resolution process determined it should not be added or a clearing request has been submitted and the dispute resolution process determined it should be cleared or the clearing was never contested. - Resubmitted, // The item has been cleared but someone has resubmitted it. - Registered, // The item has been submitted and the dispute resolution process determined it should be added or the submission was never contested. - Submitted, // The item has been submitted. - ClearingRequested, // The item is registered, but someone has requested to remove it. - PreventiveClearingRequested // The item has never been registered, but someone asked to clear it preemptively to avoid it being shown as not registered during the dispute resolution process. + Absent, // The item is not on the list. + Registered, // The item is on the list. + RegistrationRequested, // The item has a request to be added to the list. + ClearingRequested // The item has a request to be removed from the list. } enum RulingOption {