Skip to content
Permalink
Browse files

feat: submit evidence uri use evidenceIndex

  • Loading branch information...
satello committed Jul 13, 2018
1 parent c3f410f commit 12040dd59f9b0f5eb53411dced47339b1c6f0f7d
@@ -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,
@@ -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
}

@@ -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(
@@ -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`
)

// **************************** //
@@ -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
}

/**

0 comments on commit 12040dd

Please sign in to comment.
You can’t perform that action at this time.