| 1 | package Circle::Block; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.006; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Exporter 'import'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Try::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 0 | ▶ | use URL::Encode; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use Circle::Common qw(load_config build_url_template http_json_post http_json_get); | ||
| 11 | |||
| 12 | our $VERSION = '0.05'; | ||
| 13 | |||
| 14 | our @EXPORT = qw( | ||
| 15 | get_block_hashlist | ||
| 16 | get_block | ||
| 17 | get_block_header_list | ||
| 18 | get_block_data | ||
| 19 | get_blocktails_hashlist | ||
| 20 | get_blocktails_po | ||
| 21 | get_tx_by_txid | ||
| 22 | search_tx_by_txid | ||
| 23 | search_tx_by_address | ||
| 24 | search_utxos | ||
| 25 | ); | ||
| 26 | |||
| 27 | sub _build_url_template { | ||
| 28 | my ($path, $params_for) = @_; | ||
| 29 | return build_url_template( "block", $path, $params_for ); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub get_block_hashlist { | ||
| 33 | my ($base_height) = @_; | ||
| 34 | my $url = _build_url_template( | ||
| 35 | "blockchainHashListPath", | ||
| 36 | { | ||
| 37 | baseHeight => $base_height | ||
| 38 | } | ||
| 39 | ); | ||
| 40 | carp 'url: ' . $url; | ||
| 41 | return http_json_get($url, 0); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub get_block { | ||
| 45 | my ($hash) = @_; | ||
| 46 | my $url = _build_url_template( | ||
| 47 | "blockchainPath", | ||
| 48 | { | ||
| 49 | hash => $hash | ||
| 50 | } | ||
| 51 | ); | ||
| 52 | return http_json_get($url); | ||
| 53 | } | ||
| 54 | |||
| 55 | sub get_block_header_list { | ||
| 56 | my ($base_height) = @_; | ||
| 57 | my $url = _build_url_template( | ||
| 58 | "blockchainHeaderListPath", | ||
| 59 | { | ||
| 60 | baseHeight => $base_height | ||
| 61 | } | ||
| 62 | ); | ||
| 63 | return http_json_get($url, 0); | ||
| 64 | } | ||
| 65 | |||
| 66 | sub get_block_data { | ||
| 67 | my ($hash) = @_; | ||
| 68 | my $url = _build_url_template( | ||
| 69 | "blockchainDataPath", | ||
| 70 | { | ||
| 71 | hash => $hash | ||
| 72 | } | ||
| 73 | ); | ||
| 74 | return http_json_get($url); | ||
| 75 | } | ||
| 76 | |||
| 77 | sub get_blocktails_hashlist { | ||
| 78 | my ($base_height) = @_; | ||
| 79 | my $url = _build_url_template( | ||
| 80 | "blockchainTailsHashListPath", | ||
| 81 | { | ||
| 82 | baseHeight => $base_height | ||
| 83 | } | ||
| 84 | ); | ||
| 85 | return http_json_get($url, 0); | ||
| 86 | } | ||
| 87 | |||
| 88 | sub get_blocktails_po { | ||
| 89 | my ($hash) = @_; | ||
| 90 | my $url = _build_url_template( | ||
| 91 | "blockchainTailsPOPath", | ||
| 92 | { | ||
| 93 | hash => $hash | ||
| 94 | } | ||
| 95 | ); | ||
| 96 | return http_json_get($url, 0); | ||
| 97 | } | ||
| 98 | |||
| 99 | sub get_tx_by_txid { | ||
| 100 | my ($txid) = @_; | ||
| 101 | my $url = _build_url_template( | ||
| 102 | "transactionByTxIdPath", | ||
| 103 | { | ||
| 104 | txId => $txid | ||
| 105 | } | ||
| 106 | ); | ||
| 107 | return http_json_get($url, 0); | ||
| 108 | } | ||
| 109 | |||
| 110 | sub search_tx_by_txid { | ||
| 111 | my ($txid) = @_; | ||
| 112 | my $url = _build_url_template( | ||
| 113 | "searchTxByTxIdPath", | ||
| 114 | { | ||
| 115 | txId => $txid | ||
| 116 | } | ||
| 117 | ); | ||
| 118 | return http_json_get($url, 0); | ||
| 119 | } | ||
| 120 | |||
| 121 | sub search_tx_by_address { | ||
| 122 | my ( $address, $min_output_key, $limit ) = @_; | ||
| 123 | $min_output_key //= ''; | ||
| 124 | $limit //= 10; | ||
| 125 | my $url = _build_url_template( | ||
| 126 | "searchTxByAddressPath", | ||
| 127 | { | ||
| 128 | address => $address, | ||
| 129 | minOutputKey => $min_output_key, | ||
| 130 | limit => $limit | ||
| 131 | } | ||
| 132 | ); | ||
| 133 | return http_json_get($url, 0); | ||
| 134 | } | ||
| 135 | |||
| 136 | sub search_utxos { | ||
| 137 | my ( $address, $min_output_key, $limit ) = @_; | ||
| 138 | $min_output_key //= ''; | ||
| 139 | $limit //= 10; | ||
| 140 | my $url = _build_url_template( | ||
| 141 | "searchUTXOsPath", | ||
| 142 | { | ||
| 143 | address => $address, | ||
| 144 | minOutputKey => $min_output_key, | ||
| 145 | limit => $limit | ||
| 146 | } | ||
| 147 | ); | ||
| 148 | return http_json_get($url, 0 ); | ||
| 149 | } | ||
| 150 | |||
| 151 | 1; | ||
| 152 | |||
| 153 | __END__ | ||