diff --git a/hubzilla/addon/cry01/cry01_chain.php b/hubzilla/addon/cry01/cry01_chain.php index cb070e7..06d37be 100644 --- a/hubzilla/addon/cry01/cry01_chain.php +++ b/hubzilla/addon/cry01/cry01_chain.php @@ -414,6 +414,7 @@ function cry01_cache_is_stale() { function cry01_refresh_balance_cache($g1_pubkey) { // 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. // Returns true on success, false on failure. if (!$g1_pubkey) { @@ -423,9 +424,13 @@ function cry01_refresh_balance_cache($g1_pubkey) { $balance = cry01_get_balance($g1_pubkey); 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['balance'] = $balance; - $cache['g1_pubkey'] = $g1_pubkey; + $cache['g1_pubkey'] = bin2hex($g1_pubkey); $cache['refreshed_at'] = date('c'); return cry01_write_cache($cache); }