Class: Bitcoin::PSBT::Proprietary
- Inherits:
-
Object
- Object
- Bitcoin::PSBT::Proprietary
- Defined in:
- lib/bitcoin/psbt/proprietary.rb
Overview
Proprietary element of PSBT github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#Proprietary_Use_Type
Instance Attribute Summary collapse
-
#identifier ⇒ Object
binary format.
-
#sub_type ⇒ Object
integer.
-
#value ⇒ Object
binary format.
Instance Method Summary collapse
-
#initialize(key, value) ⇒ Proprietary
constructor
A new instance of Proprietary.
-
#key ⇒ String
Get key data with key type(0xfc).
- #to_h ⇒ Object
-
#to_payload ⇒ String
Convert to payload.
-
#to_s ⇒ String
Show contents.
Constructor Details
#initialize(key, value) ⇒ Proprietary
Returns a new instance of Proprietary.
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
#identifier ⇒ Object
binary format
6 7 8 |
# File 'lib/bitcoin/psbt/proprietary.rb', line 6 def identifier @identifier end |
#sub_type ⇒ Object
integer
7 8 9 |
# File 'lib/bitcoin/psbt/proprietary.rb', line 7 def sub_type @sub_type end |
#value ⇒ Object
binary format
8 9 10 |
# File 'lib/bitcoin/psbt/proprietary.rb', line 8 def value @value end |
Instance Method Details
#key ⇒ String
Get key data with key type(0xfc).
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_h ⇒ Object
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_payload ⇒ String
Convert to payload
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_s ⇒ String
Show contents
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 |