Skip to content
Permalink
Browse files

feat(all): require params in wrappers. fix how StateFullContract wrap…

…per loads
  • Loading branch information...
satello committed Mar 30, 2018
1 parent af450e4 commit 1478e3ec971717c0a5b35c1e10936f8c812b8a62
@@ -1,6 +1,7 @@
import _ from 'lodash'

import * as errorConstants from '../constants/error'
import isRequired from '../utils/isRequired'

class AbstractWrapper {
/**
@@ -10,7 +11,10 @@ class AbstractWrapper {
* @param {object} contractWrapperInstance - Contract Wrapper object to extend
* @param {object} storeProviderWrapperInstance - StoreProvider wrapper object.
*/
constructor(contractWrapperInstance, storeProviderWrapperInstance) {
constructor(
contractWrapperInstance = isRequired('contractWrapperInstance'),
storeProviderWrapperInstance = isRequired('storeProviderWrapperInstance')
) {
this._StoreProvider = storeProviderWrapperInstance
// Should still use this._contractWrapper... over this... even after calls are delegating in case any calls were overwritten by child
this._contractWrapper = contractWrapperInstance
@@ -0,0 +1,4 @@
import Arbitrator from './arbitrator'
import ArbitrableContracts from './arbitrableContracts'

export { Arbitrator, ArbitrableContracts }
@@ -1,3 +1,6 @@
// Kleros
export const MISSING_PARAMETERS = name => `Missing required parameter: ${name}`

// StoreProviderWrapper
export const PROFILE_NOT_FOUND = user => `No profile found for user: ${user}.`
export const NOTIFICATION_NOT_FOUND = txHash =>
@@ -1,19 +1,21 @@
import contract from 'truffle-contract'
import _ from 'lodash'

import * as ethConstants from '../constants/eth'
import * as errorConstants from '../constants/error'
import isRequired from '../utils/isRequired'
import deployContractAsync from '../utils/deployContractAsync'
import Web3Wrapper from '../utils/Web3Wrapper'

/**
* Contract wrapper
*/
class ContractWrapper {
/**
* Constructor contract wrapper
* @param {object} web3Wrapper instance
* @param {object} web3Provider web3 provider object
*/
constructor(web3Wrapper) {
this._Web3Wrapper = web3Wrapper
constructor(web3Provider = isRequired('web3Provider')) {
this._Web3Wrapper = new Web3Wrapper(web3Provider)
}

/**
@@ -73,24 +75,13 @@ class ContractWrapper {
_deployAsync = async (account, value, artifact, ...args) => {
if (_.isEmpty(account)) account = this._Web3Wrapper.getAccount(0)

try {
const MyContract = contract({
abi: artifact.abi,
unlinked_binary: artifact.bytecode
? artifact.bytecode
: artifact.unlinked_binary
})
MyContract.setProvider(await this._Web3Wrapper.getProvider())

return MyContract.new(...args, {
from: account,
value: value,
gas: ethConstants.TRANSACTION.GAS
})
} catch (err) {
console.error(err)
throw new Error(errorConstants.UNABLE_TO_DEPLOY_CONTRACT)
}
return deployContractAsync(
account,
value,
artifact,
this._Web3Wrapper.getProvider(),
...args
)
}

/**
@@ -4,6 +4,7 @@ import _ from 'lodash'
import * as ethConstants from '../../../constants/eth'
import * as errorConstants from '../../../constants/error'
import ContractWrapper from '../../ContractWrapper'
import deployContractAsync from '../../../utils/deployContractAsync'

/**
* Kleros API
@@ -24,18 +25,18 @@ class PinakionWrapper extends ContractWrapper {

/**
* Kleros deploy.
* @param {string} account - (default: accounts[0]).
* @param {string} account - account of user
* @param {object} web3Provider - web3 provider object
* @returns {object} - 'truffle-contract' Object | err The contract object or error deploy.
*/
deploy = async (account = this._Web3Wrapper.getAccount(0)) => {
const contractDeployed = await this._deployAsync(
static deploy = async (account, web3Provider) => {
const contractDeployed = await deployContractAsync(
account,
ethConstants.TRANSACTION.value,
PinakionPOC
ethConstants.TRANSACTION.VALUE,
PinakionPOC,
web3Provider
)

this.address = contractDeployed.address

return contractDeployed
}

@@ -3,6 +3,7 @@ import _ from 'lodash'

import * as ethConstants from '../../../constants/eth'
import ContractWrapper from '../../ContractWrapper'
import deployContractAsync from '../../../utils/deployContractAsync'

/**
* Kleros API
@@ -23,19 +24,18 @@ class BlockHashRNGWrapper extends ContractWrapper {

/**
* Kleros deploy.
* @param {string} account - (default: accounts[0])
* @param {number} value - (default: 10000)
* @param {string} account - users account
* @param {object} web3Provider - web3 provider object
* @returns {object} - truffle-contract Object | err The contract object or error deploy
*/
deploy = async (account = this._Web3Wrapper.getAccount(0)) => {
const contractDeployed = await this._deployAsync(
static deploy = async (account, web3Provider) => {
const contractDeployed = await deployContractAsync(
account,
ethConstants.TRANSACTION.VALUE,
RNG
RNG,
web3Provider
)

this.address = contractDeployed.address

return contractDeployed
}

@@ -5,6 +5,7 @@ import * as ethConstants from '../../../constants/eth'
import * as contractConstants from '../../../constants/contract'
import * as errorConstants from '../../../constants/error'
import ContractWrapper from '../../ContractWrapper'
import deployContractAsync from '../../../utils/deployContractAsync'

/**
* ArbitrableTransaction API
@@ -32,31 +33,31 @@ class ArbitrableTransactionWrapper extends ContractWrapper {
* @param {number} timeout Time after which a party automatically loose a dispute. (default 3600)
* @param {string} partyB The recipient of the transaction. (default account[1])
* @param {bytes} arbitratorExtraData Extra data for the arbitrator. (default empty string)
* @param {object} web3Provider web3 provider object
* @returns {object} truffle-contract Object | err The deployed contract or an error
*/
deploy = async (
static deploy = async (
account,
value = ethConstants.TRANSACTION.VALUE,
hashContract,
arbitratorAddress,
timeout,
partyB,
arbitratorExtraData = ''
arbitratorExtraData = '',
web3Provider
) => {
const contractDeployed = await this._deployAsync(
const contractDeployed = await deployContractAsync(
account,
value,
arbitrableTransaction,
web3Provider,
arbitratorAddress,
hashContract,
timeout,
partyB,
arbitratorExtraData
)

this.address = contractDeployed.address
this.contractInstance = contractDeployed

return contractDeployed
}

Oops, something went wrong.

0 comments on commit 1478e3e

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