Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions web/apps/messages/address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
require_once dirname(__DIR__)."/apps.inc.php";
define("PAGE", true);
define("APP_NAME", "Messages");
require_once ROOT. '/web/apps/explorer/include/functions.php';

$address = isset($_GET['address']) ? san_host($_GET['address']) : '';

function getAddressMessages($address) {
global $db;
if (empty($address)) {
return [];
}
$sql = "SELECT * FROM transactions
WHERE type = 1 AND message != '' AND dst = :address
ORDER BY height DESC";
return $db->run($sql, [":address" => $address]);
}

$messages = getAddressMessages($address);

require_once __DIR__. '/../common/include/top.php';
?>

<ol class="breadcrumb m-0 ps-0 h4">
<li class="breadcrumb-item"><a href="/apps/explorer">Explorer</a></li>
<li class="breadcrumb-item"><a href="/apps/messages">Messages</a></li>
<li class="breadcrumb-item">Address</li>
</ol>

<form class="row mb-3" method="get" action="">
<div class="col-lg-4">
<label for="address">Address</label>
<input type="text" class="form-control p-1" placeholder="Enter address" name="address" id="address" value="<?php echo htmlspecialchars($address) ?>">
</div>
<div class="col-lg-2">
<label>&nbsp;</label>
<button type="submit" class="btn btn-primary btn-sm w-100">Search</button>
</div>
</form>

<div class="table-responsive">
<table class="table table-sm table-striped dataTable">
<thead class="table-light">
<tr>
<th>ID</th>
<th>Date</th>
<th>Height</th>
<th>Source</th>
<th>Destination</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<?php if (!empty($messages)) { ?>
<?php foreach($messages as $tx) { ?>
<tr>
<td><?php echo explorer_tx_link($tx['id'], true) ?></td>
<td><?php echo display_date($tx['date']) ?></td>
<td><?php echo $tx['height'] ?></td>
<td><?php echo explorer_address_link($tx['src'], true) ?></td>
<td><?php echo explorer_address_link($tx['dst'], true) ?></td>
<td><?php echo htmlspecialchars($tx['message']) ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td colspan="6">No messages found for this address.</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>

<?php
require_once __DIR__ . '/../common/include/bottom.php';
?>
65 changes: 65 additions & 0 deletions web/apps/messages/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
require_once dirname(__DIR__)."/apps.inc.php";
define("PAGE", true);
define("APP_NAME", "Messages");
require_once ROOT. '/web/apps/explorer/include/functions.php';

$search_blocks = isset($_GET['blocks']) ? intval($_GET['blocks']) : 1000;

function getAddressesWithMessages($limit) {
global $db;
$current_height = Block::getHeight();
$start_height = $current_height - $limit;
$sql = "SELECT DISTINCT dst AS address FROM transactions WHERE type = 1 AND message != '' AND height >= :start_height AND dst IS NOT NULL AND dst != ''
ORDER BY address ASC";
$rows = $db->run($sql, [":start_height" => $start_height]);
return array_column($rows, 'address');
}

$addresses = getAddressesWithMessages($search_blocks);

require_once __DIR__. '/../common/include/top.php';
?>

<ol class="breadcrumb m-0 ps-0 h4">
<li class="breadcrumb-item"><a href="/apps/explorer">Explorer</a></li>
<li class="breadcrumb-item">Addresses with Messages</li>
</ol>

<form class="row mb-3" method="get" action="">
<div class="col-lg-4">
<label for="blocks">Search last blocks</label>
<input type="text" class="form-control p-1" placeholder="Number of blocks" name="blocks" id="blocks" value="<?php echo htmlspecialchars($search_blocks) ?>">
</div>
<div class="col-lg-2">
<label>&nbsp;</label>
<button type="submit" class="btn btn-primary btn-sm w-100">Search</button>
</div>
</form>

<div class="table-responsive">
<table class="table table-sm table-striped dataTable">
<thead class="table-light">
<tr>
<th>Address</th>
</tr>
</thead>
<tbody>
<?php if (!empty($addresses)) { ?>
<?php foreach($addresses as $address) { ?>
<tr>
<td><a href="/apps/messages/address.php?address=<?php echo urlencode($address) ?>"><?php echo htmlspecialchars($address) ?></a></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td>No addresses with messages found in the last <?php echo htmlspecialchars($search_blocks) ?> blocks.</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>

<?php
require_once __DIR__ . '/../common/include/bottom.php';
?>