Skip to content

Commit 5357d11

Browse files
committed
fix: templateId
1 parent 56bb341 commit 5357d11

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

contracts/src/arbitration/arbitrables/Escrow.sol

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ contract Escrow is IArbitrableV2 {
6262
IArbitratorV2 public arbitrator; // Address of the arbitrator contract.
6363
bytes public arbitratorExtraData; // Extra data to set up the arbitration.
6464
IDisputeTemplateRegistry public templateRegistry; // The dispute template registry.
65+
uint256 public templateId; // The current dispute template identifier.
6566
uint256 public immutable feeTimeout; // Time in seconds a party can take to pay arbitration fees before being considered unresponsive and lose the dispute.
6667
Transaction[] public transactions; // List of all created transactions.
6768
mapping(uint256 => uint256) public disputeIDtoTransactionID; // Naps dispute ID to tx ID.
@@ -115,11 +116,15 @@ contract Escrow is IArbitrableV2 {
115116
/// @dev Constructor.
116117
/// @param _arbitrator The arbitrator of the contract.
117118
/// @param _arbitratorExtraData Extra data for the arbitrator.
119+
/// @param _templateData The dispute template data.
120+
/// @param _templateDataMappings The dispute template data mappings.
118121
/// @param _templateRegistry The dispute template registry.
119122
/// @param _feeTimeout Arbitration fee timeout for the parties.
120123
constructor(
121124
IArbitratorV2 _arbitrator,
122125
bytes memory _arbitratorExtraData,
126+
string memory _templateData,
127+
string memory _templateDataMappings,
123128
IDisputeTemplateRegistry _templateRegistry,
124129
uint256 _feeTimeout
125130
) {
@@ -128,6 +133,8 @@ contract Escrow is IArbitrableV2 {
128133
arbitratorExtraData = _arbitratorExtraData;
129134
templateRegistry = _templateRegistry;
130135
feeTimeout = _feeTimeout;
136+
137+
templateId = templateRegistry.setDisputeTemplate("", _templateData, _templateDataMappings);
131138
}
132139

133140
// ************************************* //
@@ -146,6 +153,13 @@ contract Escrow is IArbitrableV2 {
146153
templateRegistry = _templateRegistry;
147154
}
148155

156+
function changeDisputeTemplate(
157+
string memory _templateData,
158+
string memory _templateDataMappings
159+
) external onlyByGovernor {
160+
templateId = templateRegistry.setDisputeTemplate("", _templateData, _templateDataMappings);
161+
}
162+
149163
// ************************************* //
150164
// * State Modifiers * //
151165
// ************************************* //
@@ -233,15 +247,13 @@ contract Escrow is IArbitrableV2 {
233247
);
234248
require(msg.sender == transaction.sender, "The caller must be the sender.");
235249

236-
uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
237250
transaction.senderFee += msg.value;
238-
// Require that the total paid to be at least the arbitration cost.
251+
uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
239252
require(transaction.senderFee >= arbitrationCost, "The sender fee must cover arbitration costs.");
240253

241254
transaction.lastInteraction = block.timestamp;
242255

243-
// The receiver still has to pay. This can also happen if he has paid,
244-
// but arbitrationCost has increased.
256+
// The receiver still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
245257
if (transaction.receiverFee < arbitrationCost) {
246258
transaction.status = Status.WaitingReceiver;
247259
emit HasToPayFee(_transactionID, Party.Receiver);
@@ -262,9 +274,8 @@ contract Escrow is IArbitrableV2 {
262274
);
263275
require(msg.sender == transaction.receiver, "The caller must be the receiver.");
264276

265-
uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
266277
transaction.receiverFee += msg.value;
267-
// Require that the total paid to be at least the arbitration cost.
278+
uint256 arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
268279
require(transaction.receiverFee >= arbitrationCost, "The receiver fee must cover arbitration costs.");
269280

270281
transaction.lastInteraction = block.timestamp;
@@ -310,6 +321,27 @@ contract Escrow is IArbitrableV2 {
310321
emit TransactionResolved(_transactionID, Resolution.TimeoutByReceiver);
311322
}
312323

324+
/// @dev Give a ruling for a dispute. Must be called by the arbitrator to enforce the final ruling.
325+
/// The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
326+
/// @param _disputeID ID of the dispute in the Arbitrator contract.
327+
/// @param _ruling Ruling given by the arbitrator. Note that 0 is reserved
328+
/// for "Refuse to arbitrate".
329+
function rule(uint256 _disputeID, uint256 _ruling) external override {
330+
require(msg.sender == address(arbitrator), "The caller must be the arbitrator.");
331+
require(_ruling <= AMOUNT_OF_CHOICES, "Invalid ruling.");
332+
uint256 transactionID = disputeIDtoTransactionID[_disputeID];
333+
Transaction storage transaction = transactions[transactionID];
334+
335+
require(transaction.status == Status.DisputeCreated, "The dispute has already been resolved.");
336+
337+
emit Ruling(arbitrator, _disputeID, _ruling);
338+
executeRuling(transactionID, _ruling);
339+
}
340+
341+
// ************************************* //
342+
// * Internal * //
343+
// ************************************* //
344+
313345
/// @dev Create a dispute.
314346
/// @param _transactionID The index of the transaction.
315347
/// @param _arbitrationCost Amount to pay the arbitrator.
@@ -321,11 +353,6 @@ contract Escrow is IArbitrableV2 {
321353
arbitratorExtraData
322354
);
323355
disputeIDtoTransactionID[transaction.disputeID] = _transactionID;
324-
uint256 templateId = templateRegistry.setDisputeTemplate(
325-
"",
326-
transaction.templateData,
327-
transaction.templateDataMappings
328-
);
329356
emit DisputeRequest(arbitrator, transaction.disputeID, _transactionID, templateId, "");
330357

331358
// Refund sender if he overpaid.
@@ -343,23 +370,6 @@ contract Escrow is IArbitrableV2 {
343370
}
344371
}
345372

346-
/// @dev Give a ruling for a dispute. Must be called by the arbitrator to enforce the final ruling.
347-
/// The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
348-
/// @param _disputeID ID of the dispute in the Arbitrator contract.
349-
/// @param _ruling Ruling given by the arbitrator. Note that 0 is reserved
350-
/// for "Refuse to arbitrate".
351-
function rule(uint256 _disputeID, uint256 _ruling) external override {
352-
require(msg.sender == address(arbitrator), "The caller must be the arbitrator.");
353-
require(_ruling <= AMOUNT_OF_CHOICES, "Invalid ruling.");
354-
uint256 transactionID = disputeIDtoTransactionID[_disputeID];
355-
Transaction storage transaction = transactions[transactionID];
356-
357-
require(transaction.status == Status.DisputeCreated, "The dispute has already been resolved.");
358-
359-
emit Ruling(arbitrator, _disputeID, _ruling);
360-
executeRuling(transactionID, _ruling);
361-
}
362-
363373
/// @dev Execute a ruling of a dispute. It reimburses the fee to the winning party.
364374
/// @param _transactionID The index of the transaction.
365375
/// @param _ruling Ruling given by the arbitrator. 1 : Reimburse the receiver. 2 : Pay the sender.

0 commit comments

Comments
 (0)