| 1 | package Net::Async::Blockchain; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | our $VERSION = '0.002'; | |||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Net::Async::Blockchain - base for blockchain subscription clients. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | Objects of this type would not normally be constructed directly. | ||||||||||
| 15 | |||||||||||
| 16 | For blockchain clients see: | ||||||||||
| 17 | - Net::Async::Blockchain::BTC | ||||||||||
| 18 | - Net::Async::BLockchain::ETH | ||||||||||
| 19 | |||||||||||
| 20 | Which will use this class as base. | ||||||||||
| 21 | |||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||
| 23 | |||||||||||
| 24 | This module contains methods that are shared by the subscription clients. | ||||||||||
| 25 | |||||||||||
| 26 | =over 4 | ||||||||||
| 27 | |||||||||||
| 28 | =back | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 3 | ▶ | no indirect; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 3 | ▶ | use parent qw(IO::Async::Notifier); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | 1 | ▶ | sub subscription_url : method { shift->{subscription_url} } | ||||||||
|
Subroutine
subscription_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 0 | ▶ | sub subscription_timeout : method { shift->{subscription_timeout} } | ||||||||
|
Subroutine
subscription_timeout: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 38 | 0 | ▶ | sub subscription_msg_timeout : method { shift->{subscription_msg_timeout} } | ||||||||
|
Subroutine
subscription_msg_timeout: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 39 | 1 | ▶ | sub blockchain_code { shift->{blockchain_code} } | ||||||||
|
Subroutine
blockchain_code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | |||||||||||
| 41 | =head2 configure | ||||||||||
| 42 | |||||||||||
| 43 | Any additional configuration that is not described on L<IO::Async::Notifier> | ||||||||||
| 44 | must be included and removed here. | ||||||||||
| 45 | |||||||||||
| 46 | =over 4 | ||||||||||
| 47 | |||||||||||
| 48 | =item * C<subscription_url> Subscription URL it can be TCP for ZMQ and WS for the Websocket subscription | ||||||||||
| 49 | =item * C<subscription_timeout> Subscription connection timeout | ||||||||||
| 50 | =item * C<subscription_msg_timeout> Subscription interval between messages timeout | ||||||||||
| 51 | =item * C<blockchain_code> The blockchain code (eg: bitcoin, litecoin, ....) | ||||||||||
| 52 | |||||||||||
| 53 | =back | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | sub configure { | ||||||||||
| 58 | 2 | ▶ | my ($self, %params) = @_; | ||||||||
|
Subroutine
configure: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 59 | |||||||||||
| 60 | 2 | for my $k (qw(subscription_url subscription_timeout subscription_msg_timeout blockchain_code)) { | |||||||||
| 61 | 8 | ▶ | $self->{$k} = delete $params{$k} if exists $params{$k}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 2 | $self->SUPER::configure(%params); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | =head2 subscription_response | ||||||||||
| 68 | |||||||||||
| 69 | Formate the subscription response message | ||||||||||
| 70 | |||||||||||
| 71 | =over 4 | ||||||||||
| 72 | |||||||||||
| 73 | =item * C<$subscription_type> - A string of the subscription type (e.g: blocks) | ||||||||||
| 74 | |||||||||||
| 75 | =item * C<$messgae> - The recevied subscription message from the blockchain node | ||||||||||
| 76 | |||||||||||
| 77 | =back | ||||||||||
| 78 | |||||||||||
| 79 | Returns a hash reference of: | ||||||||||
| 80 | |||||||||||
| 81 | =over 4 | ||||||||||
| 82 | |||||||||||
| 83 | =item * C<blockchain_code> - A string of the blockchain code (eg: bitcoin, litecoin, ....) | ||||||||||
| 84 | |||||||||||
| 85 | =item * C<subscription_type> - A string of the subscription type (e.g: blocks) | ||||||||||
| 86 | |||||||||||
| 87 | =item * C<message> - The recevied subscription message from the blockchain node | ||||||||||
| 88 | |||||||||||
| 89 | =back | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | sub subscription_response { | ||||||||||
| 94 | 1 | ▶ | my ($self, $subscription_type, $messgae) = @_; | ||||||||
|
Subroutine
subscription_response: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 95 | return { | ||||||||||
| 96 | 1 | blockchain_code => $self->blockchain_code, | |||||||||
| 97 | subscription_type => $subscription_type, | ||||||||||
| 98 | message => $messgae, | ||||||||||
| 99 | }; | ||||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 3 | 1; | |||||||||