Hush/RPC.pm

filter: Statementstmt 44.1% 19 / 43 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 26.3% 25 / 95 CC 16 SCAR 52.9
CC
16
Cov
25%
new
272.0
BEGIN
1.0
BEGIN
1.0
CRAP 198.1
↑ Summary Hush/App.pm »
1 package Hush::RPC;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Bitcoin::RPC::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Hush::Util qw/barf/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Carp::Always;
8 1 ▶use URL::Encode qw/url_encode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub new {
Subroutine new: not called CC=16 SCAR=56.1
Pod undocumented
11 0 ▶ my $port = $ENV{HUSH_RPC_PORT} || 8822;
Condition0%0/2
$ENV{'HUSH_RPC_PORT'} || 8822
l!l
00
MC/DC0%0/1
$ENV{'HUSH_RPC_PORT'} || 8822
$ENV{'HUSH_RPC_PORT'}
Truth table0%0/2
A
A= $ENV{'HUSH_RPC_PORT'}
Aresult
11
00
12 0 ▶ my $host = $ENV{HUSH_RPC_HOST} || "127.0.0.1";
Condition0%0/2
$ENV{'HUSH_RPC_HOST'} || '127.0.0.1'
l!l
00
MC/DC0%0/1
$ENV{'HUSH_RPC_HOST'} || '127.0.0.1'
$ENV{'HUSH_RPC_HOST'}
Truth table0%0/2
A
A= $ENV{'HUSH_RPC_HOST'}
Aresult
11
00
13 0 my $HOME = $ENV{HOME};
14 0 my $config = catfile($HOME, qw/.hush hush.conf/);
15 0 my ($user,$password) = ('','');
16 0 ▶ if (-e $config) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $config) 0 0 0
17 0 ▶ open(my $fh, '<', $config) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $config or die $! 0 0 0
18 0 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
19 0 ▶ if (m!^rpcuser=(.*)$!) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^rpcuser=(.*)$/) { } 0 0 0
elsif (/^rpcpassword=(.*)$/) { } 0 0 0
20 0 $user = $1;
21 }elsif (m!^rpcpassword=(.*)$!) {
22 # default Hush instructions use base62
23 0 $password = url_encode($1);
24 }
25 0 ▶ last if ($user && $password);
Branch: 1 branch
BranchTrueFalseTotal
if $user and $password 0 0 0
Condition0%0/3
$user and $password
!ll&&!rl&&r
000
MC/DC0%0/2
$user and $password
$user $password
Truth table0%0/3
A and B
A= $userB= $password
ABresult
0X0
100
111
26 }
27 }
28  
29 my $rpc = Bitcoin::RPC::Client->new(
30 port => $port, # set this to 18822 to use testnet
31 host => $host,
32 user => $ENV{HUSH_RPC_USERNAME} || $user,
33 password => $ENV{HUSH_RPC_PASSWORD} || $password,
34 # rpc calls, how do they work?
35 debug => 1,
36 0 ▶ debug => $ENV{HUSH_DEBUG} || 0,
Condition0%0/8
$ENV{'HUSH_RPC_USERNAME'} || $user
l!l&&r!l&&!r
000
$ENV{'HUSH_RPC_PASSWORD'} || $password
l!l&&r!l&&!r
000
$ENV{'HUSH_DEBUG'} || 0
l!l
00
MC/DC0%0/2
$ENV{'HUSH_RPC_USERNAME'} || $user
$ENV{'HUSH_RPC_USERNAME'} $user
MC/DC0%0/2
$ENV{'HUSH_RPC_PASSWORD'} || $password
$ENV{'HUSH_RPC_PASSWORD'} $password
MC/DC0%0/1
$ENV{'HUSH_DEBUG'} || 0
$ENV{'HUSH_DEBUG'}
Truth table0%0/3
A || B
A= $ENV{'HUSH_RPC_USERNAME'}B= $user
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $ENV{'HUSH_RPC_PASSWORD'}B= $password
ABresult
1X1
011
000
Truth table0%0/2
A
A= $ENV{'HUSH_DEBUG'}
Aresult
11
00
37 );
38 0 my $info = $rpc->getinfo;
39 0 ▶ if ($info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) { } 0 0 0
40 0 return $rpc,
41 } else {
42 0 my $coins = {
43 8822 => 'HUSH',
44 18822 => 'TUSH',
45 7770 => 'KMD',
46 17770 => 'KMD-test',
47 8232 => 'ZEC',
48 18232 => 'TAZ',
49 1989 => 'BTCZ',
50 11989 => 'BTCZ-test',
51 };
52 0 my $sites = {
53 "HUSH" => 'https://myhush.org',
54 "TUSH" => 'https://myhush.org',
55 "KMD" => 'https://komodoplatform.com',
56 "ZEC" => 'https://z.cash',
57 "TAZ" => 'https://z.cash',
58 };
59 0 ▶ my $coin = $coins->{$port} || 'cryptocoin';
Condition0%0/2
$coins->{$port} || 'cryptocoin'
l!l
00
MC/DC0%0/1
$coins->{$port} || 'cryptocoin'
$coins->{$port}
Truth table0%0/2
A
A= $coins->{$port}
Aresult
11
00
60 0 ▶ my $site = $sites->{$coin} || 'https://github.com/leto/hushlist';
Condition0%0/2
$sites->{$coin} || 'https://github.com/leto/hushlist'
l!l
00
MC/DC0%0/1
$sites->{$coin} || 'https://github.com/leto/hushlist'
$sites->{$coin}
Truth table0%0/2
A
A= $sites->{$coin}
Aresult
11
00
61 0 print "Unable to make RPC connection to $coin full node at $host:$port !\n";
62 0 print "Your $coin full node is not running, or not accessible at that port :(\n";
63 0 print "See $site for more information about this privacy coin\n";
64 0 exit(1);
65 }
66 }
67  
68 1 1;
69  
70 __DATA__
↑ Summary Hush/App.pm »