Add new underscore-privates rule to @0xproject/tslint-config and fix lint errors
This commit is contained in:
committed by
Leonid Logvinov
parent
972e1675f6
commit
cb11aec84d
@@ -7,16 +7,16 @@ import {BalancesByOwner, ContractInstance} from './types';
|
||||
bigNumberConfigs.configure();
|
||||
|
||||
export class Balances {
|
||||
private tokenContractInstances: ContractInstance[];
|
||||
private ownerAddresses: string[];
|
||||
private _tokenContractInstances: ContractInstance[];
|
||||
private _ownerAddresses: string[];
|
||||
constructor(tokenContractInstances: ContractInstance[], ownerAddresses: string[]) {
|
||||
this.tokenContractInstances = tokenContractInstances;
|
||||
this.ownerAddresses = ownerAddresses;
|
||||
this._tokenContractInstances = tokenContractInstances;
|
||||
this._ownerAddresses = ownerAddresses;
|
||||
}
|
||||
public async getAsync(): Promise<BalancesByOwner> {
|
||||
const balancesByOwner: BalancesByOwner = {};
|
||||
for (const tokenContractInstance of this.tokenContractInstances) {
|
||||
for (const ownerAddress of this.ownerAddresses) {
|
||||
for (const tokenContractInstance of this._tokenContractInstances) {
|
||||
for (const ownerAddress of this._ownerAddresses) {
|
||||
let balance = await tokenContractInstance.balanceOf(ownerAddress);
|
||||
balance = new BigNumber(balance);
|
||||
if (_.isUndefined(balancesByOwner[ownerAddress])) {
|
||||
|
||||
@@ -6,9 +6,9 @@ import {Order} from './order';
|
||||
import {ContractInstance} from './types';
|
||||
|
||||
export class ExchangeWrapper {
|
||||
private exchange: ContractInstance;
|
||||
private _exchange: ContractInstance;
|
||||
constructor(exchangeContractInstance: ContractInstance) {
|
||||
this.exchange = exchangeContractInstance;
|
||||
this._exchange = exchangeContractInstance;
|
||||
}
|
||||
public async fillOrderAsync(order: Order, from: string,
|
||||
opts: {
|
||||
@@ -17,7 +17,7 @@ export class ExchangeWrapper {
|
||||
} = {}) {
|
||||
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
|
||||
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
|
||||
const tx = await this.exchange.fillOrder(
|
||||
const tx = await this._exchange.fillOrder(
|
||||
params.orderAddresses,
|
||||
params.orderValues,
|
||||
params.fillTakerTokenAmount,
|
||||
@@ -33,7 +33,7 @@ export class ExchangeWrapper {
|
||||
public async cancelOrderAsync(order: Order, from: string,
|
||||
opts: {cancelTakerTokenAmount?: BigNumber} = {}) {
|
||||
const params = order.createCancel(opts.cancelTakerTokenAmount);
|
||||
const tx = await this.exchange.cancelOrder(
|
||||
const tx = await this._exchange.cancelOrder(
|
||||
params.orderAddresses,
|
||||
params.orderValues,
|
||||
params.cancelTakerTokenAmount,
|
||||
@@ -46,7 +46,7 @@ export class ExchangeWrapper {
|
||||
opts: {fillTakerTokenAmount?: BigNumber} = {}) {
|
||||
const shouldThrowOnInsufficientBalanceOrAllowance = true;
|
||||
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmount);
|
||||
const tx = await this.exchange.fillOrKillOrder(
|
||||
const tx = await this._exchange.fillOrKillOrder(
|
||||
params.orderAddresses,
|
||||
params.orderValues,
|
||||
params.fillTakerTokenAmount,
|
||||
@@ -66,7 +66,7 @@ export class ExchangeWrapper {
|
||||
const shouldThrowOnInsufficientBalanceOrAllowance = !!opts.shouldThrowOnInsufficientBalanceOrAllowance;
|
||||
const params = formatters.createBatchFill(
|
||||
orders, shouldThrowOnInsufficientBalanceOrAllowance, opts.fillTakerTokenAmounts);
|
||||
const tx = await this.exchange.batchFillOrders(
|
||||
const tx = await this._exchange.batchFillOrders(
|
||||
params.orderAddresses,
|
||||
params.orderValues,
|
||||
params.fillTakerTokenAmounts,
|
||||
@@ -82,7 +82,7 @@ export class ExchangeWrapper {
|
||||
public async batchFillOrKillOrdersAsync(orders: Order[], from: string,
|
||||
opts: {fillTakerTokenAmounts?: BigNumber[]} = {}) {
|
||||
const params = formatters.createBatchFill(orders, undefined, opts.fillTakerTokenAmounts);
|
||||
const tx = await this.exchange.batchFillOrKillOrders(
|
||||
const tx = await this._exchange.batchFillOrKillOrders(
|
||||
params.orderAddresses,
|
||||
params.orderValues,
|
||||
params.fillTakerTokenAmounts,
|
||||
@@ -103,7 +103,7 @@ export class ExchangeWrapper {
|
||||
const params = formatters.createFillUpTo(orders,
|
||||
shouldThrowOnInsufficientBalanceOrAllowance,
|
||||
opts.fillTakerTokenAmount);
|
||||
const tx = await this.exchange.fillOrdersUpTo(
|
||||
const tx = await this._exchange.fillOrdersUpTo(
|
||||
params.orderAddresses,
|
||||
params.orderValues,
|
||||
params.fillTakerTokenAmount,
|
||||
@@ -119,7 +119,7 @@ export class ExchangeWrapper {
|
||||
public async batchCancelOrdersAsync(orders: Order[], from: string,
|
||||
opts: {cancelTakerTokenAmounts?: BigNumber[]} = {}) {
|
||||
const params = formatters.createBatchCancel(orders, opts.cancelTakerTokenAmounts);
|
||||
const tx = await this.exchange.batchCancelOrders(
|
||||
const tx = await this._exchange.batchCancelOrders(
|
||||
params.orderAddresses,
|
||||
params.orderValues,
|
||||
params.cancelTakerTokenAmounts,
|
||||
@@ -131,11 +131,11 @@ export class ExchangeWrapper {
|
||||
public async getOrderHashAsync(order: Order): Promise<string> {
|
||||
const shouldThrowOnInsufficientBalanceOrAllowance = false;
|
||||
const params = order.createFill(shouldThrowOnInsufficientBalanceOrAllowance);
|
||||
const orderHash = await this.exchange.getOrderHash(params.orderAddresses, params.orderValues);
|
||||
const orderHash = await this._exchange.getOrderHash(params.orderAddresses, params.orderValues);
|
||||
return orderHash;
|
||||
}
|
||||
public async isValidSignatureAsync(order: Order): Promise<boolean> {
|
||||
const isValidSignature = await this.exchange.isValidSignature(
|
||||
const isValidSignature = await this._exchange.isValidSignature(
|
||||
order.params.maker,
|
||||
order.params.orderHashHex,
|
||||
order.params.v,
|
||||
@@ -146,12 +146,12 @@ export class ExchangeWrapper {
|
||||
}
|
||||
public async isRoundingErrorAsync(numerator: BigNumber, denominator: BigNumber,
|
||||
target: BigNumber): Promise<boolean> {
|
||||
const isRoundingError = await this.exchange.isRoundingError(numerator, denominator, target);
|
||||
const isRoundingError = await this._exchange.isRoundingError(numerator, denominator, target);
|
||||
return isRoundingError;
|
||||
}
|
||||
public async getPartialAmountAsync(numerator: BigNumber, denominator: BigNumber,
|
||||
target: BigNumber): Promise<BigNumber> {
|
||||
const partialAmount = new BigNumber(await this.exchange.getPartialAmount(numerator, denominator, target));
|
||||
const partialAmount = new BigNumber(await this._exchange.getPartialAmount(numerator, denominator, target));
|
||||
return partialAmount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as Web3 from 'web3';
|
||||
import {ContractInstance, TransactionDataParams} from './types';
|
||||
|
||||
export class MultiSigWrapper {
|
||||
private multiSig: ContractInstance;
|
||||
private _multiSig: ContractInstance;
|
||||
public static encodeFnArgs(name: string, abi: Web3.AbiDefinition[], args: any[]) {
|
||||
const abiEntity = _.find(abi, {name}) as Web3.MethodAbi;
|
||||
if (_.isUndefined(abiEntity)) {
|
||||
@@ -22,13 +22,13 @@ export class MultiSigWrapper {
|
||||
return funcSig + argsData.join('');
|
||||
}
|
||||
constructor(multiSigContractInstance: ContractInstance) {
|
||||
this.multiSig = multiSigContractInstance;
|
||||
this._multiSig = multiSigContractInstance;
|
||||
}
|
||||
public async submitTransactionAsync(destination: string, from: string,
|
||||
dataParams: TransactionDataParams,
|
||||
value: number = 0) {
|
||||
const {name, abi, args = []} = dataParams;
|
||||
const encoded = MultiSigWrapper.encodeFnArgs(name, abi, args);
|
||||
return this.multiSig.submitTransaction(destination, value, encoded, {from});
|
||||
return this._multiSig.submitTransaction(destination, value, encoded, {from});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export class Order {
|
||||
if (_.isUndefined(v) || _.isUndefined(r) || _.isUndefined(s)) {
|
||||
throw new Error('Cannot call isValidSignature on unsigned order');
|
||||
}
|
||||
const orderHash = this.getOrderHash();
|
||||
const orderHash = this._getOrderHash();
|
||||
const msgHash = ethUtil.hashPersonalMessage(ethUtil.toBuffer(orderHash));
|
||||
try {
|
||||
const pubKey = ethUtil.ecrecover(msgHash, v, ethUtil.toBuffer(r), ethUtil.toBuffer(s));
|
||||
@@ -32,7 +32,7 @@ export class Order {
|
||||
}
|
||||
}
|
||||
public async signAsync() {
|
||||
const orderHash = this.getOrderHash();
|
||||
const orderHash = this._getOrderHash();
|
||||
const signature = await promisify<string>(web3.eth.sign)(this.params.maker, orderHash);
|
||||
const {v, r, s} = ethUtil.fromRpcSig(signature);
|
||||
this.params = _.assign(this.params, {
|
||||
@@ -88,7 +88,7 @@ export class Order {
|
||||
};
|
||||
return cancel;
|
||||
}
|
||||
private getOrderHash(): string {
|
||||
private _getOrderHash(): string {
|
||||
const orderHash = crypto.solSHA3([
|
||||
this.params.exchangeContractAddress,
|
||||
this.params.maker,
|
||||
|
||||
@@ -6,9 +6,9 @@ import {Order} from './order';
|
||||
import {DefaultOrderParams, OptionalOrderParams, OrderParams} from './types';
|
||||
|
||||
export class OrderFactory {
|
||||
private defaultOrderParams: DefaultOrderParams;
|
||||
private _defaultOrderParams: DefaultOrderParams;
|
||||
constructor(defaultOrderParams: DefaultOrderParams) {
|
||||
this.defaultOrderParams = defaultOrderParams;
|
||||
this._defaultOrderParams = defaultOrderParams;
|
||||
}
|
||||
public async newSignedOrderAsync(customOrderParams: OptionalOrderParams = {}) {
|
||||
const randomExpiration = new BigNumber(Math.floor((Date.now() + (Math.random() * 100000000000)) / 1000));
|
||||
@@ -16,7 +16,7 @@ export class OrderFactory {
|
||||
expirationTimestampInSec: randomExpiration,
|
||||
salt: ZeroEx.generatePseudoRandomSalt(),
|
||||
taker: ZeroEx.NULL_ADDRESS,
|
||||
}, this.defaultOrderParams, customOrderParams);
|
||||
}, this._defaultOrderParams, customOrderParams);
|
||||
const order = new Order(orderParams);
|
||||
await order.signAsync();
|
||||
return order;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {ContractInstance, Token} from './types';
|
||||
|
||||
export class TokenRegWrapper {
|
||||
private tokenReg: ContractInstance;
|
||||
private _tokenReg: ContractInstance;
|
||||
constructor(tokenRegContractInstance: ContractInstance) {
|
||||
this.tokenReg = tokenRegContractInstance;
|
||||
this._tokenReg = tokenRegContractInstance;
|
||||
}
|
||||
public addTokenAsync(token: Token, from: string) {
|
||||
const tx = this.tokenReg.addToken(
|
||||
const tx = this._tokenReg.addToken(
|
||||
token.address,
|
||||
token.name,
|
||||
token.symbol,
|
||||
@@ -18,7 +18,7 @@ export class TokenRegWrapper {
|
||||
return tx;
|
||||
}
|
||||
public async getTokenMetaDataAsync(tokenAddress: string) {
|
||||
const data = await this.tokenReg.getTokenMetaData(tokenAddress);
|
||||
const data = await this._tokenReg.getTokenMetaData(tokenAddress);
|
||||
const token: Token = {
|
||||
address: data[0],
|
||||
name: data[1],
|
||||
@@ -30,7 +30,7 @@ export class TokenRegWrapper {
|
||||
return token;
|
||||
}
|
||||
public async getTokenByNameAsync(tokenName: string) {
|
||||
const data = await this.tokenReg.getTokenByName(tokenName);
|
||||
const data = await this._tokenReg.getTokenByName(tokenName);
|
||||
const token: Token = {
|
||||
address: data[0],
|
||||
name: data[1],
|
||||
@@ -42,7 +42,7 @@ export class TokenRegWrapper {
|
||||
return token;
|
||||
}
|
||||
public async getTokenBySymbolAsync(tokenSymbol: string) {
|
||||
const data = await this.tokenReg.getTokenBySymbol(tokenSymbol);
|
||||
const data = await this._tokenReg.getTokenBySymbol(tokenSymbol);
|
||||
const token: Token = {
|
||||
address: data[0],
|
||||
name: data[1],
|
||||
|
||||
Reference in New Issue
Block a user