Files
kane-diagnostics/hubzilla/addon/g1wallet/g1wallet_spool.php
2026-06-14 07:45:02 -04:00

59 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* g1wallet_spool.php — POST handlers for g1wallet.
* Currently: address registration only.
* Future: transaction broadcast (when scn01 payment is wired).
*/
function g1wallet_handle_address_post($access) {
$address = trim($_POST['g1_address'] ?? '');
if (!$address) {
return g1wallet_render_landing_with_error($access, 'Ğ1 address is required.');
}
// Ğ1 SS58 addresses: begin with "g1", 4647 characters, base58 charset.
$len = strlen($address);
if ($len < 46 || $len > 48) {
return g1wallet_render_landing_with_error($access,
'Invalid address length (' . $len . ' characters). A Ğ1 address is 4647 characters long.');
}
if (strncmp($address, 'g1', 2) !== 0) {
return g1wallet_render_landing_with_error($access,
'Invalid address: must begin with "g1".');
}
if (!preg_match('/^[1-9A-HJ-NP-Za-km-z]+$/', $address)) {
return g1wallet_render_landing_with_error($access,
'Invalid address: contains characters not valid in a Ğ1 address.');
}
$channel_id = local_channel();
if (!$channel_id) {
return g1wallet_render_landing_with_error($access, 'Not authenticated.');
}
set_pconfig($channel_id, 'g1wallet', 'g1_address', $address);
// Render landing with success notice.
return g1wallet_render_landing_with_success($access,
'Ğ1 address saved. Your balance will appear below.');
}
// -----------------------------------------------------------------------------
// LANDING VARIANTS WITH NOTICE
// These wrap g1wallet_render_landing() with a prepended notice.
// -----------------------------------------------------------------------------
function g1wallet_render_landing_with_error($access, $message) {
$notice = '<div class="alert alert-danger">' . g1wallet_h($message) . '</div>';
return $notice . g1wallet_render_landing($access);
}
function g1wallet_render_landing_with_success($access, $message) {
$notice = '<div class="alert alert-success">' . g1wallet_h($message) . '</div>';
return $notice . g1wallet_render_landing($access);
}