Client.pm

filter: Statementstmt 58.9% 23 / 39 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 1 / 1 totaltotal 53.5% 30 / 56 CC 4 SCAR 19.4
CC
4
Cov
51%
AUTOLOAD
20.0
contract
2.0
__ANON__
1.1
CRAP 6.9
« Contract/ContractTransaction.pm ↑ Summary Contract/ContractResponse.pm »
1 package Ethereum::RPC::Client;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Ethereum::RPC::Contract;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 our $VERSION = '0.05';
12  
13 has host => (
14 is => 'ro',
15 0 ▶ default => sub { '127.0.0.1' });
Subroutine __ANON__: not called CC=1 SCAR=1.2
16 6 has port => (
17 is => "ro",
18 default => 8545
19 );
20 has http_client => (
21 is => 'ro',
22 0 ▶ default => sub { Mojo::UserAgent->new });
Subroutine __ANON__: not called CC=1 SCAR=1.2
23  
24 ## no critic (RequireArgUnpacking)
25 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
26 0 my $self = shift;
27  
28 0 my $method = $Ethereum::RPC::Client::AUTOLOAD;
29 0 $method =~ s/.*:://;
30  
31 0 ▶ return if ($method eq 'DESTROY');
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "DESTROY" 0 0 0
32  
33 0 my $url = "http://" . $self->host . ":" . $self->port;
34  
35 0 $self->{id} = 1;
36 my $obj = {
37 0 ▶ id => $self->{id}++,
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
38 method => $method,
39 jsonrpc => '2.0',
40 params => (ref $_[0] ? $_[0] : [@_]),
41 };
42  
43 0 my $res = $self->http_client->post($url => json => $obj)->result;
44  
45 # https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal
46 die sprintf("error code: %d, error message: %s (%s)\n", $res->json->{error}->{code}, $res->json->{error}->{message}, $method)
47 0 ▶ if ($res->json->{error}->{message});
Branch: 1 branch
BranchTrueFalseTotal
if $res->json->{"error"}{"message"} 0 0 0
48 0 return $res->json->{result};
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 0 ▶sub contract {
Subroutine contract: not called CC=1 SCAR=6.9
Pod documented
68 0 my $self = shift;
69 0 my $params = shift;
70 0 return Ethereum::RPC::Contract->new((%{$params}, rpc_client => $self));
71 }
72  
73 6 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/ContractTransaction.pm ↑ Summary Contract/ContractResponse.pm »