File Coverage

blib/lib/Blockchain/Ethereum/Transaction/EIP1559.pm
Criterion Covered Total %
statement 28 28 100.0
branch 3 4 75.0
condition 6 8 75.0
subroutine 10 10 100.0
pod 1 5 20.0
total 48 55 87.2


line stmt bran cond sub pod time code
1             package Blockchain::Ethereum::Transaction::EIP1559;
2              
3 3     3   441049 use v5.26;
  3         11  
4 3     3   13 use strict;
  3         5  
  3         94  
5 3     3   16 use warnings;
  3         9  
  3         289  
6              
7             # ABSTRACT: Ethereum Fee Market transaction abstraction (EIP-1559)
8             our $AUTHORITY = 'cpan:REFECO'; # AUTHORITY
9             our $VERSION = '0.021'; # VERSION
10              
11 3     3   863 use parent 'Blockchain::Ethereum::Transaction';
  3         562  
  3         22  
12              
13 3     3   224 use constant TRANSACTION_PREFIX => pack("H*", '02');
  3         7  
  3         875  
14              
15             sub new {
16 6     6 0 545222 my ($class, %args) = @_;
17              
18 6         65 my $self = $class->SUPER::new(%args);
19              
20 6         27 foreach (qw( max_priority_fee_per_gas max_fee_per_gas access_list )) {
21 18 100       64 $self->{$_} = $args{$_} if exists $args{$_};
22             }
23              
24 6         19 bless $self, $class;
25 6         30 return $self;
26              
27             }
28              
29             sub max_priority_fee_per_gas {
30 8     8 0 30 return shift->{max_priority_fee_per_gas};
31             }
32              
33             sub max_fee_per_gas {
34 8     8 0 36 return shift->{max_fee_per_gas};
35             }
36              
37             sub access_list {
38 9   100 9 0 49 return shift->{access_list} // [];
39             }
40              
41             sub serialize {
42 8     8 1 39 my $self = shift;
43              
44 8         46 my @params = (
45             $self->chain_id, #
46             $self->nonce,
47             $self->max_priority_fee_per_gas,
48             $self->max_fee_per_gas,
49             $self->gas_limit,
50             $self->to,
51             $self->value,
52             $self->data,
53             $self->_encode_access_list,
54             );
55              
56 8         40 @params = $self->_normalize_params(\@params)->@*;
57              
58 8 50 66     51 push(@params, $self->v, $self->r, $self->s)
      66        
59             if $self->v && $self->r && $self->s;
60              
61             # eip-1559 transactions must be prefixed by 2 that is the
62             # transaction type
63 8         84 return TRANSACTION_PREFIX . $self->rlp->encode(\@params);
64             }
65              
66             1;
67              
68             __END__