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

[FEATURE] Enable instant return of txHash without waiting for mining. #50

Merged
merged 2 commits into from
Feb 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/API/scheduler.md
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ it in before instead.

See the example below.

### eac.Scheduler.blockSchedule(toAddress, callData, callGas, callValue, windowSize, windowStart, gasPrice, donation, payment, requiredDeposit)
### eac.Scheduler.blockSchedule(toAddress, callData, callGas, callValue, windowSize, windowStart, gasPrice, donation, payment, requiredDeposit, waitForMined = true)

- `toAddress` - an Ethereum address
- `callData` - hex encoded call data
@@ -52,6 +52,7 @@ See the example below.
- `donation` - `BigNumber` | String
- `payment` - `BigNumber` | String
- `requiredDeposit` - `BigNumber` | String
- `waitForMined` - Boolean

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

@@ -84,7 +85,7 @@ const receipt = await eacScheduler.blockSchedule(
)
```

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

- `toAddress` - an Ethereum address
- `callData` - hex encoded call data
@@ -96,5 +97,6 @@ const receipt = await eacScheduler.blockSchedule(
- `donation` - `BigNumber` | String
- `payment` - `BigNumber` | String
- `requiredDeposit` - `BigNumber` | String
- `waitForMined` - Boolean

Returns a `Promise` that will resolve to the `receipt` of the transaction if successful.
36 changes: 28 additions & 8 deletions src/scheduling/index.js
Original file line number Diff line number Diff line change
@@ -58,7 +58,8 @@ class Scheduler {
gasPrice,
fee,
bounty,
requiredDeposit
requiredDeposit,
waitForMined = true
) {
return new Promise((resolve, reject) => {
this.blockScheduler.schedule.sendTransaction(
@@ -82,9 +83,18 @@ class Scheduler {
(err, txHash) => {
if (err) reject(err)
else {
Util.waitForTransactionToBeMined(this.web3, txHash)
.then(receipt => resolve(receipt))
.catch(e => reject(e))
const miningPromise = Util.waitForTransactionToBeMined(this.web3, txHash);

if (waitForMined) {
miningPromise
.then(receipt => resolve(receipt))
.catch(e => reject(e))
} else {
resolve({
transactionHash: txHash,
miningPromise
});
}
}
}
)
@@ -101,7 +111,8 @@ class Scheduler {
gasPrice,
fee,
bounty,
requiredDeposit
requiredDeposit,
waitForMined = true
) {
return new Promise((resolve, reject) => {
this.timestampScheduler.schedule(
@@ -125,9 +136,18 @@ class Scheduler {
(err, txHash) => {
if (err) reject(err)
else {
Util.waitForTransactionToBeMined(this.web3, txHash)
.then(receipt => resolve(receipt))
.catch(e => reject(e))
const miningPromise = Util.waitForTransactionToBeMined(this.web3, txHash);

if (waitForMined) {
miningPromise
.then(receipt => resolve(receipt))
.catch(e => reject(e))
} else {
resolve({
transactionHash: txHash,
miningPromise
});
}
}
}
)