This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
403 additions
and
210 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import _ from 'lodash' | ||
|
||
import ContractImplementation from '../../ContractImplementation' | ||
import EventListener from '../../../utils/EventListener' | ||
import httpRequest from '../../../utils/httpRequest' | ||
|
||
/** | ||
* Provides interaction with standard Arbitrable contracts | ||
*/ | ||
class Arbitrable extends ContractImplementation { | ||
/** | ||
* Constructor ArbitrableTransaction. | ||
* @param {object} web3Provider instance | ||
* @param {string} contractAddress of the contract | ||
*/ | ||
constructor(web3Provider, contractArtifact, contractAddress) { | ||
super(web3Provider, contractArtifact, contractAddress) | ||
} | ||
|
||
/** | ||
* Get the meta evidence for the contract. Arbitrable Transaction can only have | ||
* one meta-evidence that is submitted on contract creation. Look up meta-evidence event | ||
* and make an http request to the resource. | ||
*/ | ||
getMetaEvidence = async () => { | ||
const metaEvidenceLog = await EventListener.getEventLogs( | ||
this, | ||
'MetaEvidence', | ||
0, | ||
'latest', | ||
{ _metaEvidenceID: 0 } | ||
) | ||
|
||
if (!metaEvidenceLog[0]) return {} // NOTE better to throw errors for missing meta-evidence? | ||
|
||
const metaEvidenceUri = metaEvidenceLog[0].args._evidence | ||
// FIXME caching issue need a query param to fetch from AWS | ||
const metaEvidenceResponse = await httpRequest( | ||
'GET', | ||
metaEvidenceUri + '?nocache' | ||
) | ||
|
||
if (metaEvidenceResponse.status >= 400) | ||
throw new Error(`Unable to fetch meta-evidence at ${metaEvidenceUri}`) | ||
return metaEvidenceResponse.body || metaEvidenceResponse | ||
} | ||
|
||
/** | ||
* Get the evidence submitted in a dispute. | ||
*/ | ||
getEvidence = async () => { | ||
await this.loadContract() | ||
const arbitratorAddress = await this.contractInstance.arbitrator() | ||
await this.loadContract() | ||
const disputeId = (await this.contractInstance.disputeID()).toNumber() | ||
|
||
// No evidence yet as there is no dispute | ||
if (_.isNull(disputeId)) return [] | ||
|
||
const evidenceLogs = await EventListener.getEventLogs( | ||
this, | ||
'Evidence', | ||
0, | ||
'latest', | ||
{ _disputeID: disputeId, _arbitrator: arbitratorAddress } | ||
) | ||
|
||
// TODO verify hash and data are valid if hash exists | ||
return Promise.all( | ||
evidenceLogs.map(async evidenceLog => { | ||
const evidenceURI = evidenceLog.args._evidence | ||
const evidence = await httpRequest('GET', evidenceURI) | ||
const submittedAt = (await this._Web3Wrapper.getBlock( | ||
evidenceLog.blockNumber | ||
)).timestamp | ||
return { | ||
...evidence.body, | ||
...{ submittedBy: evidenceLog.args._party, submittedAt } | ||
} | ||
}) | ||
) | ||
} | ||
|
||
/** | ||
* Fetch all standard contract data. | ||
*/ | ||
getContractData = async () => { | ||
await this.loadContract() | ||
|
||
const [metaEvidence, partyA, partyB] = await Promise.all([ | ||
this.getMetaEvidence(), | ||
this.contractInstance.partyA(), | ||
this.contractInstance.partyB() | ||
]) | ||
|
||
return { | ||
partyA, | ||
partyB, | ||
metaEvidence | ||
} | ||
} | ||
} | ||
|
||
export default Arbitrable |
44 changes: 44 additions & 0 deletions
44
src/contracts/implementations/arbitrable/ArbitrablePermissionList.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import ArbitrablePermissionListArtifact from 'kleros-interaction/build/contracts/ArbitrablePermissionList' | ||
|
||
import * as ethConstants from '../../../constants/eth' | ||
import Arbitrable from './Arbitrable' | ||
import deployContractAsync from '../../../utils/deployContractAsync' | ||
|
||
/** | ||
* Provides interaction with an Arbitrable Transaction contract deployed on the blockchain. | ||
*/ | ||
class ArbitrablePermissionList extends Arbitrable { | ||
/** | ||
* Constructor ArbitrableTransaction. | ||
* @param {object} web3Provider instance | ||
* @param {string} contractAddress of the contract | ||
*/ | ||
constructor(web3Provider, contractAddress) { | ||
super(web3Provider, ArbitrablePermissionListArtifact, contractAddress) | ||
} | ||
|
||
/** | ||
* Deploy ArbitrablePermissionList. TODO | ||
* @param {object} account Ethereum account (default account[0]) | ||
* @param {number} value funds to be placed in contract | ||
* @param {object} web3Provider web3 provider object | ||
* @returns {object} truffle-contract Object | err The deployed contract or an error | ||
*/ | ||
// static deploy = async ( | ||
// account, | ||
// value = ethConstants.TRANSACTION.VALUE, | ||
// web3Provider | ||
// ) => { | ||
// // const contractDeployed = await deployContractAsync() | ||
// // | ||
// // return contractDeployed | ||
// } | ||
|
||
getItemByDisputeId = async disputeId => { | ||
await this.loadContract() | ||
|
||
return this.contractInstance.disputeIDToItem(disputeId) | ||
} | ||
} | ||
|
||
export default ArbitrablePermissionList |
Oops, something went wrong.