File Coverage

blib/lib/Blockchain/Ethereum/Transaction/Legacy.pm
Criterion Covered Total %
statement 29 29 100.0
branch 3 4 75.0
condition 4 6 66.6
subroutine 8 8 100.0
pod 2 4 50.0
total 46 51 90.2


line stmt bran cond sub pod time code
1             package Blockchain::Ethereum::Transaction::Legacy;
2              
3 2     2   406139 use v5.26;
  2         8  
4 2     2   15 use strict;
  2         4  
  2         102  
5 2     2   11 use warnings;
  2         6  
  2         239  
6              
7             # ABSTRACT: Ethereum Legacy transaction abstraction
8             our $AUTHORITY = 'cpan:REFECO'; # AUTHORITY
9             our $VERSION = '0.021'; # VERSION
10              
11 2     2   550 use parent 'Blockchain::Ethereum::Transaction';
  2         432  
  2         17  
12              
13             sub new {
14 1     1 0 1034 my ($class, %args) = @_;
15              
16 1         17 my $self = $class->SUPER::new(%args);
17              
18 1         4 foreach (qw( gas_price )) {
19 1 50       8 $self->{$_} = $args{$_} if exists $args{$_};
20             }
21              
22 1         4 bless $self, $class;
23 1         6 return $self;
24             }
25              
26             sub gas_price {
27 2     2 0 9 return shift->{gas_price};
28             }
29              
30             sub serialize {
31 2     2 1 7 my $self = shift;
32              
33 2         8 my @params = (
34             $self->nonce, #
35             $self->gas_price,
36             $self->gas_limit,
37             $self->to,
38             $self->value,
39             $self->data,
40             );
41              
42 2         31 @params = $self->_normalize_params(\@params)->@*;
43              
44 2 100 66     10 if ($self->v && $self->r && $self->s) {
      66        
45 1         3 push(@params, $self->v, $self->r, $self->s);
46             } else {
47 1         22 push(@params, $self->chain_id, '0x', '0x');
48             }
49              
50 2         9 return $self->rlp->encode(\@params);
51             }
52              
53             sub generate_v {
54 1     1 1 3 my ($self, $y_parity) = @_;
55              
56 1         3 my $v = sprintf("0x%x", (hex $self->chain_id) * 2 + 35 + $y_parity);
57              
58 1         5 $self->set_v($v);
59 1         2 return $v;
60             }
61              
62             1;
63              
64             __END__