Skip to content
Permalink
Browse files

feat: create meta-evidence with contract

  • Loading branch information...
satello committed Jul 12, 2018
1 parent baef7f2 commit fef04aa54936d891175fd91e1252c4f48f9e7ce8
@@ -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",
@@ -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
@@ -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,
@@ -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,
@@ -58,7 +70,8 @@ class ArbitrableContract extends AbstractContract {
timeout,
email,
title,
description
description,
metaEvidence
}
)

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

0 comments on commit fef04aa

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