| 1 | package Bitcoin::Crypto::Transaction::UTXO; | ||||||||||||||||||||||||||||
| 2 | 26 | $Bitcoin::Crypto::Transaction::UTXO::VERSION = '4.006'; | |||||||||||||||||||||||||||
| 3 | 28 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 28 | ▶ | use Mooish::Base -standard; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use Types::Common -sigs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 28 | ▶ | use Bitcoin::Crypto::Transaction; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 28 | ▶ | use Bitcoin::Crypto::Transaction::Output; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 28 | ▶ | use Bitcoin::Crypto::Types -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 28 | ▶ | use Bitcoin::Crypto::Util::Internal qw(to_format); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 28 | ▶ | use Bitcoin::Crypto::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 26 | my %utxos; | |||||||||||||||||||||||||||
| 16 | my $loader; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 26 | has param 'txid' => ( | |||||||||||||||||||||||||||
| 19 | coerce => ByteStrLen [32], | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 26 | has option 'block' => ( | |||||||||||||||||||||||||||
| 23 | isa => InstanceOf ['Bitcoin::Crypto::Block'], | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 26 | has param 'output_index' => ( | |||||||||||||||||||||||||||
| 27 | isa => IntMaxBits [32], | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 26 | has param 'output' => ( | |||||||||||||||||||||||||||
| 31 | coerce => (InstanceOf ['Bitcoin::Crypto::Transaction::Output']) | ||||||||||||||||||||||||||||
| 32 | ->plus_coercions(HashRef q{ Bitcoin::Crypto::Transaction::Output->new($_) }), | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub register | ||||||||||||||||||||||||||||
| 36 | 94 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 94 | my ($self) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Do not store NULLDATA UTXOs | ||||||||||||||||||||||||||||
| 40 | 94 | ▶ | return $self | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->output->is_standard and $self->output->locking_script->type eq "NULLDATA"
MC/DC100%2/2
$self->output->is_standard and $self->output->locking_script->type eq "NULLDATA"
$self->output->is_standard
$self->output->locking_script->type eq "NULLDATA"
Truth table100%3/3
A and B
A= $self->output->is_standardB= $self->output->locking_script->type eq "NULLDATA"
| |||||||||||||||||||||||||||||
| 41 | if $self->output->is_standard && $self->output->locking_script->type eq 'NULLDATA'; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 92 | $utxos{$self->txid . $self->output_index} = $self; | |||||||||||||||||||||||||||
| 44 | 92 | return $self; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub unregister | ||||||||||||||||||||||||||||
| 48 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unregister: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | delete $utxos{$self->txid . $self->output_index}; | |||||||||||||||||||||||||||
| 52 | 3 | return $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 26 | signature_for get => ( | |||||||||||||||||||||||||||
| 56 | method => !!1, | ||||||||||||||||||||||||||||
| 57 | positional => [ByteStr, PositiveOrZeroInt], | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub get | ||||||||||||||||||||||||||||
| 61 | 127 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 62 | 127 | my ($class, $txid, $outid) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 127 | my $utxo = $utxos{$txid . $outid}; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 117 | ▶ | if (!$utxo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 59 | ▶ | $utxo = $loader->($txid, $outid) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | if defined $loader; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 59 | ▶ | Bitcoin::Crypto::Exception::UTXO->raise( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | sprintf( | ||||||||||||||||||||||||||||
| 73 | "no UTXO registered for transaction id %s and output index %s", | ||||||||||||||||||||||||||||
| 74 | to_format [hex => $txid], | ||||||||||||||||||||||||||||
| 75 | $outid | ||||||||||||||||||||||||||||
| 76 | ) | ||||||||||||||||||||||||||||
| 77 | ) unless $utxo; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 47 | $utxo->register; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 105 | return $utxo; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 26 | signature_for set_loader => ( | |||||||||||||||||||||||||||
| 86 | method => !!1, | ||||||||||||||||||||||||||||
| 87 | positional => [Maybe [CodeRef]], | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub set_loader | ||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | 2 | $loader = pop; | |||||||||||||||||||||||||||
| 93 | 2 | return; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub unload | ||||||||||||||||||||||||||||
| 97 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unload: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 2 | my @result = values %utxos; | |||||||||||||||||||||||||||
| 99 | 2 | %utxos = (); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 2 | return \@result; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub registered_count | ||||||||||||||||||||||||||||
| 105 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
registered_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 4 | return scalar keys %utxos; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 26 | signature_for extract => ( | |||||||||||||||||||||||||||
| 110 | method => !!1, | ||||||||||||||||||||||||||||
| 111 | positional => [ByteStr], | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub extract | ||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | 2 | my ($class, $serialized_tx) = @_; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | my $tx = Bitcoin::Crypto::Transaction->from_serialized($serialized_tx); | |||||||||||||||||||||||||||
| 119 | 2 | $tx->update_utxos; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | return; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 26 | 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||