line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ethereum::RPC::Client; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
358703
|
use strict; |
|
4
|
|
|
|
|
44
|
|
|
4
|
|
|
|
|
114
|
|
4
|
4
|
|
|
4
|
|
26
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
105
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2210
|
use Moo; |
|
4
|
|
|
|
|
46402
|
|
|
4
|
|
|
|
|
18
|
|
7
|
4
|
|
|
4
|
|
7710
|
use JSON::MaybeXS; |
|
4
|
|
|
|
|
22070
|
|
|
4
|
|
|
|
|
244
|
|
8
|
4
|
|
|
4
|
|
2224
|
use Mojo::UserAgent; |
|
4
|
|
|
|
|
1830261
|
|
|
4
|
|
|
|
|
37
|
|
9
|
4
|
|
|
4
|
|
2484
|
use Ethereum::RPC::Contract; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
1744
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has host => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
default => sub { '127.0.0.1' }); |
16
|
|
|
|
|
|
|
has port => ( |
17
|
|
|
|
|
|
|
is => "ro", |
18
|
|
|
|
|
|
|
default => 8545 |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
has http_client => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
default => sub { Mojo::UserAgent->new }); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
## no critic (RequireArgUnpacking) |
25
|
|
|
|
|
|
|
sub AUTOLOAD { |
26
|
0
|
|
|
0
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $method = $Ethereum::RPC::Client::AUTOLOAD; |
29
|
0
|
|
|
|
|
|
$method =~ s/.*:://; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
return if ($method eq 'DESTROY'); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $url = "http://" . $self->host . ":" . $self->port; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$self->{id} = 1; |
36
|
|
|
|
|
|
|
my $obj = { |
37
|
0
|
0
|
|
|
|
|
id => $self->{id}++, |
38
|
|
|
|
|
|
|
method => $method, |
39
|
|
|
|
|
|
|
params => (ref $_[0] ? $_[0] : [@_]), |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $res = $self->http_client->post($url => json => $obj)->result; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal |
45
|
|
|
|
|
|
|
die sprintf("error code: %d, error message: %s (%s)\n", $res->json->{error}->{code}, $res->json->{error}->{message}, $method) |
46
|
0
|
0
|
|
|
|
|
if ($res->json->{error}->{message}); |
47
|
0
|
|
|
|
|
|
return $res->json->{result}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 contract |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Creates a new contract instance |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Parameters: |
55
|
|
|
|
|
|
|
contract_address ( Optional - only if the contract already exists ), |
56
|
|
|
|
|
|
|
contract_abi ( Required - https://solidity.readthedocs.io/en/develop/abi-spec.html ), |
57
|
|
|
|
|
|
|
from ( Optional - Address ) |
58
|
|
|
|
|
|
|
gas ( Optional - Integer gas ) |
59
|
|
|
|
|
|
|
gas_price ( Optional - Integer gasPrice ) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Return: |
62
|
|
|
|
|
|
|
New contract instance |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub contract { |
67
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
my $params = shift; |
69
|
0
|
|
|
|
|
|
return Ethereum::RPC::Contract->new((%{$params}, rpc_client => $self)); |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Ethereum::RPC::Client - Ethereum JSON-RPC Client |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Ethereum::RPC::Client; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Create Ethereum::RPC::Client object |
85
|
|
|
|
|
|
|
my $eth = Ethereum::RPC::Client->new( |
86
|
|
|
|
|
|
|
host => "127.0.0.1", |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $web3_clientVersion = $eth->web3_clientVersion; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# https://github.com/ethereum/wiki/wiki/JSON-RPC |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This module implements in PERL the JSON-RPC of Ethereum L |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Binary.com Efayland@binary.comE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 COPYRIGHT |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright 2017- Binary.com |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
112
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |