• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marscoin / martianrepublic / 23751722506

30 Mar 2026 03:03PM UTC coverage: 8.391% (-0.01%) from 8.401%
23751722506

push

github

Martian Congress
refactor: Sprint 2 — architecture cleanup (A3, A4, A7, A9)

A3: Added $fillable to 7 models (Proposals, Vote, Threads, HDWallet,
    IPFSRoot, Publication, Voucher) — closes mass assignment risk

A4: Created config/blockchain.php centralizing all hardcoded URLs
    (RPC, Pebas, IPFS, Explorer, Ballot, Price). Updated 7 files
    to use config() instead of hardcoded strings.

A7: Removed dead code:
    - Deleted ApiController.php.bak, AppHelper.php.bak
    - Deleted unused models: Pkimport.php, Recovery.php
    - Deleted resources/views/wallet/testing.html
    - Removed 8 commented-out routes from web.php and api.php

A9: Added performance indexes migration:
    - proposals.status (phase sync, tab filtering)
    - ballots.userid, ballots.proposalid, ballots(userid,status)
    - votes.proposal_id (vote tallying)
    - forum_posts.author_id, forum_threads.author_id (joins)

A1 (controller split) deferred to dedicated session — too much
in-page JS coupling to batch safely.

79 tests passing, 0 PHPStan errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

2 of 48 new or added lines in 7 files covered. (4.17%)

2 existing lines in 2 files now uncovered.

445 of 5303 relevant lines covered (8.39%)

1.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Http/Controllers/StatusController.php
1
<?php
2
namespace App\Http\Controllers;
3

4
use Illuminate\Http\Request;
5
use Illuminate\Http\Response;
6
use Illuminate\Support\Facades\Auth;
7
use App\Includes\jsonRPCClient;
8
use App\Includes\AppHelper;
9
use Illuminate\Support\Facades\View;
10
use Illuminate\Support\Facades\DB;
11
use Carbon\Carbon;
12
use Exception;
13
use Illuminate\Support\Facades\Log;
14
use Illuminate\Support\Facades\Cache;
15

16
class StatusController extends Controller {
17

18
/**
19
         * Setup the layout used by the controller.
20
         *
21
         * @return void
22
         */
23

24
        public function __construct() {
×
25
        }
×
26

27

28

29
        protected function showStatus()
×
30
        {
31
                // Cache status results for 60 seconds to avoid slow RPC calls on every page load
32
                $cached = Cache::remember('status_page_data', 60, function () {
×
33
                        return $this->collectStatusData();
×
34
                });
×
35

36
                $view = View::make('status');
×
37
                $view->web_status = $cached['web_status'];
×
38
                $view->mysql_status = $cached['mysql_status'];
×
39
                $view->marscoind_status = $cached['marscoind_status'];
×
40
                $view->network = $cached['network'];
×
41
                $view->blockexplorer = $cached['blockexplorer'];
×
42
                $view->pebas_status = $cached['pebas_status'];
×
43
                $view->ipfs_status = $cached['ipfs_status'];
×
44
                $view->blockchain_tracker_status = $cached['blockchain_tracker_status'];
×
45
                $view->ballot_server_status = $cached['ballot_server_status'];
×
46
                return $view;
×
47
        }
48

49
        protected function collectStatusData()
×
50
        {
51
                $web_status = "danger";
×
52
                $mysql_status = "danger";
×
53
                $marscoind_status = "danger";
×
54

55
                $blockexplorer = "danger";
×
56
                $pebas_status = "danger";
×
57
                $ipfs_status = "danger";
×
58

59

60

61
                //apache webserver check
62
                try {
63
                    $a = AppHelper::file_get_contents_curl('http://127.0.0.1');
×
64
                    if($a)
×
65
                            $web_status = "success";
×
66
                    else $web_status = "danger";
×
67
                }
68
                catch (Exception $e) {
×
69
                    $web_status = "danger";
×
70
                }
71

72

73
                // Test database connection
74
                try {
75
                    DB::connection()->getPdo();
×
76
                    $mysql_status = "success";
×
77
                } catch (\Exception $e) {
×
78
                    $mysql_status = "danger";
×
79
                }
80

81

82
                try {
83
                        $data = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
84
                        $RPC_Host = $data['rpc_host'];
×
85
                        $RPC_Port = $data['rpc_port'];
×
86
                        $RPC_User = $data['rpc_user'];
×
87
                        $RPC_Pass = $data['rpc_pass'];
×
88
                        
89
                        $nu92u5p9u2np8uj5wr = "http://" . $RPC_User . ":" . $RPC_Pass . "@" . $RPC_Host . ":" . $RPC_Port . "/";
×
90
                        $Marscoind = new jsonRPCClient($nu92u5p9u2np8uj5wr);
×
91
                        $network = $Marscoind->getNetworkInfo();
×
92

93
                        // Also fetch blockchain info for blocks/difficulty (separate RPC call in v28+)
94
                        try {
95
                                $blockchain = $Marscoind->getBlockchainInfo();
×
96
                                $network['blocks'] = $blockchain['blocks'] ?? 0;
×
97
                                $network['difficulty'] = $blockchain['difficulty'] ?? 0;
×
98
                        } catch (\Exception $e) {
×
99
                                $network['blocks'] = 0;
×
100
                                $network['difficulty'] = 0;
×
101
                        }
102

103
                        // Check specific fields in the response
104
                        $marscoind_status = (isset($network['version']) && isset($network['protocolversion'])) ? "success" : "danger";
×
105
                        
106
                } catch (\Exception $e) {
×
107
                        Log::debug('Exception caught: ' . $e->getMessage());
×
108
                        $marscoind_status = "danger";
×
109
                        $network = array();
×
110
                }
111
                
112

113
                //blockexplorer check
114
                try {
NEW
115
                    $json = AppHelper::file_get_contents_curl(config('blockchain.explorer.primary_url') . '/api/status?q=getInfo');
×
116
                    $a = json_decode($json, true);
×
117
                    if($a)
×
118
                            $blockexplorer = "success";
×
119
                    else $blockexplorer = "danger";
×
120
                }
121
                catch (Exception $e) {
×
122
                    $blockexplorer = "danger";
×
123
                }
124

125

126
                //pebas api check
127
                try {
NEW
128
                    $json = AppHelper::file_get_contents_curl(config('blockchain.pebas.public_url') . '/api/mars/utxo?sender_address=MRKAuE7k9UhANQ8JjoU5A9KACic5Rt2Diz&receiver_address=MRKAuE7k9UhANQ8JjoU5A9KACic5Rt2Diz&amount=0.1');
×
129
                    $a = json_decode($json, true);
×
130
                        //Log::debug($a);
131
                    if($a)
×
132
                            $pebas_status = "success";
×
133
                    else $pebas_status = "danger";
×
134
                }
135
                catch (Exception $e) {
×
136
                    $pebas_status = "danger";
×
137
                }
138

139

140
                
141
                //ipfs node check
142
                try {
NEW
143
                    $a = AppHelper::file_get_contents_curl(config('blockchain.ipfs.api_url') . '/api/v0/swarm/peers');
×
144
                    if($a)
×
145
                            $ipfs_status = "success";
×
146
                    else $ipfs_status = "danger";
×
147
                }
148
                catch (Exception $e) {
×
149
                    $ipfs_status = "danger";
×
150
                }
151

152

153
                // Check the blockchain tracker status
154
                // In your check method
155
                $lastProcessed = $this->getLastProcessedTimestamp();
×
156
                $now = Carbon::now(); // Use same timezone as database
×
157

158
                Log::debug("Last Processed: " . $lastProcessed);
×
159
                Log::debug("Now: " . $now);
×
160
                Log::debug("Diff in minutes: " . $lastProcessed->diffInMinutes($now));
×
161

162
                if ($lastProcessed->diffInMinutes($now) <= 15) {
×
163
                        Log::debug("Success - diff is under 15 mins");
×
164
                        $blockchain_tracker_status = "success";
×
165
                } else {
166
                        Log::debug("Danger - diff is over 15 mins");
×
167
                        $blockchain_tracker_status = "danger";
×
168
                }
169

170

171
                // Check the ballot shuffle server status
172
                $ballot_server_status = $this->checkBallotServer();
×
173

174
                return [
×
175
                        'web_status' => $web_status,
×
176
                        'mysql_status' => $mysql_status,
×
177
                        'marscoind_status' => $marscoind_status,
×
178
                        'network' => $network,
×
179
                        'blockexplorer' => $blockexplorer,
×
180
                        'pebas_status' => $pebas_status,
×
181
                        'ipfs_status' => $ipfs_status,
×
182
                        'blockchain_tracker_status' => $blockchain_tracker_status,
×
183
                        'ballot_server_status' => $ballot_server_status,
×
184
                ];
×
185
        }
186

187

188
        public function getSystemStatus() {
×
189
        $response = [
×
190
            'ipfs_status' => 'offline',
×
191
            'blockchain_tracker_status' => 'offline',
×
192
            'ballot_server_status' => 'offline'
×
193
        ];
×
194

195
        // IPFS node check
196
        try {
NEW
197
            $a = AppHelper::file_get_contents_curl(config('blockchain.ipfs.api_url') . '/api/v0/swarm/peers');
×
198
            $response['ipfs_status'] = $a ? 'online' : 'offline';
×
199
        } catch (\Exception $e) {
×
200
            $response['ipfs_status'] = 'offline';
×
201
        }
202

203
        // Blockchain tracker status
204
        try {
205
            $lastProcessed = $this->getLastProcessedTimestamp();
×
206
            $now = Carbon::now();
×
207
            $response['blockchain_tracker_status'] = $lastProcessed->diffInMinutes($now) <= 15 ? 'online' : 'offline';
×
208
        } catch (\Exception $e) {
×
209
            $response['blockchain_tracker_status'] = 'offline';
×
210
        }
211

212
        // Ballot server status
213
        $response['ballot_server_status'] = $this->checkBallotServer();
×
214

215
        return response()->json($response);
×
216
    }
217

NEW
218
    private function checkBallotServer($host = null, $port = null) {
×
NEW
219
        $host = $host ?? config('blockchain.ballot.host', '127.0.0.1');
×
NEW
220
        $port = $port ?? config('blockchain.ballot.port', 3678);
×
221
        $context = stream_context_create([
×
222
            'ssl' => [
×
223
                'verify_peer' => false,
×
224
                'verify_peer_name' => false,
×
225
                'allow_self_signed' => true,
×
226
            ]
×
227
        ]);
×
228
        $socket = @stream_socket_client('ssl://' . $host . ':' . $port, $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
×
229
        if ($socket) {
×
230
            fclose($socket);
×
231
            return "success";
×
232
        }
233
        return "danger";
×
234
    }
235

236
    private function getLastProcessedTimestamp() {
×
237
        $lastLog = DB::table('feed_log')->latest('processed_at')->first();
×
238
        return Carbon::createFromFormat('Y-m-d H:i:s', $lastLog->processed_at, 'America/New_York')
×
239
                    ->setTimezone('UTC');
×
240
    }
241

242

243

244
}
245

246

247
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc