From 2099be2006d1ea7113ab494e5afeaf5f0183d29f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Nov 2017 21:23:47 -0800 Subject: [PATCH] Correctly die if we cannot talk to rpc server --- lib/Hush/List.pm | 4 +++- lib/Hush/RPC.pm | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/Hush/List.pm b/lib/Hush/List.pm index 672ad27..6994b58 100644 --- a/lib/Hush/List.pm +++ b/lib/Hush/List.pm @@ -52,7 +52,6 @@ sub _sanity_checks { sub create_default_conf { my ($list_conf) = @_; - my $time = time; # when we create a brand new conf, we create brand new funding+nym addrs my $rpc = Hush::RPC->new; @@ -62,6 +61,9 @@ sub create_default_conf { my $pseudonym_taddr = $rpc->getnewaddress; die "Unable to create pseudonym taddr" unless $pseudonym_taddr; + warn "funding=$funding_zaddr, nym=$pseudonym_taddr"; + + my $time = time; open my $fh, ">", $list_conf or die "Could not write file $list_conf ! : $!"; print $fh "# hushlist config v$Hush::List::VERSION\n"; print $fh "funding_zaddr=$funding_zaddr\n"; diff --git a/lib/Hush/RPC.pm b/lib/Hush/RPC.pm index e94d2c1..6528618 100644 --- a/lib/Hush/RPC.pm +++ b/lib/Hush/RPC.pm @@ -2,16 +2,24 @@ package Hush::RPC; use strict; use warnings; use Bitcoin::RPC::Client; +use Hush::Util qw/barf/; sub new { + my $port = $ENV{HUSH_RPC_PORT} || 8822; + my $host = "127.0.0.1"; + my $rpc = Bitcoin::RPC::Client->new( + port => $port, # set this to 18822 to use testnet + host => $host, user => $ENV{HUSH_RPC_USERNAME} || "hush", - password => $ENV{HUSH_RPC_PASSWORD} || "puppy", - host => "127.0.0.1", - # set this to 18822 to use testnet - port => $ENV{HUSH_RPC_PORT} || 8822, + password => $ENV{HUSH_RPC_PASSWORD} || "hushmegently", ); - return $rpc, + my $info = $rpc->getinfo; + if ($info) { + return $rpc, + } else { + barf "Unable to make RPC connection to $host:$port !"; + } } 1;