This commit is contained in:
2026-06-08 02:48:24 -04:00
parent 95dfc02e82
commit bf3e72f3ce
4 changed files with 66 additions and 46 deletions

View File

@@ -122,22 +122,21 @@ function cry01_cache_is_stale() {
return (time() - filemtime($path)) > $max_age;
}
function cry01_refresh_balance_cache() {
// Refreshes the balance cache by querying the Duniter node.
// Writes updated cache to disk. Called by the manage route.
$config = cry01_load_config();
$pubkey = $config['operator_g1_pubkey'] ?? '';
if (!$pubkey) {
logger('cry01_chain: operator_g1_pubkey not set in config');
function cry01_refresh_balance_cache($g1_pubkey) {
// Refreshes the balance cache for the given public key.
// 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) {
logger('cry01_chain: cry01_refresh_balance_cache called with empty pubkey');
return false;
}
$balance = cry01_get_balance($pubkey);
$balance = cry01_get_balance($g1_pubkey);
if ($balance === null) return false;
$cache = cry01_read_cache();
$cache['operator_balance'] = $balance;
$cache['operator_g1_pubkey'] = $pubkey;
$cache['refreshed_at'] = date('c');
$cache['balance'] = $balance;
$cache['g1_pubkey'] = $g1_pubkey;
$cache['refreshed_at'] = date('c');
return cry01_write_cache($cache);
}