Class: Bitcoin::PSBT::KeyOriginInfo

Inherits:
Object
  • Object
show all
Includes:
KeyPath
Defined in:
lib/bitcoin/psbt/key_origin_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from KeyPath

#parse_key_path, #to_key_path

Constructor Details

#initialize(fingerprint: nil, key_paths: []) ⇒ KeyOriginInfo

Returns a new instance of KeyOriginInfo.



11
12
13
14
# File 'lib/bitcoin/psbt/key_origin_info.rb', line 11

def initialize(fingerprint: nil, key_paths: [])
  @fingerprint = fingerprint
  @key_paths = key_paths
end

Instance Attribute Details

#fingerprintObject (readonly)

String hex format



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

def fingerprint
  @fingerprint
end

#key_pathsObject (readonly)



9
10
11
# File 'lib/bitcoin/psbt/key_origin_info.rb', line 9

def key_paths
  @key_paths
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



16
17
18
19
# File 'lib/bitcoin/psbt/key_origin_info.rb', line 16

def self.parse_from_payload(payload)
  buf = StringIO.new(payload)
  self.new(fingerprint: buf.read(4).bth, key_paths: buf.read.unpack('I*'))
end

Instance Method Details

#to_hObject



25
26
27
# File 'lib/bitcoin/psbt/key_origin_info.rb', line 25

def to_h
  {fingerprint: fingerprint, key_paths: to_key_path(key_paths)}
end

#to_payloadObject



21
22
23
# File 'lib/bitcoin/psbt/key_origin_info.rb', line 21

def to_payload
  fingerprint.htb + key_paths.pack('I*')
end

#to_sObject



29
30
31
# File 'lib/bitcoin/psbt/key_origin_info.rb', line 29

def to_s
  to_h.to_s
end