diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-08-28 02:01:53 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-08-28 04:04:54 +0800 |
commit | be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578 (patch) | |
tree | bc7d475f2409281f8ebf4234334d2894a45f0932 /packages/contract-wrappers | |
parent | 68f2dc11b4361af125f9f2ab367d758f673928ea (diff) | |
download | dexon-sol-tools-be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578.tar dexon-sol-tools-be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578.tar.gz dexon-sol-tools-be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578.tar.bz2 dexon-sol-tools-be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578.tar.lz dexon-sol-tools-be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578.tar.xz dexon-sol-tools-be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578.tar.zst dexon-sol-tools-be2f4cbdcafa19cc8433ff2dc2f0ff6befd64578.zip |
Add getBalanceAndAllowance to wrapper
Diffstat (limited to 'packages/contract-wrappers')
-rw-r--r-- | packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts | 20 | ||||
-rw-r--r-- | packages/contract-wrappers/src/types.ts | 6 |
2 files changed, 25 insertions, 1 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts index dac243434..3b83fc53b 100644 --- a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts @@ -5,7 +5,7 @@ import { ContractAbi } from 'ethereum-types'; import * as _ from 'lodash'; import { artifacts } from '../artifacts'; -import { OrderAndTraderInfo, OrdersAndTradersInfo, TraderInfo } from '../types'; +import { BalanceAndAllowance, OrderAndTraderInfo, OrdersAndTradersInfo, TraderInfo } from '../types'; import { assert } from '../utils/assert'; import { ContractWrapper } from './contract_wrapper'; @@ -92,6 +92,24 @@ export class OrderValidatorWrapper extends ContractWrapper { const result = await OrderValidatorContractInstance.getTradersInfo.callAsync(orders, takerAddresses); return result; } + /** + * Get an object conforming to BalanceAndAllowance containing on-chain balance and allowance for some address and assetData + * @return BalanceAndAllowance + */ + public async getBalanceAndAllowanceAsync(address: string, assetData: string): Promise<BalanceAndAllowance> { + assert.isETHAddressHex('address', address); + assert.isHexString('assetData', assetData); + const OrderValidatorContractInstance = await this._getOrderValidatorContractAsync(); + const balanceAndAllowance = await OrderValidatorContractInstance.getBalanceAndAllowance.callAsync( + address, + assetData, + ); + const result = { + balance: balanceAndAllowance[0], + allowance: balanceAndAllowance[1], + }; + return result; + } // HACK: We don't want this method to be visible to the other units within that package but not to the end user. // TS doesn't give that possibility and therefore we make it private and access it over an any cast. Because of that tslint sees it as unused. // tslint:disable-next-line:no-unused-variable diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index e73a09fe3..c51e0ae48 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -204,7 +204,13 @@ export interface OrdersAndTradersInfo { ordersInfo: OrderInfo[]; tradersInfo: TraderInfo[]; } + export interface OrderAndTraderInfo { orderInfo: OrderInfo; traderInfo: TraderInfo; } + +export interface BalanceAndAllowance { + balance: BigNumber; + allowance: BigNumber; +} |