File Coverage

blib/lib/Finance/Bitcoin/Address.pm
Criterion Covered Total %
statement 17 23 73.9
branch 0 2 0.0
condition 0 2 0.0
subroutine 6 8 75.0
pod 2 2 100.0
total 25 37 67.5


line stmt bran cond sub pod time code
1             package Finance::Bitcoin::Address;
2              
3             BEGIN {
4 1     1   2 $Finance::Bitcoin::Address::AUTHORITY = 'cpan:TOBYINK';
5 1         21 $Finance::Bitcoin::Address::VERSION = '0.902';
6             }
7              
8 1     1   27 use 5.010;
  1         9  
  1         34  
9 1     1   5 use Moo;
  1         2  
  1         6  
10 1     1   326 use Carp;
  1         3  
  1         70  
11 1     1   6 use Finance::Bitcoin;
  1         1  
  1         29  
12 1     1   5 use Scalar::Util qw( blessed );
  1         3  
  1         570  
13              
14             with "Finance::Bitcoin::Role::HasAPI";
15              
16             has address => (is => "ro");
17              
18             sub label
19             {
20 0     0 1   my $self = shift;
21 0 0         $self->api->call(setlabel => $self->address, @_) if @_;
22 0           return $self->api->call(getlabel => $self->address);
23             }
24              
25             sub received
26             {
27 0     0 1   my $self = shift;
28 0           my ($minconf) = @_;
29 0   0       return $self->api->call(getreceivedbyaddress => $self->address, ($minconf//1));
30             }
31              
32             1;
33              
34             __END__
35              
36             =head1 NAME
37              
38             Finance::Bitcoin::Address - a bitcoin address
39              
40             =head1 SYNOPSIS
41              
42             use Finance::Bitcoin;
43            
44             my $uri = 'http://user:password@127.0.0.1:8332/';
45             my $wallet = Finance::Bitcoin::Wallet->new($uri);
46            
47             foreach my $address ($wallet->addresses)
48             {
49             print $address->address . "\n";
50             print $address->label . "\n";
51             print $address->received . "\n\n";
52             }
53              
54             =head1 DESCRIPTION
55              
56             This module is part of the high-level API for accessing a running
57             Bitcoin instance.
58              
59             =over 4
60              
61             =item C<< new($endpoint, $string) >>
62              
63             Constructor. $endpoint may be the JSON RPC endpoint URL, or may be a
64             Finance::Bitcoin::API object; $string is an address string.
65              
66             =begin trustme
67              
68             =item BUILDARGS
69              
70             =end trustme
71              
72             =item C<< address >>
73              
74             Returns the address string.
75              
76             =item C<< label >>
77              
78             Get/set the address label.
79              
80             =item C<< received($minconf) >>
81              
82             Returns the total amount received via this address, with at least $minconf
83             confirmations. $minconf defaults to 1.
84              
85             =item C<< api >>
86              
87             Retrieve a reference to the L<Finance::Bitcoin::API> object being used.
88              
89             =back
90              
91             =head1 BUGS
92              
93             Please report any bugs to L<http://rt.cpan.org/>.
94              
95             =head1 SEE ALSO
96              
97             L<Finance::Bitcoin>, L<Finance::Bitcoin::Wallet>.
98              
99             L<http://www.bitcoin.org/>.
100              
101             =head1 AUTHOR
102              
103             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
104              
105             =head1 COPYRIGHT
106              
107             Copyright 2010, 2011, 2013, 2014 Toby Inkster
108              
109             This library is free software; you can redistribute it and/or modify it
110             under the same terms as Perl itself.
111              
112             =head1 DISCLAIMER OF WARRANTIES
113              
114             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
115             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
116             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.