Browse Source

Create Hush::Memo class and refactor find_memos to use z_listreceivedbyaddress which makes things super easier

master
Jonathan "Duke" Leto 7 years ago
parent
commit
c36850b262
  1. 3
      bin/hushlist
  2. 2
      lib/Hush/App.pm
  3. 27
      lib/Hush/List.pm
  4. 21
      lib/Hush/Memo.pm

3
bin/hushlist

@ -9,7 +9,6 @@ use Data::Dumper;
use Hush::RPC;
use Hush::App;
my $rpc = Hush::RPC->new;
my $command = shift || help();
my $command = shift;
Hush::App::run($command);
exit;

2
lib/Hush/App.pm

@ -51,7 +51,6 @@ sub show_status {
my $options = {};
my $list = Hush::List->new($rpc, $options);
my $command = shift || help();
sub run {
my ($command) = @_;
@ -134,3 +133,4 @@ sub new {
print "hushlist '$name' created, enjoy your private comms ;)\n";
}
1;

27
lib/Hush/List.pm

@ -177,30 +177,17 @@ sub show {
sub find_memos {
my ($name,$zaddr) = @_;
#List transactions 100 to 120
#> zcash-cli listtransactions "*" 20 100
# these seem to be an array from oldest to newest
my $max_xtns = 10000;
my @xtns = $rpc->listtransactions("*", $max_xtns, 0);
if (@xtns) {
my $num_xtns = @xtns;
debug("find_memos: found $num_xtns transactions for zaddr=$zaddr");
if (@xtns == $max_xtns) {
#TODO: get latest xtns if more than max
my @xtns = $rpc->listtransactions("*", $max_xtns, $max_xtns);
}
# reverse sort our found xtns by blocktime
@xtns = sort { $b->{blocktime} <=> $a->{blocktime} } @xtns;
# get a list of all xtn ids
my @txids = map { $_->{txid} } @xtns;
my @xtns = $rpc->z_listreceivedbyaddress($zaddr);
# TODO: grab memo field by using RPC method to get all xtn data
if (@xtns) {
# TODO: need local shielded balance to get data => need (t,z) xtn
my @memos = ();
# TODO: good datastructure for memo data
for my $xtn (@xtns) {
printf "txid=%s memo=%s\n", $xtn->{txid}, $xtn->{memo};
}
return @memos;
} else {
debug("find_memos: No memos found for $name + $zaddr");

21
lib/Hush/Memo.pm

@ -0,0 +1,21 @@
package Hush::Memo;
use strict;
use warnings;
use Try::Tiny;
use Hush::Util qw/barf/;
use Hush::Logger qw/debug/;
use Data::Dumper;
use JSON;
sub new {
my ($rpc,$options) = @_;
my $memo = {
txid => 0,
amount => 0.00,
memo => "",
};
return bless $memo, 'Hush::Memo';
}
1;
Loading…
Cancel
Save