aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/proxy_wrapper.ts
blob: bff917eee1dc9597dab4e13df69e6b8a8d4be0ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as _ from 'lodash';
import {Web3Wrapper} from '../web3_wrapper';
import {ContractWrapper} from './contract_wrapper';
import * as ProxyArtifacts from '../artifacts/Proxy.json';
import {ProxyContract} from '../types';

/**
 * This class includes the functionality related to interacting with the Proxy contract.
 */
export class ProxyWrapper extends ContractWrapper {
    private _proxyContractIfExists?: ProxyContract;
    public invalidateContractInstance(): void {
        delete this._proxyContractIfExists;
    }
    /**
     * Check if the Exchange contract address is authorized by the Proxy contract.
     * @param   exchangeContractAddress     The hex encoded address of the Exchange contract to use.
     * @return  Whether the exchangeContractAddress is authorized.
     */
    public async isAuthorizedAsync(exchangeContractAddress: string): Promise<boolean> {
        const proxyContractInstance = await this._getProxyContractAsync();
        const isAuthorized = await proxyContractInstance.authorized.call(exchangeContractAddress);
        return isAuthorized;
    }
    /**
     * Get the list of all Exchange contract addresses authorized by the Proxy contract.
     * @param   exchangeContractAddress     The hex encoded address of the Exchange contract to use.
     * @return  The list of authorized addresses.
     */
    public async getAuthorizedAddressesAsync(exchangeContractAddress: string): Promise<string[]> {
        const proxyContractInstance = await this._getProxyContractAsync();
        const authorizedAddresses = await proxyContractInstance.getAuthorizedAddresses.call();
        return authorizedAddresses;
    }
    private async _getProxyContractAsync(): Promise<ProxyContract> {
        if (!_.isUndefined(this._proxyContractIfExists)) {
            return this._proxyContractIfExists;
        }
        const contractInstance = await this._instantiateContractIfExistsAsync((ProxyArtifacts as any));
        this._proxyContractIfExists = contractInstance as ProxyContract;
        return this._proxyContractIfExists;
    }
}