| 1 | package Bitcoin::Crypto::Script::Tree::Leaf; | ||||||||||||||||||||||||||||
| 2 | 41 | $Bitcoin::Crypto::Script::Tree::Leaf::VERSION = '4.006'; | |||||||||||||||||||||||||||
| 3 | 41 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 41 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 41 | ▶ | use Mooish::Base -standard; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 41 | ▶ | use Types::Common -sigs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 41 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 41 | ▶ | use Bitcoin::Crypto::Util::Internal qw(tagged_hash pack_compactsize to_format); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 41 | has option 'depth' => ( | |||||||||||||||||||||||||||
| 13 | isa => PositiveInt, | ||||||||||||||||||||||||||||
| 14 | writer => 1, | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 41 | has option 'leaf_version' => ( | |||||||||||||||||||||||||||
| 18 | isa => IntMaxBits [8], | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 41 | has option 'script' => ( | |||||||||||||||||||||||||||
| 22 | coerce => BitcoinScript, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has param 'id' => ( | ||||||||||||||||||||||||||||
| 26 | coerce => ByteStr, | ||||||||||||||||||||||||||||
| 27 | 11 | ▶ | lazy => sub { shift->hash }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 41 | ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 41 | has param 'hash' => ( | |||||||||||||||||||||||||||
| 31 | coerce => ByteStr, | ||||||||||||||||||||||||||||
| 32 | lazy => 1, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | has field 'path' => ( | ||||||||||||||||||||||||||||
| 36 | isa => ArrayRef [ByteStr], | ||||||||||||||||||||||||||||
| 37 | 145 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 41 | ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub BUILD | ||||||||||||||||||||||||||||
| 41 | 145 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 145 | my ($self) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 145 | $self->hash; # forces integrity check and fills ->{hash} slot | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub _build_hash | ||||||||||||||||||||||||||||
| 48 | 115 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_build_hash: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 49 | 115 | my ($self) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 115 | ▶ | Bitcoin::Crypto::Exception::ScriptTree->raise( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_leaf_version and $self->has_script
MC/DC0%0/2
$self->has_leaf_version and $self->has_script
$self->has_leaf_version
$self->has_script
Truth table33%1/3
A and B
A= $self->has_leaf_versionB= $self->has_script
| |||||||||||||||||||||||||||||
| 52 | 'calculating tree leaf hash requires a leaf_version plus a script' | ||||||||||||||||||||||||||||
| 53 | ) unless $self->has_leaf_version && $self->has_script; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 115 | my $script = $self->script->to_serialized; | |||||||||||||||||||||||||||
| 56 | 115 | my $script_len = pack_compactsize(length $script); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 115 | return tagged_hash('TapLeaf', join '', pack('C', $self->leaf_version), $script_len, $script); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 41 | signature_for dump => ( | |||||||||||||||||||||||||||
| 62 | method => !!1, | ||||||||||||||||||||||||||||
| 63 | positional => [], | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | sub dump | ||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | my @result; | ||||||||||||||||||||||||||||
| 71 | push @result, 'Tree leaf ' . to_format [hex => $self->id]; | ||||||||||||||||||||||||||||
| 72 | push @result, 'hash ' . to_format [hex => $self->hash] | ||||||||||||||||||||||||||||
| 73 | unless $self->hash eq $self->id; | ||||||||||||||||||||||||||||
| 74 | push @result, 'depth ' . $self->depth; | ||||||||||||||||||||||||||||
| 75 | push @result, 'leaf version ' . $self->leaf_version; | ||||||||||||||||||||||||||||
| 76 | push @result, 'script: ' . $self->script->dump; | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | return join "\n", @result; | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 41 | 1; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||