diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-31 09:17:49 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-31 09:17:49 +0000 |
| commit | 3d6901831904141166d9ed8f47813c45cba109b6 (patch) | |
| tree | 44d0a431b148ad301971fadb7017dfbf937e45ff /src/nostr/builder.rs | |
| parent | 08ab20509b9c730d3db98dd6e9deb5e2b548979e (diff) | |
purgatory: fix state event receive code
Diffstat (limited to 'src/nostr/builder.rs')
| -rw-r--r-- | src/nostr/builder.rs | 47 |
1 files changed, 6 insertions, 41 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 2b4d524..37fa025 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -144,51 +144,16 @@ impl Nip34WritePolicy { | |||
| 144 | 144 | ||
| 145 | match self.state_policy.validate(event) { | 145 | match self.state_policy.validate(event) { |
| 146 | StateResult::Accept => { | 146 | StateResult::Accept => { |
| 147 | // Parse state to get identifier for purgatory message | ||
| 148 | let identifier = event | ||
| 149 | .tags | ||
| 150 | .iter() | ||
| 151 | .find_map(|tag| { | ||
| 152 | let tag_vec = tag.clone().to_vec(); | ||
| 153 | if tag_vec.len() >= 2 && tag_vec[0] == "d" { | ||
| 154 | Some(tag_vec[1].clone()) | ||
| 155 | } else { | ||
| 156 | None | ||
| 157 | } | ||
| 158 | }) | ||
| 159 | .unwrap_or_else(|| "unknown".to_string()); | ||
| 160 | |||
| 161 | // Process state alignment asynchronously | 147 | // Process state alignment asynchronously |
| 162 | match self.state_policy.process_state_event(event).await { | 148 | match self.state_policy.process_state_event(event).await { |
| 163 | Ok(0) => { | 149 | Ok(poilicy_result) => poilicy_result, |
| 164 | // No repos aligned - event was added to purgatory | ||
| 165 | tracing::info!( | ||
| 166 | "State event {} added to purgatory: waiting for git data for identifier {}", | ||
| 167 | event_id_str, | ||
| 168 | identifier | ||
| 169 | ); | ||
| 170 | WritePolicyResult::Reject { | ||
| 171 | status: true, // Client sees OK | ||
| 172 | message: format!( | ||
| 173 | "purgatory: state event stored, waiting for git push for {}", | ||
| 174 | identifier | ||
| 175 | ) | ||
| 176 | .into(), | ||
| 177 | } | ||
| 178 | } | ||
| 179 | Ok(count) => { | ||
| 180 | // Successfully aligned repos | ||
| 181 | tracing::debug!( | ||
| 182 | "Accepted repository state {}: aligned {} repo(s)", | ||
| 183 | event_id_str, | ||
| 184 | count | ||
| 185 | ); | ||
| 186 | WritePolicyResult::Accept | ||
| 187 | } | ||
| 188 | Err(e) => { | 150 | Err(e) => { |
| 189 | tracing::warn!("Failed to process state event {}: {}", event_id_str, e); | 151 | tracing::warn!("Failed to process state event {}: {}", event_id_str, e); |
| 190 | // Still accept the event even if processing failed | 152 | // reject if processing failed |
| 191 | WritePolicyResult::Accept | 153 | WritePolicyResult::Reject { |
| 154 | status: false, | ||
| 155 | message: format!("error: {e}").into(), | ||
| 156 | } | ||
| 192 | } | 157 | } |
| 193 | } | 158 | } |
| 194 | } | 159 | } |