This commit is contained in:
2026-06-12 15:02:19 -04:00
parent 5b03f95e9e
commit 2213aab723

View File

@@ -414,6 +414,7 @@ function cry01_cache_is_stale() {
function cry01_refresh_balance_cache($g1_pubkey) { function cry01_refresh_balance_cache($g1_pubkey) {
// Refreshes the balance cache for the given public key. // Refreshes the balance cache for the given public key.
// $g1_pubkey is a 32-byte raw account ID (as returned by cry01_ss58_decode()).
// The public key comes from the wallet session via the manage POST form — never from config. // The public key comes from the wallet session via the manage POST form — never from config.
// Returns true on success, false on failure. // Returns true on success, false on failure.
if (!$g1_pubkey) { if (!$g1_pubkey) {
@@ -423,9 +424,13 @@ function cry01_refresh_balance_cache($g1_pubkey) {
$balance = cry01_get_balance($g1_pubkey); $balance = cry01_get_balance($g1_pubkey);
if ($balance === null) return false; if ($balance === null) return false;
// Cache stores the account ID as hex, not raw binary — raw binary bytes
// are not valid UTF-8 and cause json_encode() to fail silently (returns
// false), which previously resulted in an empty (0-byte) cache file
// despite cry01_write_cache() reporting success.
$cache = cry01_read_cache(); $cache = cry01_read_cache();
$cache['balance'] = $balance; $cache['balance'] = $balance;
$cache['g1_pubkey'] = $g1_pubkey; $cache['g1_pubkey'] = bin2hex($g1_pubkey);
$cache['refreshed_at'] = date('c'); $cache['refreshed_at'] = date('c');
return cry01_write_cache($cache); return cry01_write_cache($cache);
} }