| 1 | package Bitcoin::Crypto::Transaction::Digest::Result; | ||||||||||
| 2 | 36 | $Bitcoin::Crypto::Transaction::Digest::Result::VERSION = '4.005'; | |||||||||
| 3 | 36 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 36 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 36 | ▶ | use Mooish::Base -standard; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 36 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 36 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 36 | ▶ | use Bitcoin::Crypto::Util::Internal qw(hash256 tagged_hash); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | use overload | ||||||||||
| 13 | 36 | ▶ | q{""} => "as_string", | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 36 | fallback => 1; | |||||||||
| 15 | |||||||||||
| 16 | 36 | has param 'taproot' => ( | |||||||||
| 17 | coerce => Bool, | ||||||||||
| 18 | default => !!0, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 36 | has option 'preimage' => ( | |||||||||
| 22 | coerce => ByteStr, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 36 | has param 'hash' => ( | |||||||||
| 26 | coerce => ByteStr, | ||||||||||
| 27 | lazy => 1, | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | sub _build_hash | ||||||||||
| 31 | 208 | ▶ | { | ||||||||
|
Subroutine
_build_hash: called CC=3 SCAR=11.0
| |||||||||||
| 32 | 208 | my $self = shift; | |||||||||
| 33 | 208 | my $preimage = $self->preimage; | |||||||||
| 34 | |||||||||||
| 35 | 208 | ▶ | Bitcoin::Crypto::Exception->raise( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | "can't hash without preimage" | ||||||||||
| 37 | ) unless defined $preimage; | ||||||||||
| 38 | |||||||||||
| 39 | 208 | ▶ | if ($self->taproot) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 56 | return tagged_hash('TapSighash', $preimage); | |||||||||
| 41 | } | ||||||||||
| 42 | else { | ||||||||||
| 43 | 152 | return hash256($preimage); | |||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub as_string | ||||||||||
| 48 | 17 | ▶ | { | ||||||||
|
Subroutine
as_string: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 49 | 17 | my ($self) = @_; | |||||||||
| 50 | |||||||||||
| 51 | # backcompat - returns preimage | ||||||||||
| 52 | |||||||||||
| 53 | 17 | ▶ | Bitcoin::Crypto::Exception->raise( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 'no preimage generated by digesting' | ||||||||||
| 55 | ) unless $self->has_preimage; | ||||||||||
| 56 | |||||||||||
| 57 | 17 | return $self->preimage; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 36 | 1; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||