The objective of this piece of code is to get a message from a cryptocurrency daemon through RPC and extract the transactions object to pass it to the view. Is there a simpler / less ugly way of doing this?
$transaction_pool = json_decode($rpc->getTransactionPool(), false);
if(isset($transaction_pool->transactions)){
$transaction_pool = $transaction_pool->transactions;
}else{
$transaction_pool = (object)NULL;
}
View partial:
@forelse ($transaction_pool as $transaction)
<?php $transaction_json = json_decode($transaction->tx_json); ?>
<div class="row show-grid top-row">
<div class="col-xs-12 col-sm-12 col-md-7">{{ $transaction->id_hash }}</div>
<div class="col-xs-12 col-sm-7 col-md-5 pull-right">
@if ($transaction_json->version == 2)
<div class="col-xs-7 col-md-6"><i class="fa fa-envelope-o"></i> confidential</div>
@else
<div class="col-xs-7 col-md-6">@coin($transaction_json->amount)</div>
@endif
<div class="col-xs-5 col-md-6">@coin($transaction->fee)</div>
</div>
</div>
@empty
<div class="row show-grid top-row">
<div class="col-xs-12">No transactions</div>
</div>
@endforelse
<div class="panel-heading large">
Transactions ({{ count($transaction_pool) }})
</div>