HushList Protocol Whitepaper
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.
 
 
 

145 lines
3.4 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;
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 = sprintf "%.8f", $balance->{transparent};
my $zbalance = sprintf "%.8f", $balance->{private};
my $total_balance = $balance->{total};
my $blockchain = "HUSH";
print "Hushlist v$Hush::List::VERSION running on $blockchain ${chain}net, $blocks blocks\n";
print "Balances: transparent $tbalance HUSH, private $zbalance HUSH\n";
# we only need one
my $options = {};
my $list = Hush::List->new($rpc, $options);
my $command = shift || help();
my $COMMANDS = {
"add" => \&add,
"contact" => \&contact,
"help" => \&help,
"new" => \&new,
"remove" => \&remove,
"send" => \&send,
"show" => \&show,
"status" => \&status,
#"public" => \&public,
};
# TODO: translations
my %HELP = (
"add" => "Add a contact to a Hushlist",
"contact" => "Manage Hushlist contacts",
"help" => "Get your learn on",
"new" => "Create a new Hushlist",
"remove" => "Remove a Hushlist",
"send" => "Send a new new Hushlist memo",
"status" => "Get overview of Hushlists or a specific Hushlist",
"show" => "Show Hushlist memos",
#"public" => "Make a private Hushlist public",
);
run();
exit;
sub help {
print "Available Hushlist commands:\n";
my @cmds = sort keys %$COMMANDS;
for my $cmd (@cmds) {
print "\t$cmd\t: $HELP{$cmd}\n";
}
}
sub show {
}
sub usage {
print "Usage: $0 command [subcommand] [options]\n";
print "$0 help for more details :)\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;
}
}
# make a hushlist public by publishing its privkey in OP_RETURN data
# This operation costs HUSH!!!
sub publi {
my ($name) = @_;
$list->public($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 {
usage();
}
}
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,$memo) = @_;
$list->send_memo($rpc, $list_name, $memo);
}