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

Commit

Permalink
feat: create meta-evidence with contract
Browse files Browse the repository at this point in the history
  • Loading branch information
satello committed Jul 25, 2018
1 parent baef7f2 commit fef04aa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"dependencies": {
"babel-runtime": "^6.26.0",
"eth-sig-util": "^1.4.2",
"ethereumjs-util": "^5.2.0",
"kleros": "^0.0.6",
"kleros-interaction": "^0.0.17",
"lodash": "^4.17.4",
Expand Down
17 changes: 15 additions & 2 deletions src/contracts/abstractions/Arbitrable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import AbstractContract from '../AbstractContract'

import getContractAddress from '../../utils/getContractAddress'

/**
* Arbitrable Abstract Contarct API. This wraps an arbitrable contract. It provides
* interaction with both the off chain store as well as the arbitrable instance. All
Expand Down Expand Up @@ -33,8 +35,14 @@ class ArbitrableContract extends AbstractContract {
email = '',
title = '',
description = '',
metaEvidence = {}
...args
) => {
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 contractInstance = await this._contractImplementation.constructor.deploy(
account,
value,
Expand All @@ -43,10 +51,14 @@ class ArbitrableContract extends AbstractContract {
timeout,
partyB,
arbitratorExtraData,
this._contractImplementation.getWeb3Provider(),
metaEvidenceUri,
web3Provider,
...args
)

if (contractInstance.address !== contractAddress)
raise new Error('Contract address does not match meta-evidence uri')

const newContract = await this._StoreProvider.updateContract(
account,
contractInstance.address,
Expand All @@ -58,7 +70,8 @@ class ArbitrableContract extends AbstractContract {
timeout,
email,
title,
description
description,
metaEvidence
}
)

Expand Down
5 changes: 5 additions & 0 deletions src/utils/StoreProviderWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class StoreProviderWrapper {
queueReadRequest = uri =>
this._storeQueue.fetch(() => this._makeRequest('GET', uri))


getMetaEvidenceUri = address => (
`${this._storeUri}/${userAddress}/contracts/${address}/meta-evidence`
)

// **************************** //
// * Read * //
// **************************** //
Expand Down
2 changes: 2 additions & 0 deletions src/utils/Web3Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Web3Wrapper {

getCoinbase = () => this._web3.eth.coinbase

getNonce = address => this._web3.eth.getTransactionCount(address)

toWei = (amount, unit) => {
const newAmount = this._web3.toWei(amount, unit)
return newAmount.toNumber ? newAmount.toNumber() : Number(newAmount)
Expand Down
6 changes: 6 additions & 0 deletions src/utils/getContractAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ethUtil from 'ethereumjs-util'

const getContractAddress (account, Web3Wrapper) => {
const currentNonce = Web3Wrapper.getNonce(account)
return ethUtil.bufferToHex(ethUtil.generateAddress(account, currentNonce))
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3418,7 +3418,7 @@ eth-sig-util@^1.4.2:
bn.js "^4.10.0"
ethereumjs-util "^5.0.0"

ethereumjs-util@^5.0.0, ethereumjs-util@^5.1.1:
ethereumjs-util@^5.0.0, ethereumjs-util@^5.1.1, ethereumjs-util@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz#3e0c0d1741471acf1036052d048623dee54ad642"
dependencies:
Expand Down

0 comments on commit fef04aa

Please sign in to comment.