<commit_before>/**
 * Ethereum transaction model
 */
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { BaseTransaction, TransactionType } from '../baseCoin';
import { BaseKey } from '../baseCoin/iface';
import { InvalidTransactionError } from '../baseCoin/errors';
import { KeyPair } from './keyPair';
import { TxData } from './iface';
import { Utils } from './';

export class Transaction extends BaseTransaction {
  private _parsedTransaction?: TxData; // transaction in JSON format
  private _encodedTransaction?: string; // transaction in hex format
  private _source: string;

  /**
   * Public constructor.
   *
   * @param {Readonly<CoinConfig>} coinConfig
   * @param {TxData | string} txData The object transaction data or encoded transaction data
   */
  constructor(coinConfig: Readonly<CoinConfig>, txData?: TxData | string) {
    super(coinConfig);
    if (typeof txData === 'string') {
      this._encodedTransaction = txData;
    } else {
      this._parsedTransaction = txData;
    }
  }

  /**
   * Set the transaction data
   *
   * @param {TxData} transactionData The transaction data to set
   */
  setTransactionData(transactionData: TxData): void {
    this._parsedTransaction = transactionData;
  }

  /**
   * Set the encoded transaction data
   *
   * @param {string} encodedTransaction The encoded transaction data
   */
  setEncodedTransactionData(encodedTransaction: string): void {
    this._encodedTransaction = encodedTransaction;
  }

  /**
   * Set the transaction type
   *
   * @param {TransactionType} transactionType The transaction type to be set
   */
  setTransactionType(transactionType: TransactionType): void {
    this._type = transactionType;
  }

  /** @inheritdoc */
  canSign(key: BaseKey): boolean {
    //TODO: implement this validation for the ethereum network
    return true;
  }

  /**
   * Sign the transaction with the provided key. It does not check if the signer is allowed to sign
   * it or not.
   *
   * @param {KeyPair} keyPair The key to sign the transaction with
   */
  async sign(keyPair: KeyPair): Promise<void> {
    // Check if there is a transaction to sign
    if (!this._parsedTransaction) {
      throw new InvalidTransactionError('Empty transaction');
    }
    this._encodedTransaction = await Utils.sign(this._parsedTransaction, keyPair);
  }

  /** @inheritdoc */
  toBroadcastFormat(): any {
    if (!this._encodedTransaction) {
      throw new InvalidTransactionError('Missing encoded transaction');
    }
    return '0x' + this._encodedTransaction;
  }

  /** @inheritdoc */
  toJson(): any {
    if (!this._parsedTransaction) {
      throw new InvalidTransactionError('Empty transaction');
    }
    return this._parsedTransaction;
  }
}
<commit_msg>Remove method to set encoded transaction in ETH transaction builder<commit_after>/**
 * Ethereum transaction model
 */
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { BaseTransaction, TransactionType } from '../baseCoin';
import { BaseKey } from '../baseCoin/iface';
import { InvalidTransactionError } from '../baseCoin/errors';
import { KeyPair } from './keyPair';
import { TxData } from './iface';
import { Utils } from './';

export class Transaction extends BaseTransaction {
  private _parsedTransaction?: TxData; // transaction in JSON format
  private _encodedTransaction?: string; // transaction in hex format
  private _source: string;

  /**
   * Public constructor.
   *
   * @param {Readonly<CoinConfig>} coinConfig
   * @param {TxData | string} txData The object transaction data or encoded transaction data
   */
  constructor(coinConfig: Readonly<CoinConfig>, txData?: TxData | string) {
    super(coinConfig);
    if (typeof txData === 'string') {
      this._encodedTransaction = txData;
    } else {
      this._parsedTransaction = txData;
    }
  }

  /**
   * Set the transaction data
   *
   * @param {TxData} transactionData The transaction data to set
   */
  setTransactionData(transactionData: TxData): void {
    this._parsedTransaction = transactionData;
  }

  /**
   * Set the transaction type
   *
   * @param {TransactionType} transactionType The transaction type to be set
   */
  setTransactionType(transactionType: TransactionType): void {
    this._type = transactionType;
  }

  /** @inheritdoc */
  canSign(key: BaseKey): boolean {
    //TODO: implement this validation for the ethereum network
    return true;
  }

  /**
   * Sign the transaction with the provided key. It does not check if the signer is allowed to sign
   * it or not.
   *
   * @param {KeyPair} keyPair The key to sign the transaction with
   */
  async sign(keyPair: KeyPair): Promise<void> {
    // Check if there is a transaction to sign
    if (!this._parsedTransaction) {
      throw new InvalidTransactionError('Empty transaction');
    }
    this._encodedTransaction = await Utils.sign(this._parsedTransaction, keyPair);
  }

  /** @inheritdoc */
  toBroadcastFormat(): any {
    if (!this._encodedTransaction) {
      throw new InvalidTransactionError('Missing encoded transaction');
    }
    return '0x' + this._encodedTransaction;
  }

  /** @inheritdoc */
  toJson(): any {
    if (!this._parsedTransaction) {
      throw new InvalidTransactionError('Empty transaction');
    }
    return this._parsedTransaction;
  }
}

{'fraction_non_alphanumeric': 0.10501367365542388, 'fraction_numerical': 0.00036463081130355516, 'mean_word_length': 2.9869186046511627, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '489789', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1471, 'n_words': 454}