Class: Bitcoin::PSBT::Proprietary

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ Proprietary

Returns a new instance of Proprietary.

Parameters:

  • key (String)

    key with binary format without key type(0xfc).

  • value (String)

    value with binary format.



12
13
14
15
16
17
18
# File 'lib/bitcoin/psbt/proprietary.rb', line 12

def initialize(key, value)
  buf = StringIO.new(key)
  id_len = Bitcoin.unpack_var_int_from_io(buf)
  @identifier = buf.read(id_len)
  @sub_type = Bitcoin.unpack_var_int_from_io(buf)
  @value = value
end

Instance Attribute Details

#identifierObject

binary format



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

def identifier
  @identifier
end

#sub_typeObject

integer



7
8
9
# File 'lib/bitcoin/psbt/proprietary.rb', line 7

def sub_type
  @sub_type
end

#valueObject

binary format



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

def value
  @value
end

Instance Method Details

#keyString

Get key data with key type(0xfc).

Returns:

  • (String)

    key data with binary format.



28
29
30
31
32
33
34
# File 'lib/bitcoin/psbt/proprietary.rb', line 28

def key
  k = [PSBT_GLOBAL_TYPES[:proprietary]].pack('C')
  k << Bitcoin.pack_var_int(identifier ? identifier.bytesize : 0)
  k << identifier if identifier
  k << Bitcoin.pack_var_int(sub_type)
  k
end

#to_hObject



43
44
45
# File 'lib/bitcoin/psbt/proprietary.rb', line 43

def to_h
  {identifier: identifier.bth, sub_type: sub_type, value: value.bth}
end

#to_payloadString

Convert to payload

Returns:

  • (String)

    payload with binary format.



38
39
40
41
# File 'lib/bitcoin/psbt/proprietary.rb', line 38

def to_payload
  k = key
  Bitcoin.pack_var_int(k.bytesize) + k + Bitcoin.pack_var_int(value.bytesize) + value
end

#to_sString

Show contents

Returns:



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

def to_s
  "identifier: #{identifier&.bth}, sub type: #{sub_type}, value: #{value&.bth}"
end