import { getLatestABI } from './AbiService';
import Promisify from '../utils/Promisify';
import Services from '../Services';

export class MarketplaceService extends Services {
  private address: string;

  constructor(address: string) {
    super();
    this.address = address;
  }

  private get contract() {
    return (async () => (this.rpcService.contract(await getLatestABI('MARKETPLACE_ABI'), this.address)))();
  }

  public getAllProducts(): Promise<string[]> {
    return Promisify(async (cb) => {
      (await this.contract).getAllProducts(cb);
    });
  }
}
