Sha256: a8299243311233ba0e9fddde9dd28530f9d512e99b1b8a4b1bab2d908bd720ac

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

# Porting part of the code from bitcoin-ruby. see the license.
# https://github.com/lian/bitcoin-ruby/blob/master/COPYING

module Bitcoin

  # transaction output
  class TxOut

    include OpenAssets::MarkerOutput

    attr_accessor :value
    attr_accessor :script_pubkey

    def initialize(value: 0, script_pubkey: nil)
      @value = value
      @script_pubkey = script_pubkey
    end

    def self.parse_from_payload(payload)
      buf = payload.is_a?(String) ? StringIO.new(payload) : payload
      value = buf.read(8).unpack('q').first
      script_size = Bitcoin.unpack_var_int_from_io(buf)
      new(value: value, script_pubkey: Script.parse_from_payload(buf.read(script_size)))
    end

    def to_payload
      s = script_pubkey.to_payload
      [value].pack('Q') << Bitcoin.pack_var_int(s.length) << s
    end

    def to_empty_payload
      'ffffffffffffffff00'.htb
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bitcoinrb-0.1.7 lib/bitcoin/tx_out.rb
bitcoinrb-0.1.6 lib/bitcoin/tx_out.rb