Crypto/Transaction/Signer/Legacy.pm

filter: Statementstmt 100% 48 / 48 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 94.2% 65 / 69 CC 6 SCAR 8.4
CC
6
Cov
95%
_get_signature
5.1
_finalize
2.0
__ANON__
1.0
CRAP 2.3
« Crypto/Script/Compiler/Opcode.pm ↑ Summary Crypto/Script/Transaction.pm »
1 package Bitcoin::Crypto::Transaction::Signer::Legacy;
2 14 $Bitcoin::Crypto::Transaction::Signer::Legacy::VERSION = '4.005';
3 14 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 14 ▶use Bitcoin::Crypto qw(btc_script);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use Bitcoin::Crypto::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use Bitcoin::Crypto::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Bitcoin::Crypto::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 14 extends 'Bitcoin::Crypto::Transaction::Signer';
15  
16 sub _initialize
17 24 ▶{
Subroutine _initialize: called CC=1 SCAR=0.0
18 24 my ($self) = @_;
19  
20 # do nothing
21 }
22  
23 sub _get_signature
24 27 ▶{
Subroutine _get_signature: called CC=5 SCAR=16.2
25 27 my ($self, $privkey, $args) = @_;
26 27 my $runner = $self->_runner;
27 27 my $pubkey = $privkey->get_public_key;
28  
29 27 ▶ if ($self->_multisigop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_multisigop) { } 11 16 27
30 11 my $stack = $runner->stack;
31 11 ▶ my $pubkey_count = $runner->to_int($stack->[-1] // "\x00");
Condition50%1/2
$stack->[-1] // "\0"
l!l
110
MC/DC0%0/1
$stack->[-1] // "\0"
$stack->[-1]
Truth table50%1/2
A
A= $stack->[-1]
Aresult
11
00
32 11 my @pubkeys = @{$stack}[-1 - $pubkey_count .. -2];
33  
34 11 my $pubkey_serialized = $pubkey->to_serialized;
35 Bitcoin::Crypto::Exception::Sign->raise(
36 'bad private key for public keys encountered in script multisigop at position ' . $runner->pos
37 11 ▶ ) unless any { $_ eq $pubkey_serialized } @pubkeys;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $_ eq $pubkey_serialized; } , @pubkeys) 0 11 11
38 }
39 else {
40 16 my $script_pubkey = $runner->stack->[-1];
41 16 ▶ Bitcoin::Crypto::Exception::Sign->raise(
Branch: 1 branch
BranchTrueFalseTotal
unless $script_pubkey eq $pubkey->to_serialized 0 16 16
42 'bad private key for public key encountered in script sigop at position ' . $runner->pos
43 ) unless $script_pubkey eq $pubkey->to_serialized;
44 }
45  
46 my $digest_obj = $runner->transaction->get_digest_object(
47 sighash => $args->{sighash},
48 27 );
49  
50 27 return $privkey->sign_message($digest_obj->get_digest)
51 . pack 'C', $digest_obj->sighash;
52 }
53  
54 sub _finalize
55 13 ▶{
Subroutine _finalize: called CC=2 SCAR=6.9
56 13 my ($self) = @_;
57  
58 13 my $script = btc_script->new;
59 13 foreach my $element (reverse @{$self->_signature}) {
60 29 $script->push($element);
61 }
62  
63 13 $self->transaction->inputs->[$self->signing_index]->set_signature_script($script);
64 }
65  
66 14 1;
67  
« Crypto/Script/Compiler/Opcode.pm ↑ Summary Crypto/Script/Transaction.pm »