Skip to content

Commit

Permalink
Merge c4176a2 into 21c3f4a
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaether committed Oct 10, 2018
2 parents 21c3f4a + c4176a2 commit 24dfe13
Show file tree
Hide file tree
Showing 18 changed files with 450 additions and 198 deletions.
93 changes: 43 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 14 additions & 17 deletions src/Actions/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BigNumber from 'bignumber.js';

import Cache, { ICachedTxDetails } from '../Cache';
import { IEconomicStrategyManager } from '../EconomicStrategy/EconomicStrategyManager';
import { ClaimStatus, ExecuteStatus } from '../Enum';
import { TxSendErrors } from '../Enum/TxSendErrors';
import { ILogger } from '../Logger';
Expand All @@ -15,8 +14,8 @@ import { Pending } from './Pending';
import { Operation } from '../Types/Operation';

export default interface IActions {
claim(txRequest: ITxRequest, nextAccount: Address): Promise<ClaimStatus>;
execute(txRequest: ITxRequest): Promise<ExecuteStatus>;
claim(txRequest: ITxRequest, nextAccount: Address, gasPrice: BigNumber): Promise<ClaimStatus>;
execute(txRequest: ITxRequest, gasPrice: BigNumber): Promise<ExecuteStatus>;
}

export default class Actions implements IActions {
Expand All @@ -26,27 +25,28 @@ export default class Actions implements IActions {
private cache: Cache<ICachedTxDetails>;
private utils: W3Util;
private pending: Pending;
private economicStrategyManager: IEconomicStrategyManager;

constructor(
wallet: Wallet,
ledger: ILedger,
logger: ILogger,
cache: Cache<ICachedTxDetails>,
utils: W3Util,
pending: Pending,
economicStrategyManager: IEconomicStrategyManager
pending: Pending
) {
this.wallet = wallet;
this.logger = logger;
this.ledger = ledger;
this.cache = cache;
this.utils = utils;
this.pending = pending;
this.economicStrategyManager = economicStrategyManager;
}

public async claim(txRequest: ITxRequest, nextAccount: Address): Promise<ClaimStatus> {
public async claim(
txRequest: ITxRequest,
nextAccount: Address,
gasPrice: BigNumber
): Promise<ClaimStatus> {
//TODO: merge wallet ifs into 1 getWalletStatus or something
if (this.wallet.hasPendingTransaction(txRequest.address, Operation.CLAIM)) {
return ClaimStatus.IN_PROGRESS;
Expand All @@ -59,7 +59,7 @@ export default class Actions implements IActions {
}

try {
const opts = await this.getClaimingOpts(txRequest);
const opts = this.getClaimingOpts(txRequest, gasPrice);
const { receipt, from, status } = await this.wallet.sendFromAccount(nextAccount, opts);

this.ledger.accountClaiming(receipt, txRequest, opts, from);
Expand All @@ -82,7 +82,7 @@ export default class Actions implements IActions {
return ClaimStatus.FAILED;
}

public async execute(txRequest: ITxRequest): Promise<ExecuteStatus> {
public async execute(txRequest: ITxRequest, gasPrice: BigNumber): Promise<ExecuteStatus> {
if (this.wallet.hasPendingTransaction(txRequest.address, Operation.EXECUTE)) {
return ExecuteStatus.IN_PROGRESS;
}
Expand All @@ -91,7 +91,7 @@ export default class Actions implements IActions {
}

try {
const opts = await this.getExecutionOpts(txRequest);
const opts = this.getExecutionOpts(txRequest, gasPrice);
const claimIndex = this.wallet.getAddresses().indexOf(txRequest.claimedBy);
const wasClaimedByOurNode = claimIndex > -1;
let executionResult: IWalletReceipt;
Expand Down Expand Up @@ -154,22 +154,19 @@ export default class Actions implements IActions {
});
}

private async getClaimingOpts(txRequest: ITxRequest): Promise<ITransactionOptions> {
private getClaimingOpts(txRequest: ITxRequest, gasPrice: BigNumber): ITransactionOptions {
return {
to: txRequest.address,
value: txRequest.requiredDeposit,
gas: 120000,
// NOTE - as for why we use `getGasPrice` instead of `networkGasPrice` see
// note at `src/EconomicStrategy/EconomicStrategyManager.ts` line 221.
gasPrice: await this.utils.getGasPrice(),
gasPrice,
data: txRequest.claimData,
operation: Operation.CLAIM
};
}

private async getExecutionOpts(txRequest: ITxRequest): Promise<ITransactionOptions> {
private getExecutionOpts(txRequest: ITxRequest, gasPrice: BigNumber): ITransactionOptions {
const gas = this.utils.calculateGasAmount(txRequest);
const gasPrice = await this.economicStrategyManager.getExecutionGasPrice(txRequest);

return {
to: txRequest.address,
Expand Down

0 comments on commit 24dfe13

Please sign in to comment.