Skip to content
This repository has been archived by the owner on Aug 22, 2018. It is now read-only.

Commit

Permalink
Merge pull request #33 from ethereum-alarm-clock/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lsaether committed Jan 30, 2018
2 parents 3f1a378 + cef653b commit 77a3f74
Show file tree
Hide file tree
Showing 10 changed files with 646 additions and 449 deletions.
56 changes: 56 additions & 0 deletions docs/API/requestFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,60 @@ contracts.
if (!await requestFactory.isKnownRequest(nextRequestAddress)) {
throw new Error(`Encountered unknown address! Please check that you are using the correct contracts JSON file.`)
}
```

### eac.RequestFactory.validateRequestParams(addressArgs, uintArgs, callData, endowment)

Lowest level validation function and takes the full request params

* addressArgs [0] - meta.owner
* addressArgs [1] - paymentData.donationBenefactor
* addressArgs [2] - txnData.toAddress
* uintArgs [0] - paymentData.donation
* uintArgs [1] - paymentData.payment
* uintArgs [2] - schedule.claimWindowSize
* uintArgs [3] - schedule.freezePeriod
* uintArgs [4] - schedule.reservedWindowSize
* uintArgs [5] - schedule.temporalUnit
* uintArgs [6] - schedule.windowSize
* uintArgs [7] - schedule.windowStart
* uintArgs [8] - txnData.callGas
* uintArgs [9] - txnData.callValue
* uintArgs [10] - txnData.gasPrice
* uintArgs [11] - claimData.requiredDeposit
* callData - The call data
* endowment - The value sent with the creation request.

where `addressArgs` is an array of length 3 containing valid Ethereum addresses, `uintArgs`
is an array of length 12 containing unsigned integers, the `callData` is hex
encoded and the `endowment` is a wei value. Returns an `Array<boolean>` of length 6,
the booleans will be true if validation passed and false if an error was triggered.
Use `eac.RequestFactroy.parseIsValid()` to parse error messages from this array.

### eac.RequestFactory.parseIsValid(isValid)

Takes an `Array<boolean>` of length six containing the results of `.validateRequestParams()`
and returns an `Array<string>` containig the parsed error messages.

Error messages include:
* InsufficientEndowment
* ReservedWindowBiggerThanExecutionWindow
* InvalidTemporalUnit
* ExecutionWindowTooSoon
* CallGasTooHigh
* EmptyToAddress

```javascript
// Defines the variables addressArgs, uintArgs, callData and endowment earlier in the file
const isValid = await requestFactory.validateRequestParams(
addressArgs,
uintArgs,
callData,
endowment
)

if (isValid.indexOf(false) != -1) {
const errorMsgs = requestFactory.parseIsValid(isValid)
throw new Error(errorMsgs)
}
```
29 changes: 29 additions & 0 deletions docs/API/scheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ Takes in `BigNumber` arguments for `callGas`, `callValue`, `gasPrice`, `donation

Returns a `Promise` that will resolve to the `receipt` of the transaction if successful.

```javascript
const endowment = eacScheduler.calcEndowment(
new BigNumber(callGas),
new BigNumber(callValue),
new BigNumber(gasPrice),
new BigNumber(donation),
new BigNumber(payment)
)

eacScheduler.initSender({
from: web3.eth.defaultAccount,
gas: 3000000,
value: endowment
})

eacScheduler.blockSchedule(
toAddress,
web3.fromAscii(callData),
callGas,
callValue,
windowSize,
windowStart,
gasPrice,
donation,
payment,
requiredDeposit
)
```

### eac.Scheduler.timestampSchedule(toAddress, callData, callGas, callValue, windowSize, windowStart, gasPrice, donation, payment, requiredDeposit)

- `toAddress` - an Ethereum address
Expand Down
13 changes: 0 additions & 13 deletions example/webpack/src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ class App extends React.Component {
gas: 3000000,
value: endowment
})

// console.log(
// toAddress,
// web3.fromAscii(callData),
// callGas,
// callValue,
// windowSize,
// windowStart,
// gasPrice,
// donation,
// payment,
// requiredDeposit)

eacScheduler.blockSchedule(
toAddress,
web3.fromAscii(callData),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eac.js",
"version": "1.0.4",
"version": "1.0.5",
"description": "Commnandline tool to interact with the Ethereum Alarm Clock contracts.",
"main": "./src/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/eac.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const log = {
}

program
.version("1.0.4")
.version("1.0.5")
// Client options
.option("-c, --client", "starts the executing client")
.option(
Expand Down
44 changes: 44 additions & 0 deletions src/requestFactory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,50 @@ class RequestFactory {
})
}


validateRequestParams(addressArgs, uintArgs, callData, endowment) {
return new Promise((resolve, reject) => {
this.instance.validateRequestParams.call(
addressArgs,
uintArgs,
callData,
endowment,
(err, isValid) => {
if (!err) resolve(isValid)
else reject(err)
}
)
})
}

/**
* Parses the boolean returned by validateRequestParams() and returns the reason validation failed.
* @param {Array<boolean>} isValid The array returned by this.validateRequestParams()
* @return {Array<String>} An array of the strings of validation errors or an array of length 0 if no errors.
*/
parseIsValid(isValid) {
if (isValid.length != 6) {
throw new Error(
"Must pass an array of booleans returned by validateRequestParams()"
)
}
const Errors = [
"InsufficientEndowment",
"ReservedWindowBiggerThanExecutionWindow",
"InvalidTemporalUnit",
"ExecutionWindowTooSoon",
"CallGasTooHigh",
"EmptyToAddress",
]
let errors = new Array()
isValid.forEach((boolIsTrue, index) => {
if (!boolIsTrue) {
errors.push(Errors[index])
}
})
return errors
}

/**
* Chain inits
*/
Expand Down
Loading

0 comments on commit 77a3f74

Please sign in to comment.