<commit_before>import {each as promiseEach} from 'promise-each2'
import { GenericEthereumManager } from './ethereum-transaction-monitor'
import { EthereumTransaction } from './types'

export interface EthereumSweepConfig {
  minSweepAmount: number
  sweepAddress: string
}

export interface Bristle {
  from: string
  to: string
  account: string
  status: number
  txid: string
  blockIndex: number
  amount: number
}

export class Broom {
  private minSweepAmount: number
  private sweepGas: number
  private sweepAddress: string
  private manager: GenericEthereumManager<EthereumTransaction>
  private client

  constructor(ethereumConfig: EthereumSweepConfig, ethereumManager: GenericEthereumManager<EthereumTransaction>, ethereumClient) {
    this.minSweepAmount = ethereumConfig.minSweepAmount
    this.sweepAddress = ethereumConfig.sweepAddress
    this.manager = ethereumManager
    this.client = ethereumClient
  }

  private getSweepGas() {
    return this.client.getGas()
      .then(gasPrice => this.sweepGas = gasPrice)
      .catch(err => err)
  }

    private singleSweep(address):Promise<Bristle> {
      return this.client.getBalance(address)
        .then(balance => {
          if(balance > this.minSweepAmount) {
            return this.client.send(address, this.sweepAddress, this.calculateSendAmount)
            .then(txHash => this.saveSweepRecord(txHash))
          }
      })
      .catch(err => err)
  }

  calculateSendAmount(amount) {
    return amount - (this.sweepGas * 21000)
  }

  saveSweepRecord(txHash) {
    return this.client.getClient().getTransaction(txHash)
      .then(transaction => {
        return this.manager.saveSweepRecord(transaction:Bristle)
          .then(() => this.manager.saveTransaction(transaction))
      })
      .catch(err => err)
  }

  sweep() {
    return this.getSweepGas()
      .then(() => {
        return this.manager.getAddresses()
          .then(addresses => promiseEach(addresses, address => this.singleSweep(address) ))
      })
  }

}
<commit_msg>Fixes sweep to not getBlock and retrieve blocknumber<commit_after>import {each as promiseEach} from 'promise-each2'
import { GenericEthereumManager } from './ethereum-transaction-monitor'
import { EthereumTransaction } from './types'

export interface EthereumSweepConfig {
  minSweepAmount: number
  sweepAddress: string
}

export interface Bristle {
  from: string
  to: string
  status: number
  txid: string
  amount: number
}

export class Broom {
  private minSweepAmount: number
  private sweepGas: number
  private sweepAddress: string
  private manager: GenericEthereumManager<EthereumTransaction>
  private client

  constructor(ethereumConfig: EthereumSweepConfig, ethereumManager: GenericEthereumManager<EthereumTransaction>, ethereumClient) {
    this.minSweepAmount = ethereumConfig.minSweepAmount
    this.sweepAddress = ethereumConfig.sweepAddress
    this.manager = ethereumManager
    this.client = ethereumClient
  }

  private getSweepGas():Promise<void> {
    return this.client.getGas()
      .then(gasPrice => this.sweepGas = gasPrice)
      .catch(err => err)
  }

    private singleSweep(address):Promise<Bristle> {
      return this.client.getBalance(address)
        .then(balance => {
          if(balance > this.minSweepAmount) {
            const sendAmount = this.calculateSendAmount()
            return this.client.send(address, this.sweepAddress, sendAmount)
              .then(txHash => this.saveSweepRecord({
                from: address,
                to: this.sweepAddress,
                status: 0,
                txid: txHash,
                amount: sendAmount
            })
          }
      })
      .catch(err => err)
  }

  calculateSendAmount(amount) {
    return amount - (this.sweepGas * 21000)
  }

  saveSweepRecord(bristle: Bristle) {
    return this.manager.saveSweepRecord(bristle)
      .then(() => this.manager.saveTransaction(bristle))
      .catch(err => err)
  }

  sweep() {
    return this.getSweepGas()
      .then(() => {
        return this.manager.getAddresses()
          .then(addresses => promiseEach(addresses, address => this.singleSweep(address) ))
      })
  }

}

{'fraction_non_alphanumeric': 0.10062439961575408, 'fraction_numerical': 0.003121998078770413, 'mean_word_length': 3.144278606965174, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 33, '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': '1943307', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1255, 'n_words': 248}