This repository was archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: throw semantic errors #109
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,50 +256,39 @@ class Disputes extends AbstractWrapper { | |
| * @param {string} account - Ethereum account. | ||
| * @param {string} arbitrableContractAddress - Address address of arbitrable contract. | ||
| * @param {number} [arbitrationCost=DEFAULT_ARBITRATION_FEE] - Amount to pay the arbitrator. | ||
| * @returns {string} - txHash hash transaction | Error. | ||
| * @returns {object} - The result transaction object. | ||
| */ | ||
| raiseDisputePartyA = async ( | ||
| raiseDisputePartyA = ( | ||
| account, | ||
| arbitrableContractAddress, | ||
| arbitrationCost = arbitratorConstants.DEFAULT_ARBITRATION_FEE | ||
| ) => { | ||
| this._checkArbitrableWrappersSet() | ||
| try { | ||
| const txHash = await this._ArbitrableContract.payArbitrationFeeByPartyA( | ||
| account, | ||
| arbitrableContractAddress, | ||
| arbitrationCost | ||
| ) | ||
|
|
||
| if (!txHash) throw new Error('unable to pay arbitration fee for party A') | ||
| return txHash | ||
| } catch (err) { | ||
| throw new Error(err) | ||
| } | ||
| return this._ArbitrableContract.payArbitrationFeeByPartyA( | ||
| account, | ||
| arbitrableContractAddress, | ||
| arbitrationCost | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Pay the arbitration fee to raise a dispute. To be called by the party B. | ||
| * @param {string} account - Ethereum account. | ||
| * @param {string} arbitrableContractAddress - Address address of arbitrable contract. | ||
| * @param {number} [arbitrationCost=DEFAULT_ARBITRATION_FEE] - Amount to pay the arbitrator. | ||
| * @returns {string} - txHash hash of the transaction | Error. | ||
| * @returns {object} - The result transaction object. | ||
| */ | ||
| raiseDisputePartyB = async ( | ||
| raiseDisputePartyB = ( | ||
| account, | ||
| arbitrableContractAddress, | ||
| arbitrationCost = arbitratorConstants.DEFAULT_ARBITRATION_FEE | ||
| ) => { | ||
| this._checkArbitrableWrappersSet() | ||
|
|
||
| const txHash = await this._ArbitrableContract.payArbitrationFeeByPartyB( | ||
| return this._ArbitrableContract.payArbitrationFeeByPartyB( | ||
| account, | ||
| arbitrableContractAddress, | ||
| arbitrationCost | ||
| ) | ||
|
|
||
| if (!txHash) throw new Error('unable to pay arbitration fee for party B') | ||
| return txHash | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -435,30 +424,23 @@ class Disputes extends AbstractWrapper { | |
| * @param {number} ruling - Int representing the jurors decision. | ||
| * @param {number[]} draws - Int[] of drawn votes for dispute. | ||
| * @param {string} account - Address of user. | ||
| * @returns {string} - Transaction hash | Error. | ||
| * @returns {object} - The result transaction object. | ||
| */ | ||
| submitVotesForDispute = async ( | ||
| submitVotesForDispute = ( | ||
| arbitratorAddress, | ||
| disputeId, | ||
| ruling, | ||
| draws, | ||
| account | ||
| ) => { | ||
| const txHash = await this._Arbitrator.submitVotes( | ||
| ) => | ||
| this._Arbitrator.submitVotes( | ||
| arbitratorAddress, | ||
| disputeId, | ||
| ruling, | ||
| draws, | ||
| account | ||
| ) | ||
|
|
||
| if (txHash) { | ||
| return txHash | ||
| } else { | ||
| throw new Error('unable to submit votes') | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the deadline for an arbitrator's period, which is also the deadline for all its disputes. | ||
| * @param {string} arbitratorAddress - The address of the arbitrator contract. | ||
|
|
@@ -580,7 +562,7 @@ class Disputes extends AbstractWrapper { | |
| ) | ||
|
|
||
| if (_.isEmpty(disputeArray)) | ||
| throw new Error(`User ${account} does not have store data for dispute`) | ||
| throw new Error(errorConstants.NO_STORE_DATA_FOR_DISPUTE(account)) | ||
|
|
||
| return disputeArray[0] | ||
| } | ||
|
|
@@ -630,17 +612,10 @@ class Disputes extends AbstractWrapper { | |
| * @returns {object[]} - Array of ruling objects. | ||
| */ | ||
| getRulingOptions = async (arbitratorAddress, disputeId) => { | ||
| const dispute = await this._Arbitrator.getDispute( | ||
| const arbitrableContractAddress = (await this._Arbitrator.getDispute( | ||
| arbitratorAddress, | ||
| disputeId | ||
| ) | ||
| if (!dispute) { | ||
| throw new Error( | ||
| `Cannot fetch ruling options: Dispute from arbitrator ${arbitratorAddress} with disputeId: ${disputeId} does not exist` | ||
| ) | ||
| } | ||
| const arbitrableContractAddress = dispute.arbitratedContract | ||
|
|
||
| )).arbitratedContract | ||
| return this._ArbitrableContract.getRulingOptions( | ||
| arbitrableContractAddress, | ||
| arbitratorAddress, | ||
|
|
@@ -660,16 +635,11 @@ class Disputes extends AbstractWrapper { | |
| this._checkArbitratorWrappersSet() | ||
| this._checkArbitrableWrappersSet() | ||
|
|
||
| // Get dispute data from contract, and throw if not found. Also get current session and period | ||
| // Get dispute data from contract. Also get the current session and period. | ||
| const [dispute, arbitratorData] = await Promise.all([ | ||
| this._Arbitrator.getDispute(arbitratorAddress, disputeId), | ||
| this._Arbitrator.getData(arbitratorAddress, account) | ||
| ]) | ||
| if (!dispute) { | ||
| throw new Error( | ||
| `Dispute with arbitrator: ${arbitratorAddress} and disputeId: ${disputeId} does not exist` | ||
| ) | ||
| } | ||
|
|
||
| // Get arbitrable contract data and evidence | ||
| const arbitrableContractAddress = dispute.arbitratedContract | ||
|
|
@@ -802,43 +772,36 @@ class Disputes extends AbstractWrapper { | |
| * @returns {int[]} - array of active disputeId | ||
| */ | ||
| _getOpenDisputesForSession = async arbitratorAddress => { | ||
| const currentSession = (await this._Arbitrator.getData(arbitratorAddress)) | ||
| .session | ||
| const openDisputes = [] | ||
| // contract data | ||
| const arbitratorData = await this._Arbitrator.getData(arbitratorAddress) | ||
| let disputeId = 0 | ||
| const currentSession = arbitratorData.session | ||
|
|
||
| let disputeId = 0 | ||
| let dispute | ||
| while (1) { | ||
| // iterate over all disputes (FIXME inefficient) | ||
| // Iterate over all the disputes | ||
| // TODO: Implement a more performant solution | ||
| try { | ||
| try { | ||
| dispute = await this._Arbitrator.getDispute( | ||
| arbitratorAddress, | ||
| disputeId | ||
| ) | ||
| // eslint-disable-next-line no-unused-vars | ||
| } catch (err) { | ||
| // FIXME standardize | ||
| throw new Error(errorConstants.TYPE.DISPUTE_OUT_OF_RANGE) | ||
| } | ||
|
|
||
| if (dispute.arbitratedContract === ethConstants.NULL_ADDRESS) break | ||
| // session + number of appeals | ||
| const disputeSession = dispute.firstSession + dispute.numberOfAppeals | ||
| // if dispute not in current session skip | ||
| if (disputeSession !== currentSession) { | ||
| disputeId++ | ||
| continue | ||
| } | ||
|
|
||
| openDisputes.push(disputeId) | ||
| // check next dispute | ||
| disputeId += 1 | ||
| dispute = await this._Arbitrator.getDispute( | ||
| arbitratorAddress, | ||
| disputeId | ||
| ) | ||
| } catch (err) { | ||
| if (err.message === errorConstants.TYPE.DISPUTE_OUT_OF_RANGE) break | ||
| // Dispute out of range, break | ||
| if (err.message === errorConstants.UNABLE_TO_FETCH_DISPUTE) break | ||
| console.error(err) | ||
| throw err | ||
| } | ||
|
|
||
| // Dispute has no arbitrable contract, break | ||
| if (dispute.arbitratedContract === ethConstants.NULL_ADDRESS) break | ||
|
|
||
| // If dispute is in the current session, add it to the result array | ||
| if (dispute.firstSession + dispute.numberOfAppeals === currentSession) | ||
| openDisputes.push(disputeId) | ||
|
|
||
| // Advance to the next dispute | ||
| disputeId++ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice. much cleaner |
||
| } | ||
|
|
||
| return openDisputes | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how clean these are now but we won't really get user friendly errors if we don't catch them since it will just throw either truffle contract or EVM errors (which I barely consider semantic). I am assuming you are planning on giving something more user friendly on the front end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm i see you throw something nice a layer lower