| 1 | package Finance::Dogechain::Block; | ||
| 2 | $Finance::Dogechain::Block::VERSION = '1.20210418.2306'; | ||
| 3 | use Mojo::Base -base, -signatures, 'Finance::Dogechain::Base'; | ||
| 4 | use Finance::Dogechain::Transaction; | ||
| 5 | |||
| 6 | has 'block_id'; | ||
| 7 | |||
| 8 | sub block($self) { | ||
| 9 | my $block = $self->return_field_if_success( '/block/' . $self->block_id, 'block' ); | ||
| 10 | say JSON->new->pretty->encode( $block ); | ||
| 11 | |||
| 12 | if ($block) { | ||
| 13 | $self->convert_transactions_in_place( $block->{txs} ); | ||
| 14 | } | ||
| 15 | |||
| 16 | return $block; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub convert_transactions_in_place($self, $txs) { | ||
| 20 | while (my ($i, $tx_id) = each @$txs) { | ||
| 21 | $txs->[$i] = Finance::Dogechain::Transaction->new( tx_id => $tx_id ); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | sub TO_JSON($self) { | ||
| 26 | return '[Finance::Dogechain::Block](block_id => ' . $self->block_id . ')'; | ||
| 27 | } | ||
| 28 | |||
| 29 | 'to the moon'; | ||
| 30 | __END__ |