Skip to content
Permalink
Browse files

feat: update doc strings

  • Loading branch information...
satello committed Apr 9, 2018
1 parent 4a89382 commit f5bacccfe5cbf96cd3ada4198a5a4fee900e7b4a
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -3,6 +3,11 @@ import _ from 'lodash'
import isRequired from '../utils/isRequired'
import delegateCalls from '../utils/delegateCalls'

/**
* Abstract Contract holds a contract implementation to make calls to the blockchain but
* also includes methods that interact with the off chain store. NOTE all methods that
* the underlying contract implementation expose can be called directly from an Abstract contract.
*/
class AbstractContract {
/**
* AbstractContract wraps an implementation instance to provide access to higher level
@@ -2,9 +2,13 @@ import contract from 'truffle-contract'
import _ from 'lodash'

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

/**
* ContractImplementation is a parent class for on chain contracts. It loads the contract from the
* blockchain and exposes the contract instance for use by the child.
*/
class ContractImplementation {
constructor(
web3Provider = isRequired('web3Provider'),
@@ -120,14 +124,21 @@ class ContractImplementation {
}
}

/**
* Create a new Promise to be used in loading the contract.
* @returns {Promise} - Resolves to contract instance.
*/
_newLoadingPromise = () =>
new Promise((resolve, reject) => {
this._contractLoadedResolver = resolve
this._contractLoadedRejecter = reject
})

// we have getters so that abstract classes can provide public access to implementations variables
getContractInstance = () => this.contractInstance
/**
* Get the contract address for the currently instantiated contract.
* @returns {string} - The address of the contract.
*/
getContractAddress = () => this.contractAddress
}

@@ -1,7 +1,10 @@
import AbstractContract from '../AbstractContract'

/**
* Arbitrable Contract API.
* 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
* arbitrable methods from the supplied contract implementation can be called from this
* object.
*/
class ArbitrableContract extends AbstractContract {
/**
@@ -81,9 +84,11 @@ class ArbitrableContract extends AbstractContract {
await this._StoreProvider.addEvidenceContract(
this._contractImplementation.contractAddress,
account,
name,
description,
url
{
name,
description,
url
}
)

return txHash
@@ -1,10 +1,13 @@
import _ from 'lodash'

import * as arbitratorConstants from '../../constants/arbitrator'
import * as arbitratorConstants from '../../../constants/arbitrator'
import AbstractContract from '../AbstractContract'

/**
* Arbitrator API.
* Arbitrator Abstract Contarct API. This wraps an arbitrator contract. It provides
* interaction with both the off chain store as well as the arbitrator instance. All
* arbitrator methods from the supplied contract implementation can be called from this
* object.
*/
class Arbitrator extends AbstractContract {
/**
@@ -1,17 +1,17 @@
import PinakionPOCArtifact from 'kleros/build/contracts/PinakionPOC' // FIXME: mock
import _ from 'lodash'

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

/**
* Kleros API
* Provides interaction with a PinakionPOC contract deployed on the blockchain.
*/
class PinakionPOC extends ContractImplementation {
/**
* Constructor Kleros.
* Constructor PinakionPOC.
* @param {object} web3Provider - web3 instance.
* @param {string} contractAddress - of the contract (optionnal).
*/
@@ -20,7 +20,7 @@ class PinakionPOC extends ContractImplementation {
}

/**
* Kleros deploy.
* Deploy a new instance of PinakionPOC.
* @param {string} account - account of user
* @param {object} web3Provider - web3 provider object
* @returns {object} - 'truffle-contract' Object | err The contract object or error deploy.
@@ -37,7 +37,7 @@ class PinakionPOC extends ContractImplementation {
}

/**
* change the kleros contract in the PNK contract.
* Change the kleros contract variable in instance of PinakionPOC.
* @param {string} klerosAddress - Address of Kleros POC contract.
* @param {string} account - Address of user.
* @returns {object} - The result transaction object.
@@ -60,7 +60,7 @@ class PinakionPOC extends ContractImplementation {
}

/**
* transfer ownership of the PNK contract to the kleros POC contract.
* Transfer ownership of the PNK contract to the kleros POC contract.
* @param {string} klerosAddress - Address of Kleros POC contract.
* @param {string} account - Address of user.
* @returns {object} - The result transaction object.
@@ -1,16 +1,16 @@
import BlockHashRNGArtifact from 'kleros-interaction/build/contracts/BlockHashRNG'
import _ from 'lodash'

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

/**
* Kleros API
* Provides interaction with an instance of BlockHashRNG.
*/
class BlockHashRNG extends ContractImplementation {
/**
* Constructor Kleros.
* Constructor BlockHashRNG.
* @param {object} web3Provider - instance
* @param {string} contractAddress - of the contract (optionnal)
*/
@@ -19,7 +19,7 @@ class BlockHashRNG extends ContractImplementation {
}

/**
* Kleros deploy.
* BlockHashRNG deploy.
* @param {string} account - users account
* @param {object} web3Provider - web3 provider object
* @returns {object} - truffle-contract Object | err The contract object or error deploy
@@ -1,3 +1,3 @@
import _BlockHashRNG from './BlockHashRNG'
import BlockHashRNG from './BlockHashRNG'

export const BlockHashRNG = _BlockHashRNG
export { BlockHashRNG }
@@ -1,14 +1,14 @@
import arbitrableTransactionArtifact from 'kleros-interaction/build/contracts/ArbitrableTransaction'
import _ from 'lodash'

import * as ethConstants from '../../../constants/eth'
import * as contractConstants from '../../../constants/contract'
import * as errorConstants from '../../../constants/error'
import * as ethConstants from '../../../../constants/eth'
import * as contractConstants from '../../../../constants/contract'
import * as errorConstants from '../../../../constants/error'
import ContractImplementation from '../../ContractImplementation'
import deployContractAsync from '../../../utils/deployContractAsync'

/**
* ArbitrableTransaction API
* Provides interaction with an Arbitrable Transaction contract deployed on the blockchain.
*/
class ArbitrableTransaction extends ContractImplementation {
/**
@@ -217,7 +217,6 @@ class ArbitrableTransaction extends ContractImplementation {

/**
* Get ruling options from dispute via event
* FIXME this can be an abstract method as it is in the standard
* @param {string} arbitratorAddress address of arbitrator contract
* @param {number} disputeId index of dispute
* @returns {object[]} an array of objects that specify the name and value of the resolution option
@@ -1,18 +1,18 @@
import klerosArtifact from 'kleros/build/contracts/KlerosPOC'
import _ from 'lodash'

import * as ethConstants from '../../../constants/eth'
import * as errorConstants from '../../../constants/error'
import * as arbitratorConstants from '../../../constants/arbitrator'
import * as ethConstants from '../../../../constants/eth'
import * as errorConstants from '../../../../constants/error'
import * as arbitratorConstants from '../../../../constants/arbitrator'
import ContractImplementation from '../../ContractImplementation'
import deployContractAsync from '../../../utils/deployContractAsync'

/**
* Kleros API
* Provides interaction with a KlerosPOC contract on the blockchain.
*/
class KlerosPOC extends ContractImplementation {
/**
* Constructor Kleros.
* Create new KlerosPOC Implementation.
* @param {object} web3Provider - web3 instance.
* @param {string} contractAddress - Address of the KlerosPOC contract.
*/
@@ -21,7 +21,7 @@ class KlerosPOC extends ContractImplementation {
}

/**
* STATIC: Deploy a kleros instance
* STATIC: Deploy a KlerosPOC contract on the blockchain.
* @param {string} rngAddress address of random number generator contract
* @param {string} pnkAddress address of pinakion contract
* @param {number[]} timesPerPeriod array of 5 ints indicating the time limit for each period of contract
@@ -52,7 +52,7 @@ class KlerosPOC extends ContractImplementation {
}

/**
* Use Arbitrator.buyPNK
* Purchase PNK.
* @param {string} amount - The number of pinakion to buy.
* @param {string} account - The address of the user.
* @returns {object} - The result transaction object.
@@ -113,7 +113,6 @@ class KlerosPOC extends ContractImplementation {

/**
* Activate Pinakion tokens to be eligible to be a juror.
* FIXME use estimateGas
* @param {string} amount - number of tokens to activate.
* @param {string} account - address of user.
* @returns {object} - PNK balance.
@@ -141,7 +140,7 @@ class KlerosPOC extends ContractImplementation {
}

/**
* Fetch the cost of arbitration
* Fetch the cost of arbitration.
* @param {bytes} contractExtraData - extra data from arbitrable contract.
* @returns {number} - The cost of arbitration.
*/
@@ -5,6 +5,13 @@ import * as contracts from './contracts'
import * as resources from './resources'
import EventListener from './utils/EventListener'

/**
* The Kleros Api provides access to the full suite of functionality. It will initialize
* contract instances for you when possible and creates an object that you can use to
* call all of the other api modules. If you are only going to be interacting with
* specific apis, or you don't want certain functionality such as the off chain store,
* you might find it easier to initialze a specific instance of the api you want.
*/
class Kleros {
web3Wrapper = {}

@@ -19,7 +26,7 @@ class Kleros {
* @param {string} ethereumProvider - The Web3.js Provider instance you would like the
* Kleros.js library to use for interacting with the
* Ethereum network.
* @param {string} storeUri - <optional> The storage provider uri used to
* @param {string} storeUri - The storage provider uri used to
* get metadata from the cloud for the UI. e.g. Kleros-Store,
* IPFS, Swarm etc.
* @param {string} arbitratorAddress - Address of the arbitrator contract we should
@@ -73,11 +80,18 @@ class Kleros {
)
}

setArbitrableContractAddress = contractAddress =>
/**
* Set a new arbitrable contract for Kleros instance of arbitrableContracts
* @param {string} contractAddress - Address of arbitrable contract
*/
setArbitrableContractAddress = contractAddress => {
this.arbitrableContracts.setContractInstance(contractAddress)
}

/**
* Entry point to set up all event listerners and to start the events watcher
* Bootstraps an EventListener and adds all Kleros handlers for event logs. Use
* this if you want to watch the chain for notifications, or are using the off chain
* store for metadata.
* @param {string} account Address of the user
* @param {function} callback The function to be called once a notification
*/
@@ -106,7 +120,14 @@ class Kleros {
}

/**
* set store provider in all high level wrappers
* Stop watching for events on the Arbitrator initialized in the Kleros Instance.
*/
stopWatchingForEvents = () => {
this.eventListener.stopWatchingForEvents(this.arbitrator)
}

/**
* Sets the store provider uri for all higher level apis in the Kleros Instance.
* @param {string} storeUri - The URI that the store provider will use
*/
setStoreProvider = storeUri => {

0 comments on commit f5baccc

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