Class: Bitcoin::Taproot::ControlBlock
- Inherits:
-
Object
- Object
- Bitcoin::Taproot::ControlBlock
- Includes:
- HexConverter
- Defined in:
- lib/bitcoin/taproot/control_block.rb
Instance Attribute Summary collapse
-
#internal_key ⇒ Object
Returns the value of attribute internal_key.
-
#leaf_ver ⇒ Object
Returns the value of attribute leaf_ver.
-
#parity ⇒ Object
Returns the value of attribute parity.
-
#paths ⇒ Object
Returns the value of attribute paths.
Class Method Summary collapse
-
.parse_from_payload(payload) ⇒ Bitcoin::Taproot::ControlBlock
parse control block from payload.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(parity, leaf_ver, internal_key, paths = []) ⇒ ControlBlock
constructor
A new instance of ControlBlock.
-
#to_payload ⇒ String
Convert to payload.
Methods included from HexConverter
Constructor Details
#initialize(parity, leaf_ver, internal_key, paths = []) ⇒ ControlBlock
Returns a new instance of ControlBlock.
15 16 17 18 19 20 |
# File 'lib/bitcoin/taproot/control_block.rb', line 15 def initialize(parity, leaf_ver, internal_key, paths = []) @parity = parity @leaf_ver = leaf_ver @internal_key = internal_key @paths = paths end |
Instance Attribute Details
#internal_key ⇒ Object
Returns the value of attribute internal_key.
8 9 10 |
# File 'lib/bitcoin/taproot/control_block.rb', line 8 def internal_key @internal_key end |
#leaf_ver ⇒ Object
Returns the value of attribute leaf_ver.
7 8 9 |
# File 'lib/bitcoin/taproot/control_block.rb', line 7 def leaf_ver @leaf_ver end |
#parity ⇒ Object
Returns the value of attribute parity.
6 7 8 |
# File 'lib/bitcoin/taproot/control_block.rb', line 6 def parity @parity end |
#paths ⇒ Object
Returns the value of attribute paths.
9 10 11 |
# File 'lib/bitcoin/taproot/control_block.rb', line 9 def paths @paths end |
Class Method Details
.parse_from_payload(payload) ⇒ Bitcoin::Taproot::ControlBlock
parse control block from payload.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bitcoin/taproot/control_block.rb', line 25 def self.parse_from_payload(payload) raise Bitcoin::Taproot::Error, 'Invalid data length for Control Block' if payload.bytesize > TAPROOT_CONTROL_MAX_SIZE raise Bitcoin::Taproot::Error, 'Invalid data length for path in Control Block' unless (payload.bytesize - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_NODE_SIZE == 0 control, internal_key, paths = payload.unpack('Ca32a*') parity = control & 1 leaf_ver = control - parity raw_paths = StringIO.new(paths) paths = (paths.bytesize / 32).times.map { raw_paths.read(32).bth } ControlBlock.new(parity, leaf_ver, internal_key.bth, paths) end |
Instance Method Details
#==(other) ⇒ Object
42 43 44 |
# File 'lib/bitcoin/taproot/control_block.rb', line 42 def ==(other) to_payload == other.to_payload end |
#to_payload ⇒ String
Convert to payload.
38 39 40 |
# File 'lib/bitcoin/taproot/control_block.rb', line 38 def to_payload [parity + leaf_ver].pack("C") + internal_key.htb + paths.map(&:htb).join end |