<commit_before>require 'bitcoin'

module Coloredcoins
  class Transaction
    attr_reader :tx

    def initialize(hex)
      @tx = Bitcoin::P::Tx.new([hex].pack('H*'))
    end

    def to_hex
      raw_tx = Bitcoin::P::Tx.binary_from_json(new_tx.to_json)
      raw_tx.scrub.unpack('H*').first
    end

    def new_tx
      h = JSON.load(tx.to_json)
      @new_tx = Bitcoin::P::Tx.new(nil)
      @new_tx.ver = (h['ver'] || h['version'])
      @new_tx.lock_time = h['lock_time']
      ins  = h['in']  || h['inputs']
      outs = h['out'] || h['outputs']
      ins .each { |input|   @new_tx.add_in  Bitcoin::P::TxIn.from_hash(input)   }
      outs.each { |output|  @new_tx.add_out Bitcoin::P::TxOut.from_hash(output) }
      @new_tx
    end

    def broadcast
      response = Coloredcoins.broadcast(to_hex)
      return response[:txId] if response[:txId]
      response
    end
  end
end<commit_msg>lower assignment branch of new_tx<commit_after>require 'bitcoin'

module Coloredcoins
  class Transaction
    attr_reader :tx

    def initialize(hex)
      @tx = Bitcoin::P::Tx.new([hex].pack('H*'))
    end

    def to_hex
      raw_tx = Bitcoin::P::Tx.binary_from_json(new_tx.to_json)
      raw_tx.scrub.unpack('H*').first
    end

    def new_tx
      @new_tx = Bitcoin::P::Tx.new
      @new_tx.ver = tx.ver
      @new_tx.lock_time = tx.lock_time
      tx.in.each  { |input|   @new_tx.add_in(input)   }
      tx.out.each { |output|  @new_tx.add_out(output) }
      @new_tx
    end

    def broadcast
      response = Coloredcoins.broadcast(to_hex)
      return response[:txId] if response[:txId]
      response
    end
  end
end
{'fraction_non_alphanumeric': 0.13943488943488944, 'fraction_numerical': 0.0, 'mean_word_length': 2.710706150341686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2339580', 'n_tokens_mistral': 612, 'n_tokens_neox': 600, 'n_words': 109}