You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.5 KiB
114 lines
2.5 KiB
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
use Try::Tiny;
|
|
use lib 'lib';
|
|
use Hush::List;
|
|
use Hush::Util qw/barf/;
|
|
use Data::Dumper;
|
|
use Hush::RPC; #hack
|
|
|
|
my $rpc = Hush::RPC->new;
|
|
my $chaininfo = $rpc->getblockchaininfo;
|
|
my $walletinfo = $rpc->getwalletinfo;
|
|
my $chain = $chaininfo->{chain};
|
|
my $blocks = $chaininfo->{blocks};
|
|
my $balance = $rpc->z_gettotalbalance;
|
|
my $tbalance = $balance->{transparent};
|
|
my $zbalance = $balance->{private};
|
|
my $total_balance = $balance->{total};
|
|
my $blockchain = "HUSH";
|
|
|
|
print "Hushlist running on $blockchain ${chain}net, $blocks blocks\n";
|
|
print "Balances: transparent $tbalance HUSH, private $zbalance HUSH\n";
|
|
|
|
# we only need one
|
|
my $list = Hush::List->new;
|
|
my $command = shift || help();
|
|
my $COMMANDS = {
|
|
"add" => \&add,
|
|
"contact" => \&contact,
|
|
"new" => \&new,
|
|
"remove" => \&remove,
|
|
"send" => \&send,
|
|
"status" => \&status,
|
|
"public" => \&public,
|
|
};
|
|
run();
|
|
exit;
|
|
|
|
sub help {
|
|
print "It would be nice to give some help\n";
|
|
}
|
|
|
|
sub contact {
|
|
my $cmd = shift || '';
|
|
my $subcommands = {
|
|
"add" => sub {
|
|
# add a hush contact, yay
|
|
my ($cmd,$name,$zaddr) = @ARGV;
|
|
barf Dumper [ $cmd, $name, $zaddr ];
|
|
},
|
|
"rm" => sub {
|
|
my ($cmd,$name,$zaddr) = @ARGV;
|
|
barf Dumper [ $cmd, $name, $zaddr ];
|
|
},
|
|
};
|
|
my $subcmd = $subcommands->{$cmd};
|
|
if ($subcmd) {
|
|
$subcmd->();
|
|
} else {
|
|
barf "Invalid hushlist contact subcommand!";
|
|
}
|
|
}
|
|
|
|
sub status {
|
|
my $name = shift;
|
|
if ($name) {
|
|
my $status = $list->status($name);
|
|
} else {
|
|
my $status = $list->global_status;
|
|
}
|
|
}
|
|
|
|
sub public {
|
|
my ($name) = @_;
|
|
}
|
|
|
|
sub new {
|
|
my $name = shift || '';
|
|
#TODO: better validation and allow safe unicode stuff
|
|
barf "Invalid hushlist name '$name' !" unless $name && ($name =~ m/^[A-z0-9_-]{0,64}/);
|
|
|
|
$list->new_list($name);
|
|
print "hushlist '$name' created, enjoy your private comms ;)\n";
|
|
}
|
|
|
|
sub run {
|
|
#print "Running command $command\n";
|
|
my $cmd = $COMMANDS->{$command};
|
|
|
|
if ($cmd) {
|
|
$cmd->(@ARGV);
|
|
} else {
|
|
help();
|
|
}
|
|
}
|
|
|
|
sub add {
|
|
my ($list_name,$zaddr) = @_;
|
|
|
|
$list->add_zaddr($list_name,$zaddr);
|
|
}
|
|
|
|
sub remove {
|
|
my ($list_name,$zaddr) = @_;
|
|
|
|
$list->remove_zaddr($list_name,$zaddr);
|
|
}
|
|
|
|
sub send {
|
|
my ($list_name,$from,$memo) = @_;
|
|
|
|
$list->send_message($from, $list_name, $memo);
|
|
}
|
|
|