Client.pm

filter: Statementstmt 82.5% 33 / 40 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 1 / 1 totaltotal 77.9% 46 / 59 CC 5 SCAR 11.5
CC
5
Cov
75%
AUTOLOAD
6.9
contract
2.0
BEGIN
1.0
CRAP 3.2
« Contract/ContractResponse.pm ↑ Summary Contract/Helper/UnitConversion.pm »
1 package Ethereum::RPC::Client;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Ethereum::RPC::Contract;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '0.02';
12  
13 has host => (
14 is => 'ro',
15 3 ▶ default => sub { '127.0.0.1' });
Subroutine __ANON__: called CC=1 SCAR=0.0
16 5 has port => (
17 is => "ro",
18 default => 8545
19 );
20 has http_client => (
21 is => 'ro',
22 3 ▶ default => sub { Mojo::UserAgent->new });
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 ## no critic (RequireArgUnpacking)
25 sub AUTOLOAD {
26 6 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=5 SCAR=19.3
27  
28 6 my $method = $Ethereum::RPC::Client::AUTOLOAD;
29 6 $method =~ s/.*:://;
30  
31 6 ▶ return if ($method eq 'DESTROY');
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "DESTROY" 3 3 6
32  
33 3 my $url = "http://" . $self->host . ":" . $self->port;
34  
35 3 $self->{id} = 1;
36 my $obj = {
37 3 ▶ id => $self->{id}++,
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 3 3
38 method => $method,
39 params => (ref $_[0] ? $_[0] : [@_]),
40 jsonrpc => "2.0"
41 };
42  
43 3 my $res = $self->http_client->post($url => json => $obj)->result;
44  
45 0 ▶ return $res->json->{result} unless $res->is_error;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_error 0 0 0
46 0 ▶ return $res->message if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
47 0 return undef;
48  
49 }
50  
51 =head2 contract
52  
53 Creates a new contract instance
54  
55 Parameters:
56 contract_address ( Optional - only if the contract already exists ),
57 contract_abi ( Required - https://solidity.readthedocs.io/en/develop/abi-spec.html ),
58 from ( Optional - Address )
59 gas ( Optional - Integer gas )
60 gas_price ( Optional - Integer gasPrice )
61  
62 Return:
63 New contract instance
64  
65 =cut
66  
67 sub contract {
68 0 ▶ my $self = shift;
Subroutine contract: not called CC=1 SCAR=6.9
Pod documented
69 0 my $params = shift;
70 0 return Ethereum::RPC::Contract->new((%{$params}, rpc_client => $self));
71 }
72  
73 5 1;
74  
75 =pod
76  
77 =head1 NAME
78  
79 Ethereum::RPC::Client - Ethereum JSON-RPC Client
80  
81 =head1 SYNOPSIS
82  
83 use Ethereum::RPC::Client;
84  
85 # Create Ethereum::RPC::Client object
86 my $eth = Ethereum::RPC::Client->new(
87 host => "127.0.0.1",
88 );
89  
90 my $web3_clientVersion = $eth->web3_clientVersion;
91  
92 # https://github.com/ethereum/wiki/wiki/JSON-RPC
93  
94 =head1 DESCRIPTION
95  
96 This module implements in PERL the JSON-RPC of Ethereum L<https://github.com/ethereum/wiki/wiki/JSON-RPC>
97  
98 =head1 SEE ALSO
99  
100 L<Bitcoin::RPC::Client>
101  
102 =head1 AUTHOR
103  
104 Binary.com E<lt>fayland@binary.comE<gt>
105  
106 =head1 COPYRIGHT
107  
108 Copyright 2017- Binary.com
109  
110 =head1 LICENSE
111  
112 This library is free software; you can redistribute it and/or modify
113 it under the same terms as Perl itself.
114  
115 =cut
« Contract/ContractResponse.pm ↑ Summary Contract/Helper/UnitConversion.pm »