Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async increaseTimeAsync(timeDelta: number): Promise {
assert.isNumber('timeDelta', timeDelta);
// Detect Geth vs. Ganache and use appropriate endpoint.
const version = await this.getNodeVersionAsync();
if (_.includes(version, uniqueVersionIds.geth)) {
return this.sendRawPayloadAsync({ method: 'debug_increaseTime', params: [timeDelta] });
} else if (_.includes(version, uniqueVersionIds.ganache)) {
return this.sendRawPayloadAsync({ method: 'evm_increaseTime', params: [timeDelta] });
} else {
throw new Error(`Unknown client version: ${version}`);
}
}
/**
public async awaitTransactionMinedAsync(
txHash: string,
pollingIntervalMs: number = 1000,
timeoutMs?: number,
): Promise {
assert.isHexString('txHash', txHash);
assert.isNumber('pollingIntervalMs', pollingIntervalMs);
if (timeoutMs !== undefined) {
assert.isNumber('timeoutMs', timeoutMs);
}
// Immediately check if the transaction has already been mined.
let transactionReceipt = await this.getTransactionReceiptIfExistsAsync(txHash);
if (transactionReceipt !== undefined) {
const logsWithDecodedArgs = _.map(
transactionReceipt.logs,
this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder),
);
const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = {
...transactionReceipt,
logs: logsWithDecodedArgs,
};
return transactionReceiptWithDecodedLogArgs;
}
// Otherwise, check again every pollingIntervalMs.
public async awaitTransactionMinedAsync(
txHash: string,
pollingIntervalMs: number = 1000,
timeoutMs?: number,
): Promise {
assert.isHexString('txHash', txHash);
assert.isNumber('pollingIntervalMs', pollingIntervalMs);
if (timeoutMs !== undefined) {
assert.isNumber('timeoutMs', timeoutMs);
}
// Immediately check if the transaction has already been mined.
let transactionReceipt = await this.getTransactionReceiptIfExistsAsync(txHash);
if (transactionReceipt !== undefined) {
const logsWithDecodedArgs = _.map(
transactionReceipt.logs,
this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder),
);
const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = {
...transactionReceipt,
logs: logsWithDecodedArgs,
};
return transactionReceiptWithDecodedLogArgs;
}
constructor(opts: SRAPollingOrderProviderOpts, orderStore: OrderStore) {
super(orderStore, opts.httpEndpoint, opts.perPage);
assert.isNumber('pollingIntervalMs', opts.pollingIntervalMs);
this._pollingIntervalMs = opts.pollingIntervalMs;
}
public static toUnitAmount(amount: BigNumber, decimals: number): BigNumber {
assert.isValidBaseUnitAmount('amount', amount);
assert.isNumber('decimals', decimals);
const aUnit = new BigNumber(BASE_TEN).pow(decimals);
const unit = amount.div(aUnit);
return unit;
}
/**
constructor(config: MnemonicWalletSubproviderConfigs) {
assert.isString('mnemonic', config.mnemonic);
const baseDerivationPath = config.baseDerivationPath || DEFAULT_BASE_DERIVATION_PATH;
assert.isString('baseDerivationPath', baseDerivationPath);
const addressSearchLimit = config.addressSearchLimit || DEFAULT_ADDRESS_SEARCH_LIMIT;
assert.isNumber('addressSearchLimit', addressSearchLimit);
super();
this._mnemonic = config.mnemonic;
this._baseDerivationPath = baseDerivationPath;
this._addressSearchLimit = addressSearchLimit;
this._derivedKeyInfo = this._initialDerivedKeyInfo(this._baseDerivationPath);
}
/**
public async revertSnapshotAsync(snapshotId: number): Promise {
assert.isNumber('snapshotId', snapshotId);
const didRevert = await this.sendRawPayloadAsync({ method: 'evm_revert', params: [snapshotId] });
return didRevert;
}
/**
public static toBaseUnitAmount(amount: BigNumber | number, decimals: number): BigNumber {
assert.isNumber('decimals', decimals);
const unit = new BigNumber(BASE_TEN).pow(decimals);
const baseUnitAmount = unit.times(amount);
const hasDecimals = baseUnitAmount.decimalPlaces() !== 0;
if (hasDecimals) {
throw new Error(`Invalid unit amount: ${amount.toString(BASE_TEN)} - Too many decimal places`);
}
return baseUnitAmount;
}
/**
public async setHeadAsync(blockNumber: number): Promise {
assert.isNumber('blockNumber', blockNumber);
await this.sendRawPayloadAsync({ method: 'debug_setHead', params: [utils.numberToHex(blockNumber)] });
}
/**