| 1 | package Bitcoin::Crypto::Script; | ||||||||||||||||||||||||||||||||
| 2 | 64 | $Bitcoin::Crypto::Script::VERSION = '4.005'; | |||||||||||||||||||||||||||||||
| 3 | 64 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 64 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 64 | ▶ | use Mooish::Base -standard; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 64 | ▶ | use Types::Common -sigs; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 64 | ▶ | use Crypt::Digest::SHA256 qw(sha256); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 64 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 64 | ▶ | use List::Util qw(any); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 64 | ▶ | use Carp qw(carp); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 64 | ▶ | use Bitcoin::Crypto::Base58 qw(encode_base58check decode_base58check); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 64 | ▶ | use Bitcoin::Crypto::Bech32 qw(encode_segwit decode_segwit get_hrp); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 64 | ▶ | use Bitcoin::Crypto::Constants qw(:witness); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 64 | ▶ | use Bitcoin::Crypto::Util::Internal qw(hash160 hash256 get_address_type to_format); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 64 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 64 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 64 | ▶ | use Bitcoin::Crypto::Script::Opcode; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 64 | ▶ | use Bitcoin::Crypto::Script::Runner; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 64 | ▶ | use Bitcoin::Crypto::Script::Compiler; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 64 | ▶ | use Bitcoin::Crypto::Script::Common; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 64 | ▶ | use Bitcoin::Crypto::Script::Recognition; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 64 | has field '_serialized' => ( | |||||||||||||||||||||||||||||||
| 26 | isa => ByteStr, | ||||||||||||||||||||||||||||||||
| 27 | writer => 1, | ||||||||||||||||||||||||||||||||
| 28 | default => '', | ||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 64 | has field '_recognition' => ( | |||||||||||||||||||||||||||||||
| 32 | isa => InstanceOf ['Bitcoin::Crypto::Script::Recognition'], | ||||||||||||||||||||||||||||||||
| 33 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 34 | clearer => -hidden, | ||||||||||||||||||||||||||||||||
| 35 | handles => { | ||||||||||||||||||||||||||||||||
| 36 | get_raw_address => 'address', | ||||||||||||||||||||||||||||||||
| 37 | type => 'type', | ||||||||||||||||||||||||||||||||
| 38 | segwit_version => 'segwit_version', | ||||||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 64 | has field '_compiler' => ( | |||||||||||||||||||||||||||||||
| 43 | isa => InstanceOf ['Bitcoin::Crypto::Script::Compiler'], | ||||||||||||||||||||||||||||||||
| 44 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 45 | clearer => -hidden, | ||||||||||||||||||||||||||||||||
| 46 | handles => { | ||||||||||||||||||||||||||||||||
| 47 | operations => 'operations', | ||||||||||||||||||||||||||||||||
| 48 | has_errors => 'has_errors', | ||||||||||||||||||||||||||||||||
| 49 | assert_valid => 'assert_valid', | ||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 64 | with qw(Bitcoin::Crypto::Role::Network); | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | sub _build_recognition | ||||||||||||||||||||||||||||||||
| 56 | 360 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_recognition: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 57 | 360 | return Bitcoin::Crypto::Script::Recognition->check(shift); | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | sub _build_compiler | ||||||||||||||||||||||||||||||||
| 61 | 798 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_compiler: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 62 | 798 | return Bitcoin::Crypto::Script::Compiler->compile(shift); | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | sub _build | ||||||||||||||||||||||||||||||||
| 66 | 132 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_build: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 67 | 132 | my ($self, $type, $address) = @_; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 132 | state $types = do { | |||||||||||||||||||||||||||||||
| 70 | 48 | ▶ | my $legacy = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 71 | 48 | my ($self, $address, $type) = @_; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 48 | my $decoded = decode_base58check($address); | |||||||||||||||||||||||||||||||
| 74 | 48 | my $network_byte = substr $decoded, 0, 1, ''; | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 48 | ▶ | Bitcoin::Crypto::Exception::Address->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | "legacy scripts should contain 20 bytes" | ||||||||||||||||||||||||||||||||
| 78 | ) unless length $decoded == 20; | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 48 | my $byte_method = lc "p2${type}_byte"; | |||||||||||||||||||||||||||||||
| 81 | 48 | ▶ | Bitcoin::Crypto::Exception::NetworkCheck->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | "provided address $address is not P2$type on network " . $self->network->name | ||||||||||||||||||||||||||||||||
| 83 | ) if $network_byte ne $self->network->$byte_method; | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 46 | Bitcoin::Crypto::Script::Common->fill($type => $self, $decoded); | |||||||||||||||||||||||||||||||
| 86 | 24 | }; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 46 | ▶ | my $witness = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 89 | 46 | my ($self, $address, $name, $version, $length) = @_; | |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 46 | my $data = decode_segwit $address; | |||||||||||||||||||||||||||||||
| 92 | 46 | my $this_version = substr $data, 0, 1, ''; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 46 | ▶ | Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 95 | "$name script only handles witness version $version" | ||||||||||||||||||||||||||||||||
| 96 | ) unless $this_version eq chr $version; | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 45 | ▶ | Bitcoin::Crypto::Exception::SegwitProgram->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | "$name script should contain $length bytes" | ||||||||||||||||||||||||||||||||
| 100 | ) unless length $data eq $length; | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 43 | ▶ | Bitcoin::Crypto::Exception::NetworkCheck->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | "provided address $address does not belong to network " . $self->network->name | ||||||||||||||||||||||||||||||||
| 104 | ) if get_hrp($address) ne $self->network->segwit_hrp; | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 41 | $self | |||||||||||||||||||||||||||||||
| 107 | ->add("OP_$version") | ||||||||||||||||||||||||||||||||
| 108 | ->push($data); | ||||||||||||||||||||||||||||||||
| 109 | 24 | }; | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||
| 112 | 10 | ▶ | P2PK => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 113 | 10 | my ($self, $pubkey) = @_; | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 10 | $self | |||||||||||||||||||||||||||||||
| 116 | ->push($pubkey) | ||||||||||||||||||||||||||||||||
| 117 | ->add('OP_CHECKSIG'); | ||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 27 | ▶ | P2PKH => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 121 | 27 | $legacy->(@_, 'PKH'); | |||||||||||||||||||||||||||||||
| 122 | }, | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 21 | ▶ | P2SH => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 125 | 21 | $legacy->(@_, 'SH'); | |||||||||||||||||||||||||||||||
| 126 | }, | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | 5 | ▶ | P2MS => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=21.8
| |||||||||||||||||||||||||||||||||
| 129 | 5 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 5 | ▶ | Bitcoin::Crypto::Exception::ScriptPush->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 'P2MS script argument must be an array reference' | ||||||||||||||||||||||||||||||||
| 133 | ) unless ref $data eq 'ARRAY'; | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 5 | my ($signatures_num, @pubkeys) = @$data; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 5 | ▶ | Bitcoin::Crypto::Exception::ScriptPush->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$signatures_num >= 0 and $signatures_num <= 15
MC/DC0%0/2
$signatures_num >= 0 and $signatures_num <= 15
$signatures_num >= 0
$signatures_num <= 15
Truth table33%1/3
A and B
A= $signatures_num >= 0B= $signatures_num <= 15
| |||||||||||||||||||||||||||||||||
| 138 | 'P2MS script first element must be a number between 1 and 15' | ||||||||||||||||||||||||||||||||
| 139 | ) unless $signatures_num >= 0 && $signatures_num <= 15; | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | Bitcoin::Crypto::Exception::ScriptPush->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@pubkeys >= $signatures_num and @pubkeys <= 15
MC/DC0%0/2
@pubkeys >= $signatures_num and @pubkeys <= 15
@pubkeys >= $signatures_num
@pubkeys <= 15
Truth table33%1/3
A and B
A= @pubkeys >= $signatures_numB= @pubkeys <= 15
| |||||||||||||||||||||||||||||||||
| 142 | 'P2MS script remaining elements number should be between the number of signatures and 15' | ||||||||||||||||||||||||||||||||
| 143 | ) unless @pubkeys >= $signatures_num && @pubkeys <= 15; | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 5 | $self->push(chr $signatures_num); | |||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 5 | foreach my $pubkey (@pubkeys) { | |||||||||||||||||||||||||||||||
| 148 | 13 | $self->push($pubkey); | |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | $self | ||||||||||||||||||||||||||||||||
| 152 | 5 | ->push(chr scalar @pubkeys) | |||||||||||||||||||||||||||||||
| 153 | ->add('OP_CHECKMULTISIG'); | ||||||||||||||||||||||||||||||||
| 154 | }, | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 13 | ▶ | P2WPKH => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 157 | 13 | $witness->(@_, 'P2WPKH', 0, 20); | |||||||||||||||||||||||||||||||
| 158 | }, | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 9 | ▶ | P2WSH => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 161 | 9 | $witness->(@_, 'P2WSH', 0, 32); | |||||||||||||||||||||||||||||||
| 162 | }, | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 24 | ▶ | P2TR => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 165 | 24 | $witness->(@_, 'P2TR', 1, 32); | |||||||||||||||||||||||||||||||
| 166 | }, | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 23 | ▶ | NULLDATA => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 169 | 23 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 23 | $self | |||||||||||||||||||||||||||||||
| 172 | ->add('OP_RETURN') | ||||||||||||||||||||||||||||||||
| 173 | ->push($data); | ||||||||||||||||||||||||||||||||
| 174 | }, | ||||||||||||||||||||||||||||||||
| 175 | 24 | }; | |||||||||||||||||||||||||||||||
| 176 | }; | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | Bitcoin::Crypto::Exception::ScriptType->raise( | ||||||||||||||||||||||||||||||||
| 179 | "unknown standard script type $type" | ||||||||||||||||||||||||||||||||
| 180 | 132 | ▶ | ) if !$types->{$type}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 132 | $types->{$type}->($self, $address); | |||||||||||||||||||||||||||||||
| 183 | 125 | return; | |||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | sub opcode_class | ||||||||||||||||||||||||||||||||
| 187 | 1688 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
opcode_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 188 | 1688 | return 'Bitcoin::Crypto::Script::Opcode'; | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | sub BUILD | ||||||||||||||||||||||||||||||||
| 192 | 2904 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 193 | 2904 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | 2904 | ▶ | if ($args->{type}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 196 | Bitcoin::Crypto::Exception::ScriptPush->raise( | ||||||||||||||||||||||||||||||||
| 197 | 'script with a "type" also requires an "address"' | ||||||||||||||||||||||||||||||||
| 198 | 132 | ▶ | ) unless $args->{address}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 132 | $self->_build($args->{type}, $args->{address}); | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | sub is_pushes_only | ||||||||||||||||||||||||||||||||
| 205 | 26 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
is_pushes_only: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 206 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 26 | foreach my $op (@{$self->operations}) { | |||||||||||||||||||||||||||||||
| 209 | 47 | ▶ | return !!0 if $op->[0]->non_push_opcode; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | 25 | return !!1; | |||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | # same as add_raw, but does not clear the object - to avoid clearing it | ||||||||||||||||||||||||||||||||
| 216 | # multiple times per operation | ||||||||||||||||||||||||||||||||
| 217 | sub _add_raw | ||||||||||||||||||||||||||||||||
| 218 | 1769 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
_add_raw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 219 | 1769 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | 1769 | $self->_set_serialized($self->_serialized . $bytes); | |||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | 64 | signature_for add_raw => ( | |||||||||||||||||||||||||||||||
| 225 | method => !!1, | ||||||||||||||||||||||||||||||||
| 226 | positional => [ByteStr], | ||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | sub add_raw | ||||||||||||||||||||||||||||||||
| 230 | 1253 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
add_raw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 231 | 1253 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 1253 | $self->_add_raw($bytes); | |||||||||||||||||||||||||||||||
| 234 | 1253 | $self->_clear_compiler; | |||||||||||||||||||||||||||||||
| 235 | 1253 | $self->_clear_recognition; | |||||||||||||||||||||||||||||||
| 236 | 1253 | return $self; | |||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | 64 | signature_for add_operation => ( | |||||||||||||||||||||||||||||||
| 240 | method => !!1, | ||||||||||||||||||||||||||||||||
| 241 | positional => [Str], | ||||||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | sub add_operation | ||||||||||||||||||||||||||||||||
| 245 | 1251 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
add_operation: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 246 | 1251 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | 1251 | my $opcode = $self->opcode_class->get_opcode_by_name($name); | |||||||||||||||||||||||||||||||
| 249 | 1251 | $self->add_raw(chr $opcode->code); | |||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | 1251 | return $self; | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | sub add | ||||||||||||||||||||||||||||||||
| 255 | 1079 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 256 | 1079 | goto \&add_operation; | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | 64 | signature_for push_bytes => ( | |||||||||||||||||||||||||||||||
| 260 | method => !!1, | ||||||||||||||||||||||||||||||||
| 261 | positional => [ByteStr], | ||||||||||||||||||||||||||||||||
| 262 | ); | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | sub push_bytes | ||||||||||||||||||||||||||||||||
| 265 | 563 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
push_bytes: called CC=10 SCAR=23.6
| |||||||||||||||||||||||||||||||||
| 266 | 563 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 563 | my $len = length $bytes; | |||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 563 | ▶ | if ($len == 0) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 271 | 10 | return $self->add_operation('OP_0'); | |||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | elsif ($len == 1) { | ||||||||||||||||||||||||||||||||
| 274 | 54 | my $ord = ord($bytes); | |||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | 54 | ▶ | if ($ord <= 0x10 && $ord != 0) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$ord <= 16 and $ord != 0
MC/DC50%1/2
$ord <= 16 and $ord != 0
$ord <= 16
$ord != 0
Truth table66%2/3
A and B
A= $ord <= 16B= $ord != 0
| |||||||||||||||||||||||||||||||||
| 277 | 35 | return $self->add_operation("OP_$ord"); | |||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||
| 279 | elsif ($ord == 0x81) { | ||||||||||||||||||||||||||||||||
| 280 | 2 | return $self->add_operation('OP_1NEGATE'); | |||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 516 | ▶ | if ($len <= 75) { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 285 | 508 | $self | |||||||||||||||||||||||||||||||
| 286 | ->_add_raw(pack 'Ca*', $len, $bytes); | ||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||
| 288 | elsif ($len <= 0xff) { | ||||||||||||||||||||||||||||||||
| 289 | 6 | $self | |||||||||||||||||||||||||||||||
| 290 | ->add_operation('OP_PUSHDATA1') | ||||||||||||||||||||||||||||||||
| 291 | ->_add_raw(pack 'Ca*', $len, $bytes); | ||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||
| 293 | elsif ($len <= 0xffff) { | ||||||||||||||||||||||||||||||||
| 294 | 2 | $self | |||||||||||||||||||||||||||||||
| 295 | ->add_operation('OP_PUSHDATA2') | ||||||||||||||||||||||||||||||||
| 296 | ->_add_raw(pack 'va*', $len, $bytes); | ||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||
| 298 | elsif ($len <= 0xffffffff) { | ||||||||||||||||||||||||||||||||
| 299 | 0 | $self | |||||||||||||||||||||||||||||||
| 300 | ->add_operation('OP_PUSHDATA4') | ||||||||||||||||||||||||||||||||
| 301 | ->_add_raw(pack 'Va*', $len, $bytes); | ||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||
| 303 | else { | ||||||||||||||||||||||||||||||||
| 304 | 0 | Bitcoin::Crypto::Exception::ScriptPush->raise( | |||||||||||||||||||||||||||||||
| 305 | 'too much data to push onto stack in one operation' | ||||||||||||||||||||||||||||||||
| 306 | ); | ||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||
| 309 | 516 | return $self; | |||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | 64 | signature_for push_number => ( | |||||||||||||||||||||||||||||||
| 313 | method => !!1, | ||||||||||||||||||||||||||||||||
| 314 | positional => [Int | Str | InstanceOf ['Math::BigInt']], | ||||||||||||||||||||||||||||||||
| 315 | ); | ||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | sub push_number | ||||||||||||||||||||||||||||||||
| 318 | { | ||||||||||||||||||||||||||||||||
| 319 | my ($self, $number) = @_; | ||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | return $self->push_bytes(Bitcoin::Crypto::Script::Runner->from_int($number)); | ||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | sub push | ||||||||||||||||||||||||||||||||
| 325 | 413 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
push: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 326 | 413 | goto \&push_bytes; | |||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||
| 329 | # this can only detect native segwit in this context, as P2SH outputs are | ||||||||||||||||||||||||||||||||
| 330 | # indistinguishable from any other P2SH | ||||||||||||||||||||||||||||||||
| 331 | sub is_native_segwit | ||||||||||||||||||||||||||||||||
| 332 | 859 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
is_native_segwit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 333 | 859 | return defined shift->segwit_version; | |||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | sub is_taproot | ||||||||||||||||||||||||||||||||
| 337 | 355 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
is_taproot: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 338 | 355 | ▶ | return (shift->type // '') eq 'P2TR'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
(shift())->type // ""
MC/DC100%1/1
(shift())->type // ""
(shift())->type
Truth table100%2/2
A
A= (shift())->type
| |||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | sub get_hash | ||||||||||||||||||||||||||||||||
| 342 | 51 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
get_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 343 | 51 | return hash160(shift->_serialized); | |||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | sub to_serialized | ||||||||||||||||||||||||||||||||
| 347 | 3560 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
to_serialized: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 348 | 3560 | goto \&_serialized; | |||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||
| 351 | 64 | signature_for from_serialized => ( | |||||||||||||||||||||||||||||||
| 352 | method => !!1, | ||||||||||||||||||||||||||||||||
| 353 | positional => [ByteStr], | ||||||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | sub from_serialized | ||||||||||||||||||||||||||||||||
| 357 | 2413 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
from_serialized: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 358 | 2413 | my ($class, $bytes) = @_; | |||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||
| 360 | 2413 | my $self = $class->new; | |||||||||||||||||||||||||||||||
| 361 | 2273 | $self->_set_serialized($bytes); | |||||||||||||||||||||||||||||||
| 362 | 2393 | return $self; | |||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | 64 | signature_for from_standard => ( | |||||||||||||||||||||||||||||||
| 366 | method => !!1, | ||||||||||||||||||||||||||||||||
| 367 | positional => [ScriptDesc, {slurpy => !!1}], | ||||||||||||||||||||||||||||||||
| 368 | ); | ||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||
| 370 | sub from_standard | ||||||||||||||||||||||||||||||||
| 371 | { | ||||||||||||||||||||||||||||||||
| 372 | my ($class, $desc) = @_; | ||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | ▶ | if ($desc->[0] eq 'address') { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 375 | $desc->[0] = get_address_type($desc->[1]); | ||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | return $class->new( | ||||||||||||||||||||||||||||||||
| 379 | type => $desc->[0], | ||||||||||||||||||||||||||||||||
| 380 | address => $desc->[1], | ||||||||||||||||||||||||||||||||
| 381 | ); | ||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||
| 384 | 64 | signature_for run => ( | |||||||||||||||||||||||||||||||
| 385 | method => !!1, | ||||||||||||||||||||||||||||||||
| 386 | positional => [ArrayRef [ByteStr], {default => []}], | ||||||||||||||||||||||||||||||||
| 387 | ); | ||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | sub run | ||||||||||||||||||||||||||||||||
| 390 | 279 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 391 | 279 | my ($self, $initial_stack) = @_; | |||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | 279 | my $runner = Bitcoin::Crypto::Script::Runner->new(); | |||||||||||||||||||||||||||||||
| 394 | 279 | return $runner->execute($self, $initial_stack); | |||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||
| 397 | sub witness_program | ||||||||||||||||||||||||||||||||
| 398 | 25 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
witness_program: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 399 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||
| 401 | 25 | my $program = Bitcoin::Crypto::Script->new(network => $self->network); | |||||||||||||||||||||||||||||||
| 402 | 25 | $program | |||||||||||||||||||||||||||||||
| 403 | ->add_operation('OP_' . SEGWIT_WITNESS_VERSION) | ||||||||||||||||||||||||||||||||
| 404 | ->push_bytes(sha256($self->to_serialized)); | ||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | 25 | return $program; | |||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||
| 409 | sub get_legacy_address | ||||||||||||||||||||||||||||||||
| 410 | 44 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
get_legacy_address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 411 | 44 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 412 | 44 | return encode_base58check($self->network->p2sh_byte . $self->get_hash); | |||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||
| 415 | sub get_compat_address | ||||||||||||||||||||||||||||||||
| 416 | 7 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
get_compat_address: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 417 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | # network field is not required, lazy check for completeness | ||||||||||||||||||||||||||||||||
| 420 | 7 | ▶ | Bitcoin::Crypto::Exception::NetworkConfig->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 421 | 'this network does not support segregated witness' | ||||||||||||||||||||||||||||||||
| 422 | ) unless $self->network->supports_segwit; | ||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||
| 424 | 7 | return $self->witness_program->get_legacy_address; | |||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||
| 427 | sub get_segwit_address | ||||||||||||||||||||||||||||||||
| 428 | 8 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
get_segwit_address: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 429 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||
| 431 | # network field is not required, lazy check for completeness | ||||||||||||||||||||||||||||||||
| 432 | 8 | ▶ | Bitcoin::Crypto::Exception::NetworkConfig->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 433 | 'this network does not support segregated witness' | ||||||||||||||||||||||||||||||||
| 434 | ) unless $self->network->supports_segwit; | ||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||
| 436 | 8 | return encode_segwit($self->network->segwit_hrp, $self->witness_program->run->stack_serialized); | |||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | sub get_address | ||||||||||||||||||||||||||||||||
| 440 | 25 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
get_address: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 441 | 25 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 442 | 25 | my $address = $self->get_raw_address; | |||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||
| 444 | return undef | ||||||||||||||||||||||||||||||||
| 445 | 25 | ▶ | unless $self->has_type && defined $address; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_type and defined $address
MC/DC100%2/2
$self->has_type and defined $address
$self->has_type
defined $address
Truth table100%3/3
A and B
A= $self->has_typeB= defined $address
| |||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||
| 447 | 11 | ▶ | if ($self->is_native_segwit) { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||
| 449 | # network field is not required, lazy check for completeness | ||||||||||||||||||||||||||||||||
| 450 | 7 | ▶ | Bitcoin::Crypto::Exception::NetworkConfig->raise( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 451 | 'this network does not support segregated witness' | ||||||||||||||||||||||||||||||||
| 452 | ) unless $self->network->supports_segwit; | ||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | 7 | ▶ | my $version = pack 'C', | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 455 | $self->is_taproot | ||||||||||||||||||||||||||||||||
| 456 | ? TAPROOT_WITNESS_VERSION | ||||||||||||||||||||||||||||||||
| 457 | : SEGWIT_WITNESS_VERSION; | ||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||
| 459 | 7 | return encode_segwit($self->network->segwit_hrp, $version . $address); | |||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||
| 461 | elsif ($self->type eq 'P2PKH') { | ||||||||||||||||||||||||||||||||
| 462 | 1 | return encode_base58check($self->network->p2pkh_byte . $address); | |||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||
| 464 | elsif ($self->type eq 'P2SH') { | ||||||||||||||||||||||||||||||||
| 465 | 1 | return encode_base58check($self->network->p2sh_byte . $address); | |||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||
| 467 | elsif ($self->type eq 'NULLDATA') { | ||||||||||||||||||||||||||||||||
| 468 | 2 | return qq("$address"); | |||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||
| 472 | sub has_type | ||||||||||||||||||||||||||||||||
| 473 | 167 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
has_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 474 | 167 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||
| 476 | 167 | return defined $self->type; | |||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||
| 479 | sub is_empty | ||||||||||||||||||||||||||||||||
| 480 | 138 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
is_empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 481 | 138 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | 138 | return length $self->_serialized == 0; | |||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | sub dump | ||||||||||||||||||||||||||||||||
| 487 | 3 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 488 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||
| 490 | 3 | my $ops = $self->operations; | |||||||||||||||||||||||||||||||
| 491 | 3 | my $num = @$ops; | |||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||
| 493 | 3 | ▶ | return 'Empty script' unless $num; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||
| 495 | 3 | ▶ | my $type = $self->type // 'Custom'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->type // "Custom"
MC/DC100%1/1
$self->type // "Custom"
$self->type
Truth table100%2/2
A
A= $self->type
| |||||||||||||||||||||||||||||||||
| 496 | 3 | ▶ | my $errors = $self->has_errors ? ' (with errors)' : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | 3 | my @result; | |||||||||||||||||||||||||||||||
| 499 | 3 | CORE::push @result, "$type script$errors, $num ops:"; | |||||||||||||||||||||||||||||||
| 500 | 3 | foreach my $op (@$ops) { | |||||||||||||||||||||||||||||||
| 501 | 5 | CORE::push @result, ' ' . $op->opcode->name . ' (' . (to_format [hex => $op->raw_data]) . ')'; | |||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||
| 504 | 3 | return join "\n", @result; | |||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||
| 507 | 64 | 1; | |||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||
| 509 | __END__ | ||||||||||||||||||||||||||||||||