Class: Bitcoin::ScriptWitness

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/script_witness.rb

Overview

witness

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stack = []) ⇒ ScriptWitness

Returns a new instance of ScriptWitness.



8
9
10
# File 'lib/bitcoin/script_witness.rb', line 8

def initialize(stack = [])
  @stack = stack
end

Instance Attribute Details

#stackObject (readonly)

Returns the value of attribute stack.



6
7
8
# File 'lib/bitcoin/script_witness.rb', line 6

def stack
  @stack
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/bitcoin/script_witness.rb', line 12

def self.parse_from_payload(payload)
  buf = payload.is_a?(StringIO) ? payload : StringIO.new(payload)
  return self.new if buf.eof?
  size = Bitcoin.unpack_var_int_from_io(buf)
  stack = size.times.map do
    buf.read(Bitcoin.unpack_var_int_from_io(buf))
  end
  self.new(stack)
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/bitcoin/script_witness.rb', line 22

def empty?
  stack.empty?
end

#to_payloadObject



26
27
28
29
30
31
# File 'lib/bitcoin/script_witness.rb', line 26

def to_payload
  p = Bitcoin.pack_var_int(stack.size)
  p << stack.map { |s|
    Bitcoin.pack_var_int(s.bytesize) << s
  }.join
end

#to_sObject



33
34
35
# File 'lib/bitcoin/script_witness.rb', line 33

def to_s
  stack.map{|s|s.bth}.join(' ')
end