<commit_before>import Promise from 'bluebird'
import _ from 'lodash'
import { coinbase } from './web3'

export default class Contract {
  constructor(abi, address) {
    this.web3Contract = web3.eth.contract(abi).at(address)
  }

  // async callSync(func, args = []) {
  //   const asd = await this.call(func, args);
  //   console.log(asd);
  //   return asd
  // }

  call(func, args = []) {
    return new Promise((resolve, reject) => {
      // console.log('call', func);
      // console.log(args);
      this.web3Contract[func](...args, (error, result) => {
        if (error) {
          reject(error);
        }
        resolve(result);
      })
    });
  }

  get(func, args = []) {
    // console.log('get', func);
    // console.log(args);
    return this.web3Contract[func](...args)
  }

  send(func, args = [], txArgs = {}) {
    return new Promise((resolve, reject) => {
      const paramsGas = args.concat([
        _.merge({
          from: coinbase()
        }, txArgs)
      ]);
      this.web3Contract[func].estimateGas(...paramsGas, (error, gas) => {
        if (error) {
          reject(error);
        }
        console.log(gas);
        const params = args.concat([
          _.merge({
            from: coinbase(),
            gas: gas + 50000
          }, txArgs)
        ]);
        console.log('send', func);
        console.log(params);
        this.web3Contract[func](...params, (errorTx, result) => {
          if (errorTx) {
            reject(errorTx);
          }
          resolve(result);
        })
      })
      // const params = args.concat([
      //   _.merge({
      //     from: coinbase()
      //   }, txArgs)
      // ]);
      // console.log('send', func);
      // console.log(params);
      // this.web3Contract[func](...params, (error, result) => {
      //   if (error) {
      //     reject(error);
      //   }
      //   resolve(result);
      // })
    });
  }

  watch(func) {
    return new Promise((resolve, reject) => {
      const event = this.web3Contract[func]({}, '', (error, result) => {
        if (error) {
          reject(error);
        }
        event.stopWatching()
        resolve(result.args);
      })
    });<commit_msg>fix stopWatching async<commit_after>import Promise from 'bluebird'
import _ from 'lodash'
import { coinbase } from './web3'

export default class Contract {
  constructor(abi, address) {
    this.web3Contract = web3.eth.contract(abi).at(address)
  }

  // async callSync(func, args = []) {
  //   const asd = await this.call(func, args);
  //   console.log(asd);
  //   return asd
  // }

  call(func, args = []) {
    return new Promise((resolve, reject) => {
      // console.log('call', func);
      // console.log(args);
      this.web3Contract[func](...args, (error, result) => {
        if (error) {
          reject(error);
        }
        resolve(result);
      })
    });
  }

  get(func, args = []) {
    // console.log('get', func);
    // console.log(args);
    return this.web3Contract[func](...args)
  }

  send(func, args = [], txArgs = {}) {
    return new Promise((resolve, reject) => {
      const paramsGas = args.concat([
        _.merge({
          from: coinbase()
        }, txArgs)
      ]);
      this.web3Contract[func].estimateGas(...paramsGas, (error, gas) => {
        if (error) {
          reject(error);
        }
        console.log(gas);
        const params = args.concat([
          _.merge({
            from: coinbase(),
            gas: gas + 50000
          }, txArgs)
        ]);
        console.log('send', func);
        console.log(params);
        this.web3Contract[func](...params, (errorTx, result) => {
          if (errorTx) {
            reject(errorTx);
          }
          resolve(result);
        })
      })
      // const params = args.concat([
      //   _.merge({
      //     from: coinbase()
      //   }, txArgs)
      // ]);
      // console.log('send', func);
      // console.log(params);
      // this.web3Contract[func](...params, (error, result) => {
      //   if (error) {
      //     reject(error);
      //   }
      //   resolve(result);
      // })
    });
  }

  watch(func) {
    return new Promise((resolve, reject) => {
      const event = this.web3Contract[func]({}, '', (error, result) => {
        if (error) {
          reject(error);
        }
        event.stopWatching((e, r) => {
          console.log(e, r);
        })
        resolve(result.args);
      })
    });
{'fraction_non_alphanumeric': 0.179285553808133, 'fraction_numerical': 0.006290721186250281, 'mean_word_length': 1.6787003610108304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5293746', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1387, 'n_words': 257}