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

Commit

Permalink
feat: submit evidence uri use evidenceIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
satello committed Jul 25, 2018
1 parent c3f410f commit 12040dd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
24 changes: 16 additions & 8 deletions src/contracts/abstractions/Arbitrable.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ArbitrableContract extends AbstractContract {
const web3Provider = this._contractImplementation.getWeb3Provider()
// determine the contract address WARNING if the nonce changes this will produce a different address
const contractAddress = getContractAddress(account, web3Provider)
const metaEvidenceUri = this._StoreProvider.getMetaEvidenceUri(contractAddress)
const metaEvidenceUri = this._StoreProvider.getMetaEvidenceUri(account, contractAddress)

const contractInstance = await this._contractImplementation.constructor.deploy(
account,
Expand Down Expand Up @@ -79,29 +79,37 @@ class ArbitrableContract extends AbstractContract {
}

/**
* Submit evidence.
* Submit evidence. FIXME should we determine the hash for the user?
* @param {string} account - ETH address of user.
* @param {string} name - Name of evidence.
* @param {string} description - Description of evidence.
* @param {string} url - A link to an evidence using its URI.
* @param {string} hash - A hash of the evidence at the URI. No hash if content is dynamic
* @returns {string} - txHash Hash transaction.
*/
submitEvidence = async (account, name, description = '', url) => {
const txHash = await this._contractImplementation.submitEvidence(
submitEvidence = async (account, name, description, url, hash) => {
const contractAddress = this._contractImplementation.contractAddress
// get the index of the new evidence
const evidenceIndex = await this._StoreProvider.addEvidenceContract(
contractAddress,
account,
name,
description,
url
url,
hash
)
// construct the unique URI
const evidenceUri = this._StoreProvider.getEvidenceUri(account, contractAddress, evidenceIndex)

await this._StoreProvider.addEvidenceContract(
this._contractImplementation.contractAddress,
const txHash = await this._contractImplementation.submitEvidence(
account,
name,
description,
url
evidenceUri
)



return txHash
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class ArbitrableTransaction extends ContractImplementation {
{ _disputeID: disputeId, _arbitrator: arbitratorAddress }
)

// TODO verify hash and data are valid if hash exists
return evidenceLogs.map(async evidenceLog => {
const evidenceURI = evidenceLog.args._evidence
const evidence = await httpRequest(
Expand Down
27 changes: 17 additions & 10 deletions src/utils/StoreProviderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ class StoreProviderWrapper {
this._storeQueue.fetch(() => httpRequest('GET', uri))


getMetaEvidenceUri = address => (
`${this._storeUri}/${userAddress}/contracts/${address}/meta-evidence`
getMetaEvidenceUri = userAddress, contractAddress => (
`${this._storeUri}/${userAddress}/contracts/${contractAddress}/meta-evidence`
)
getEvidenceUri = (address, contractAddress, evidenceIndex) => (
`${this._storeUri}/${userAddress}/contracts/${contractAddress}/evidence/evidenceIndex`
)
// **************************** //
Expand Down Expand Up @@ -239,35 +243,38 @@ class StoreProviderWrapper {
* @param {string} name - Name of evidence.
* @param {string} description - Description of evidence.
* @param {string} url - A link to the evidence.
* @returns {Promise} - The resulting evidence data.
* @returns {number} - The index of the evidence
*/
addEvidenceContract = (
contractAddress,
userAddress,
name,
description,
url
url,
hash
) => {
// get timestamp for submission
const submittedAt = new Date().getTime()

const getBodyFn = () =>
new Promise(resolve =>
resolve(
JSON.stringify({
name,
description,
url,
submittedAt
URI: url,
hash
})
)
)
return this.queueWriteRequest(
const response = await this.queueWriteRequest(
getBodyFn,
'POST',
`${this._storeUri}/${userAddress}/contracts/${contractAddress}/evidence`
)
if (response.status !== 200)
throw new Error(errorConstants.REQUEST_FAILED('Unable to submit evidence')
return response.body.evidenceIndex
}
/**
Expand Down

0 comments on commit 12040dd

Please sign in to comment.