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

Commit

Permalink
feat(all): require params in wrappers. fix how StateFullContract wrap…
Browse files Browse the repository at this point in the history
…per loads
  • Loading branch information
satello committed Mar 30, 2018
1 parent af450e4 commit 1478e3e
Show file tree
Hide file tree
Showing 23 changed files with 513 additions and 515 deletions.
6 changes: 5 additions & 1 deletion src/abstractWrappers/AbstractWrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'lodash'

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

class AbstractWrapper {
/**
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/abstractWrappers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Arbitrator from './arbitrator'
import ArbitrableContracts from './arbitrableContracts'

export { Arbitrator, ArbitrableContracts }
3 changes: 3 additions & 0 deletions src/constants/error.js
Original file line number Diff line number Diff line change
@@ -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 =>
Expand Down
35 changes: 13 additions & 22 deletions src/contractWrappers/ContractWrapper.js
Original file line number Diff line number Diff line change
@@ -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)
}

/**
Expand Down Expand Up @@ -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
)
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/contractWrappers/PNK/PinakionPOC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions src/contractWrappers/RNG/BlockHashRNG/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _ from 'lodash'

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

/**
* Kleros API
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 1478e3e

Please sign in to comment.