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

@@ -12,18 +12,18 @@
function cry01_handle_signal_post($association_slug, $access) {
// Validates and submits a capacity signal to the orchestrator spool receiver.
$g1_pubkey = trim($_POST['g1_pubkey'] ?? '');
$direction = trim($_POST['direction'] ?? '');
$category_id = trim($_POST['category_id'] ?? '');
$g1_pubkey = trim($_POST['g1_pubkey'] ?? '');
$direction = trim($_POST['direction'] ?? '');
$category_id = trim($_POST['category_id'] ?? '');
$capacity_description = trim($_POST['capacity_description'] ?? '');
$g1_denomination = trim($_POST['g1_denomination'] ?? '');
$duration_days = intval($_POST['duration_days'] ?? 0);
$g1_denomination = trim($_POST['g1_denomination'] ?? '');
$duration_days = intval($_POST['duration_days'] ?? 0);
// Validate required fields.
$errors = [];
if (!$g1_pubkey) $errors[] = 'Ğ1 public key is required.';
if (!$g1_pubkey) $errors[] = 'Ğ1 public key is required.';
if (!in_array($direction, ['offer', 'seek'])) $errors[] = 'Direction must be offer or seek.';
if (!$category_id) $errors[] = 'Category is required.';
if (!$category_id) $errors[] = 'Category is required.';
if (!$capacity_description) $errors[] = 'Description is required.';
if (!$g1_denomination || !is_numeric($g1_denomination) || floatval($g1_denomination) <= 0) {
$errors[] = 'Ğ1 amount must be a positive number.';
@@ -45,11 +45,11 @@ function cry01_handle_signal_post($association_slug, $access) {
// Build the spool envelope per contracts/signal-v1.json.
$envelope = [
'_header' => [
'addon' => 'cry01',
'association_slug' => $association_slug,
'participant_xchan' => get_observer_hash(),
'submitted_at' => date('c'),
'node_token_hash' => hash('sha256', $token),
'addon' => 'cry01',
'association_slug' => $association_slug,
'participant_xchan' => get_observer_hash(),
'submitted_at' => date('c'),
'node_token_hash' => hash('sha256', $token),
],
'_payload' => [
'g1_pubkey' => $g1_pubkey,
@@ -83,7 +83,7 @@ function cry01_handle_signal_post($association_slug, $access) {
// ---------------------------------------------------------------------------
function cry01_handle_manage_post($association_slug) {
// Handles operator manage actions: currently only cache refresh.
// Handles operator manage actions.
if (!cry01_verify_csrf()) {
return cry01_render_error('Invalid form token. Please reload and try again.');
}
@@ -91,10 +91,20 @@ function cry01_handle_manage_post($association_slug) {
$action = $_POST['action'] ?? '';
if ($action === 'refresh_cache') {
$ok = cry01_refresh_balance_cache();
// The public key comes from the wallet session via the hidden form field.
// It is never read from config — the operator is a participant like any other.
$g1_pubkey = trim($_POST['g1_pubkey'] ?? '');
if (!$g1_pubkey) {
return '<div class="cry01-content">'
. '<div class="alert alert-warning">No Ğ1 public key received. '
. 'Unlock your <a href="' . z_root() . '/g1wallet">Ğ1 Wallet</a> first, then try again.</div>'
. '</div>'
. cry01_render_manage($association_slug);
}
$ok = cry01_refresh_balance_cache($g1_pubkey);
$msg = $ok
? '<div class="alert alert-success">Balance cache refreshed successfully.</div>'
: '<div class="alert alert-warning">Cache refresh failed. Check that the Duniter node is reachable and the operator Ğ1 key is configured.</div>';
: '<div class="alert alert-warning">Cache refresh failed. Check that the Duniter node is reachable.</div>';
return '<div class="cry01-content">' . $msg . '</div>' . cry01_render_manage($association_slug);
}
@@ -108,8 +118,8 @@ function cry01_handle_manage_post($association_slug) {
function cry01_post_to_orchestrator($path, $payload) {
// POSTs a JSON envelope to the orchestrator spool receiver.
// Returns true on success (HTTP 201), false on any failure.
$config = cry01_load_config();
$base = rtrim($config['receiver_url'] ?? '', '/');
$config = cry01_load_config();
$base = rtrim($config['receiver_url'] ?? '', '/');
if (!$base) {
logger('cry01_spool: receiver_url not configured');
return false;