Browse Source

Correctly die if we cannot talk to rpc server

master
Jonathan "Duke" Leto 7 years ago
parent
commit
2099be2006
  1. 4
      lib/Hush/List.pm
  2. 18
      lib/Hush/RPC.pm

4
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";

18
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;

Loading…
Cancel
Save