Jonathan "Duke" Leto
7 years ago
commit
fc2ca015c6
3 changed files with 102 additions and 0 deletions
@ -0,0 +1,5 @@ |
|||||
|
package Hush; |
||||
|
use strict; |
||||
|
use warnings; |
||||
|
|
||||
|
1; |
@ -0,0 +1,63 @@ |
|||||
|
package Hush::List; |
||||
|
use strict; |
||||
|
use warnings; |
||||
|
use Hush::RPC; |
||||
|
use Try::Tiny; |
||||
|
|
||||
|
|
||||
|
#TODO: verify |
||||
|
my $MAX_RECIPIENTS = 55; |
||||
|
|
||||
|
#TODO: create this if not specified |
||||
|
my $ZADDR = $ENV{HUSH_LIST_ZADDR} || die 'No funding zaddr found'; |
||||
|
|
||||
|
sub new { |
||||
|
my $hush_list = {}; |
||||
|
$hush_list->{lists} = {}; |
||||
|
return bless $hush_list, 'Hush::List'; |
||||
|
} |
||||
|
|
||||
|
sub new_list { |
||||
|
my ($self,$name) = @_; |
||||
|
my $lists = $self->{lists}; |
||||
|
die "Hush list $name already exists" if $lists->{$name}; |
||||
|
$lists->{$name}++; |
||||
|
return $self; |
||||
|
} |
||||
|
|
||||
|
# send a message to a Hush List, weeeeee! |
||||
|
sub send_message { |
||||
|
my ($self,$from,$name,$message) = @_; |
||||
|
|
||||
|
# TODO: better validation |
||||
|
die "Invalid Hush list name" unless $name; |
||||
|
die "Hush message cannot be empty" unless $message; |
||||
|
die "Invalid Hush from address: $from" unless $from; |
||||
|
|
||||
|
my $hush_list = $self->{lists}->{$name} || die "No Hush List by the name of '$name' found"; |
||||
|
|
||||
|
my $rpc = Hush::RPC->new; |
||||
|
my $recipients = $hush_list->recipients; |
||||
|
|
||||
|
die "Max recipients of $MAX_RECIPIENTS exceeded" if (@$recipients > $MAX_RECIPIENTS); |
||||
|
|
||||
|
# prevent an easily searchable single xtn amount |
||||
|
my $amount = 1e-4 + (1e-5*rand()); |
||||
|
|
||||
|
# this could blow up for a bajillion reasons... |
||||
|
try { |
||||
|
$rpc->z_sendmany($from, $amount, $recipients, $memo); |
||||
|
} catch { |
||||
|
die "caught RPC error: $_"; |
||||
|
} finally { |
||||
|
# TODO: notekeeping, logging, etc.. |
||||
|
} |
||||
|
|
||||
|
return $self; |
||||
|
} |
||||
|
|
||||
|
sub new_taddr {} |
||||
|
sub new_zaddr {} |
||||
|
|
||||
|
|
||||
|
1; |
@ -0,0 +1,34 @@ |
|||||
|
package Hush::RPC; |
||||
|
use strict; |
||||
|
use warnings; |
||||
|
use Bitcoin::RPC::Client; |
||||
|
|
||||
|
sub new { |
||||
|
my $rpc = Bitcoin::RPC::Client->new( |
||||
|
user => $ENV{HUSH_RPC_USERNAME} || "hush", |
||||
|
password => $ENV{HUSH_RPC_PASSWORD} || "puppy", |
||||
|
host => "127.0.0.1", |
||||
|
); |
||||
|
return $rpc, |
||||
|
} |
||||
|
|
||||
|
__DATA__ |
||||
|
|
||||
|
my $chaininfo = $btc->getblockchaininfo; |
||||
|
my $blocks = $chaininfo->{blocks}; |
||||
|
|
||||
|
# Set the transaction fee |
||||
|
# https://bitcoin.org/en/developer-reference#settxfee |
||||
|
my $settx = $btc->settxfee($feerate); |
||||
|
|
||||
|
# Check your balance |
||||
|
# (JSON::Boolean objects must be passed as boolean parameters) |
||||
|
# https://bitcoin.org/en/developer-reference#getbalance |
||||
|
my $account = ''; |
||||
|
my $balance = $btc->getbalance($account, 1, JSON::true); |
||||
|
|
||||
|
# Send to an address |
||||
|
# https://bitcoin.org/en/developer-reference#sendtoaddress |
||||
|
my $txid = $rpc->sendtoaddress("1Ky49cu7FLcfVmuQEHLa1WjhRiqJU2jHxe","0.01"); |
||||
|
|
||||
|
1; |
Loading…
Reference in new issue