1use std::collections::{HashMap, HashSet};
55use std::sync::{Arc, Mutex};
56use std::time::{Duration, Instant};
57
58use datumesh_core::{
59 format_uri, keys_from_response, Args, Cell, CellRef, Error as CoreError, ErrorCode, FunctionDescriptor, KeyDoc,
60 MeshDoc, Receipt, Request, Scalar,
61};
62use datumesh_engine::{Budget, Clock, EvalError, FnBinding, Input, Inputs, Member, Runtime, SlicePattern};
63use datumesh_store::Store;
64
65use crate::client::{Client, ClientConfig};
66use crate::config::Config;
67
68type Version = (Vec<u8>, Box<Receipt>);
70
71const MAX_WALK: usize = 10_000;
73
74const END: &str = "9999-12-31T23:59:59.999999Z";
76
77#[derive(Default)]
80pub struct KeyCache {
81 #[allow(clippy::type_complexity)]
82 docs: Mutex<HashMap<String, (Result<KeyDoc, CoreError>, Vec<u8>, Instant)>>,
83}
84
85impl std::fmt::Debug for KeyCache {
86 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87 f.debug_struct("KeyCache").field("hosts", &self.docs.lock().map(|d| d.len()).unwrap_or(0)).finish()
88 }
89}
90
91impl KeyCache {
92 pub fn insert(&self, host: &str, doc: &[u8]) -> Result<(), CoreError> {
95 let kd = keys_from_response(host, 200, Some(doc))?;
96 self.docs
97 .lock()
98 .unwrap_or_else(|p| p.into_inner())
99 .insert(host.to_string(), (Ok(kd), doc.to_vec(), Instant::now()));
100 Ok(())
101 }
102
103 pub fn insert_response(&self, host: &str, status: u16, body: Option<&[u8]>) {
106 let r = keys_from_response(host, status, body);
107 self.docs
108 .lock()
109 .unwrap_or_else(|p| p.into_inner())
110 .insert(host.to_string(), (r, body.unwrap_or_default().to_vec(), Instant::now()));
111 }
112
113 pub fn get(&self, host: &str) -> Option<(KeyDoc, Vec<u8>, Instant)> {
115 match self.docs.lock().unwrap_or_else(|p| p.into_inner()).get(host) {
116 Some((Ok(d), b, at)) => Some((d.clone(), b.clone(), *at)),
117 _ => None,
118 }
119 }
120
121 pub fn result(&self, host: &str) -> Option<Result<KeyDoc, CoreError>> {
123 self.docs.lock().unwrap_or_else(|p| p.into_inner()).get(host).map(|(r, _, _)| r.clone())
124 }
125
126 pub fn remove(&self, host: &str) {
128 self.docs.lock().unwrap_or_else(|p| p.into_inner()).remove(host);
129 }
130}
131
132pub type ForeignError = crate::client::ClientError;
135
136impl ForeignError {
137 pub(crate) fn eval(self) -> EvalError {
140 EvalError::InvalidInput(CoreError::new(self.code, "$", format!("cross-mesh: {}", self.detail)))
141 }
142}
143
144pub fn pct(s: &str) -> String {
146 crate::client::pct(s)
147}
148
149fn before(t: &str) -> Option<String> {
151 let us = datumesh_formula::calendar::parse_instant(t)?;
152 datumesh_formula::calendar::instant_text(us - 1)
153}
154
155pub fn host_of(name: &str) -> &str {
157 name.split('/').next().unwrap_or(name)
158}
159
160struct Confirmed {
161 at: Instant,
162 instant: String,
164}
165
166pub struct Foreign {
169 store: Arc<dyn Store + Send + Sync>,
170 client: Client,
171 clock: Arc<dyn Clock>,
172 owned: Vec<String>,
173 enabled: bool,
174 ttl_binding: Duration,
175 ttl_current: Duration,
176 names: Mutex<HashMap<String, Confirmed>>,
177 cells: Mutex<HashMap<String, Confirmed>>,
178 invalidated: Mutex<Vec<String>>,
179 dirty: std::sync::atomic::AtomicBool,
182 any: std::sync::atomic::AtomicBool,
183 deps: Mutex<HashMap<String, Arc<Vec<Cell>>>>,
184 pub(crate) fetches: std::sync::atomic::AtomicU64,
186 pub(crate) failures: std::sync::atomic::AtomicU64,
187 pub(crate) imported: std::sync::atomic::AtomicU64,
188}
189
190impl std::fmt::Debug for Foreign {
191 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
192 f.debug_struct("Foreign").field("owned", &self.owned).field("enabled", &self.enabled).finish_non_exhaustive()
193 }
194}
195
196enum Fetched {
197 Receipt(Vec<u8>, Box<Receipt>),
198 NotCovered,
199}
200
201impl Foreign {
202 pub(crate) fn new(
203 config: &Config,
204 store: Arc<dyn Store + Send + Sync>,
205 keys: Arc<KeyCache>,
206 clock: Arc<dyn Clock>,
207 ) -> Foreign {
208 let cc = ClientConfig {
209 peers: config.peers.clone(),
210 allowed: config.cross_mesh_hosts.clone(),
211 timeout: config.peer_timeout,
212 key_ttl: config.ttl.key_doc,
213 key_refetch: config.ttl.key_refetch,
214 mesh_ttl: config.ttl.mesh_doc,
215 };
216 Foreign {
217 store,
218 client: Client::with_keys(cc, keys),
219 clock,
220 owned: config.namespaces.clone(),
221 enabled: config.cross_mesh,
222 ttl_binding: config.ttl.binding,
223 ttl_current: config.ttl.current,
224 names: Mutex::new(HashMap::new()),
225 cells: Mutex::new(HashMap::new()),
226 invalidated: Mutex::new(Vec::new()),
227 dirty: Default::default(),
228 any: Default::default(),
229 deps: Mutex::new(HashMap::new()),
230 fetches: Default::default(),
231 failures: Default::default(),
232 imported: Default::default(),
233 }
234 }
235
236 pub fn client(&self) -> &Client {
238 &self.client
239 }
240
241 pub fn is_foreign(&self, name: &str) -> bool {
244 let host = host_of(name);
245 self.enabled && !self.owned.iter().any(|h| h == host) && self.client.allowed(host)
246 }
247
248 pub fn any_cells(&self) -> bool {
250 self.any.load(std::sync::atomic::Ordering::Acquire)
251 }
252
253 pub fn take_invalidated(&self) -> Vec<String> {
256 if !self.dirty.swap(false, std::sync::atomic::Ordering::AcqRel) {
257 return Vec::new();
258 }
259 std::mem::take(&mut *self.invalidated.lock().unwrap_or_else(|p| p.into_inner()))
260 }
261
262 fn counted<T>(&self, r: Result<T, ForeignError>) -> Result<T, ForeignError> {
263 self.fetches.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
264 if r.is_err() {
265 self.failures.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
266 }
267 r
268 }
269
270 pub fn keys_for(&self, host: &str, refresh: bool) -> Result<KeyDoc, ForeignError> {
272 self.counted(self.client.key_document(host, refresh))
273 }
274
275 pub fn mesh(&self, host: &str) -> Result<MeshDoc, ForeignError> {
277 self.counted(self.client.resolve(host))
278 }
279
280 pub fn ensure_name(&self, name: &str) -> Result<(), ForeignError> {
282 if !self.is_foreign(name) {
283 return Ok(());
284 }
285 if let Some(c) = self.names.lock().unwrap_or_else(|p| p.into_inner()).get(name) {
286 if c.at.elapsed() < self.ttl_binding {
287 return Ok(());
288 }
289 }
290 let now = self.clock.now();
291 let host = host_of(name);
292 let local = self
293 .store
294 .resolve_binding(name, END)
295 .map_err(|e| ForeignError::unavailable(format!("store: {e}")))?
296 .map(|b| (b.fn_hash, b.tx));
297 let mut chain = Vec::new();
298 let mut at: Option<String> = None;
299 while let Some(b) = self.counted(self.client.binding(host, name, at.as_deref()))? {
300 let b = (b.fn_hash, b.since);
301 if Some(&b) == local.as_ref() {
302 break;
303 }
304 if chain.len() >= MAX_WALK {
305 return Err(ForeignError::unavailable(format!("{name}: more than {MAX_WALK} bindings")));
306 }
307 at = Some(before(&b.1).ok_or_else(|| ForeignError::unavailable("a binding at the first instant"))?);
308 let stop = at.as_deref() < Some("0001-01-01T00:00:00.000000Z");
309 chain.push(b);
310 if stop {
311 break;
312 }
313 }
314 if let (Some(oldest), Some(l)) = (chain.last(), &local) {
315 if oldest.1 <= l.1 {
316 return Err(ForeignError::unavailable(format!("{name}: the other mesh's bindings do not extend ours")));
317 }
318 }
319 for (fn_hash, since) in chain.iter().rev() {
320 self.import_descriptor(host, fn_hash)?;
321 self.store
322 .bind_name(name, fn_hash, since)
323 .map_err(|e| ForeignError::unavailable(format!("bind {name}: {e}")))?;
324 }
325 self.names
326 .lock()
327 .unwrap_or_else(|p| p.into_inner())
328 .insert(name.to_string(), Confirmed { at: Instant::now(), instant: now });
329 Ok(())
330 }
331
332 fn import_descriptor(&self, host: &str, fn_hash: &str) -> Result<(), ForeignError> {
333 if self.store.descriptor(fn_hash).is_some() {
334 return Ok(());
335 }
336 let body = self.counted(self.client.descriptor(host, fn_hash))?;
337 let h = self
338 .store
339 .put_descriptor(&body)
340 .map_err(|e| ForeignError::new(ErrorCode::FnHashMismatch, e.to_string()))?;
341 if h != fn_hash {
342 return Err(ForeignError::new(ErrorCode::FnHashMismatch, format!("{host} gave the descriptor {h}")));
343 }
344 Ok(())
345 }
346
347 fn fetch_cell(&self, cell: &Cell, asof: Option<&str>) -> Result<Fetched, ForeignError> {
350 let host = host_of(&cell.ns);
351 let reference = CellRef {
352 ns: cell.ns.clone(),
353 fn_name: cell.fn_name.clone(),
354 args: cell.args.clone(),
355 asof: asof.map(str::to_string),
356 };
357 let uri = format_uri(&reference);
358 let request = Request::new(&cell.id(), asof).map_err(|_| ForeignError::unavailable("request"))?;
359 let f = match self.counted(self.client.cell(host, &uri["cell://".len()..], &request)) {
360 Ok(f) => f,
361 Err(e) if e.code == ErrorCode::Envelope => return Err(ForeignError::unavailable(e.detail)),
362 Err(e) => return Err(e),
363 };
364 match (f.answer.outcome.as_str(), f.answer.receipt) {
365 ("ok" | "stale", Some(r)) => {
366 let bytes = datumesh_core::json::parse(&f.body)
367 .ok()
368 .and_then(|v| v.get("receipt").map(datumesh_core::json::Value::to_jcs))
369 .ok_or_else(|| ForeignError::unavailable("receipt"))?;
370 Ok(Fetched::Receipt(bytes, Box::new(r)))
371 }
372 ("not_covered", _) => Ok(Fetched::NotCovered),
373 (o, _) => Err(ForeignError::unavailable(format!("{host}: {o}"))),
374 }
375 }
376
377 fn listed_versions(&self, cell: &Cell, after_tx: Option<&str>) -> Result<Option<Vec<Version>>, ForeignError> {
380 let host = host_of(&cell.ns);
381 let mesh = self.mesh(host)?;
382 if !mesh.endpoints.contains_key("versions") {
383 return Ok(None);
384 }
385 let reference =
386 CellRef { ns: cell.ns.clone(), fn_name: cell.fn_name.clone(), args: cell.args.clone(), asof: None };
387 let uri = format_uri(&reference);
388 let mut rest = uri["cell://".len()..].to_string();
389 if let Some(t) = after_tx
390 .and_then(datumesh_formula::calendar::parse_instant)
391 .and_then(|us| datumesh_formula::calendar::instant_text(us + 1))
392 {
393 rest.push(if rest.contains('?') { '&' } else { '?' });
394 rest.push_str(&format!("from={t}"));
395 }
396 let mut page = self.counted(self.client.versions(host, &rest))?;
397 let mut out = Vec::new();
398 loop {
399 if page.cell.get("fn_hash").and_then(datumesh_core::json::Value::as_str) != Some(cell.fn_hash.as_str()) {
400 return Err(ForeignError::unavailable(format!("{host}: the versions of another function")));
401 }
402 for v in &page.versions {
403 let bytes = self.counted(self.client.receipt(host, &v.receipt))?;
404 let r = Receipt::from_json(&bytes).map_err(|e| ForeignError::new(e.code(), e.to_string()))?;
405 if r.cell().id() != cell.id() || r.tx() != v.tx {
406 return Err(ForeignError::unavailable(format!("{host}: a version of another cell")));
407 }
408 out.push((bytes, Box::new(r)));
409 if out.len() > MAX_WALK {
410 return Err(ForeignError::unavailable(format!("{host}: more than {MAX_WALK} versions")));
411 }
412 }
413 match page.next.clone() {
414 Some(n) => page = self.counted(self.client.versions_at(&n))?,
415 None => break,
416 }
417 }
418 Ok(Some(out))
419 }
420
421 pub fn ensure_cell(&self, cell: &Cell) -> Result<bool, ForeignError> {
424 let id = cell.id();
425 if let Some(c) = self.cells.lock().unwrap_or_else(|p| p.into_inner()).get(&id) {
426 if c.at.elapsed() < self.ttl_current {
427 return Ok(false);
428 }
429 }
430 let now = self.clock.now();
431 let name = cell.function_name();
432 let current = self
433 .store
434 .resolve_binding(&name, &now)
435 .map_err(|e| ForeignError::unavailable(format!("store: {e}")))?
436 .map(|b| b.fn_hash);
437 if current.as_deref() != Some(cell.fn_hash.as_str()) {
438 if self.cells.lock().unwrap_or_else(|p| p.into_inner()).contains_key(&id) {
439 return Ok(false);
441 }
442 return Err(ForeignError::unavailable(format!(
443 "{name}: a cell of an earlier binding is not resolved in 0.1.x"
444 )));
445 }
446 let local = self.store.latest(&id).map_err(|e| ForeignError::unavailable(format!("store: {e}")))?;
447 let chain: Vec<(Vec<u8>, Box<Receipt>)> =
449 match self.listed_versions(cell, local.as_ref().map(|v| v.tx.as_str()))? {
450 Some(listed) => listed,
451 None => {
452 let mut chain: Vec<(Vec<u8>, Box<Receipt>)> = Vec::new();
453 let mut at: Option<String> = None;
454 loop {
455 match self.fetch_cell(cell, at.as_deref())? {
456 Fetched::NotCovered => break,
457 Fetched::Receipt(bytes, r) => {
458 if local.as_ref().is_some_and(|v| v.receipt_hash == r.hash()) {
459 break;
460 }
461 if chain.iter().any(|(_, c)| c.hash() == r.hash()) || chain.len() >= MAX_WALK {
462 return Err(ForeignError::unavailable(format!(
463 "{name}: the other mesh's history does not end"
464 )));
465 }
466 let start = std::cmp::max(r.tx(), r.asof()).to_string();
467 let next = before(&start);
468 chain.push((bytes, r));
469 match next {
470 Some(t) => at = Some(t),
471 None => break,
472 }
473 }
474 }
475 }
476 chain.reverse();
477 chain
478 }
479 };
480 if let (Some((_, oldest)), Some(l)) = (chain.first(), &local) {
481 if oldest.tx() <= l.tx.as_str() {
482 return Err(ForeignError::unavailable(format!("{name}: the other mesh's versions do not extend ours")));
483 }
484 }
485 let added = !chain.is_empty();
486 for (bytes, r) in &chain {
487 self.ensure_namespace(r.signer_host())?;
488 let h =
489 self.store.put_receipt(bytes).map_err(|e| ForeignError::unavailable(format!("put_receipt: {e}")))?;
490 self.store
491 .put_version(&id, r.tx(), &h)
492 .map_err(|e| ForeignError::unavailable(format!("put_version: {e}")))?;
493 self.imported.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
494 }
495 if added {
496 self.invalidated.lock().unwrap_or_else(|p| p.into_inner()).push(id.clone());
497 self.dirty.store(true, std::sync::atomic::Ordering::Release);
498 }
499 self.cells.lock().unwrap_or_else(|p| p.into_inner()).insert(id, Confirmed { at: Instant::now(), instant: now });
500 self.any.store(true, std::sync::atomic::Ordering::Release);
501 Ok(added)
502 }
503
504 fn ensure_namespace(&self, host: &str) -> Result<(), ForeignError> {
507 if self.owned.iter().any(|h| h == host) {
508 return Ok(());
509 }
510 self.keys_for(host, false)?;
511 self.store_key_document(host)
512 }
513
514 pub fn ensure_publisher(&self, ns: &str) -> Result<(), ForeignError> {
521 if !self.is_foreign(ns) {
522 return Ok(());
523 }
524 let host = host_of(ns);
525 self.counted(self.client.publisher_key_document(host))?;
526 self.store_key_document(host)
527 }
528
529 fn store_key_document(&self, host: &str) -> Result<(), ForeignError> {
531 let bytes = self
532 .client
533 .key_document_bytes(host)
534 .ok_or_else(|| ForeignError::new(ErrorCode::KeyUnavailable, host.to_string()))?;
535 let stored = self.store.namespace(host).map_err(|e| ForeignError::unavailable(format!("store: {e}")))?;
536 if stored.as_ref().map(|n| n.keydoc.as_slice()) != Some(bytes.as_slice()) {
537 self.store
538 .put_namespace(host, &bytes, &self.clock.now())
539 .map_err(|e| ForeignError::new(ErrorCode::KeyDoc, format!("put_namespace {host}: {e}")))?;
540 }
541 Ok(())
542 }
543
544 fn foreign_deps(&self, receipt_hash: &str) -> Arc<Vec<Cell>> {
547 if let Some(d) = self.deps.lock().unwrap_or_else(|p| p.into_inner()).get(receipt_hash) {
548 return d.clone();
549 }
550 let mut out = Vec::new();
551 let mut seen = HashSet::new();
552 let mut todo = vec![receipt_hash.to_string()];
553 while let Some(h) = todo.pop() {
554 if !seen.insert(h.clone()) || seen.len() > 100_000 {
555 continue;
556 }
557 if h.starts_with("slice:") {
558 if let Some(m) = self.store.manifest(&h) {
559 if let Ok(m) = datumesh_core::Manifest::from_json(&m) {
560 todo.extend(m.members().iter().cloned());
561 }
562 }
563 continue;
564 }
565 let Some(bytes) = self.store.receipt(&h) else {
566 continue;
567 };
568 let Ok(r) = Receipt::from_json(&bytes) else { continue };
569 if self.is_foreign(&r.cell().ns) && r.inputs().is_empty() {
570 out.push(r.cell().clone());
571 } else {
572 todo.extend(r.inputs().iter().cloned());
573 }
574 }
575 let d = Arc::new(out);
576 let mut deps = self.deps.lock().unwrap_or_else(|p| p.into_inner());
577 if deps.len() > 100_000 {
578 deps.clear();
579 }
580 deps.insert(receipt_hash.to_string(), d.clone());
581 d
582 }
583
584 pub fn refresh_deps(&self, receipt_hash: &str, asof: &str) -> Result<bool, ForeignError> {
588 if !self.any_cells() {
589 return Ok(false);
590 }
591 let mut added = false;
592 for cell in self.foreign_deps(receipt_hash).iter() {
593 let stale = match self.cells.lock().unwrap_or_else(|p| p.into_inner()).get(&cell.id()) {
594 Some(c) => c.at.elapsed() >= self.ttl_current && asof > c.instant.as_str(),
595 None => true,
596 };
597 if stale {
598 added |= self.ensure_cell(cell)?;
599 }
600 }
601 Ok(added)
602 }
603
604 pub fn prepare(&self, cell: &Cell, stored: bool, asof: Option<&str>) -> Result<(), ForeignError> {
607 if !self.is_foreign(&cell.function_name()) || !stored {
608 return Ok(());
609 }
610 let fresh = match self.cells.lock().unwrap_or_else(|p| p.into_inner()).get(&cell.id()) {
611 Some(c) => c.at.elapsed() < self.ttl_current || asof.is_some_and(|a| a <= c.instant.as_str()),
612 None => false,
613 };
614 if !fresh {
615 self.ensure_cell(cell)?;
616 }
617 Ok(())
618 }
619}
620
621pub struct CrossMesh {
623 inner: Arc<dyn Runtime>,
624 foreign: Arc<Foreign>,
625}
626
627impl CrossMesh {
628 pub fn new(inner: Arc<dyn Runtime>, foreign: Arc<Foreign>) -> CrossMesh {
630 CrossMesh { inner, foreign }
631 }
632}
633
634impl Runtime for CrossMesh {
635 fn lang(&self) -> &str {
636 self.inner.lang()
637 }
638
639 fn evaluate(
640 &self,
641 descriptor: &FunctionDescriptor,
642 cell: &Cell,
643 inputs: &mut dyn Inputs,
644 budget: &mut Budget,
645 ) -> Result<Scalar, EvalError> {
646 self.foreign.ensure_publisher(&cell.ns).map_err(ForeignError::eval)?;
648 for name in &descriptor.inputs {
649 self.foreign.ensure_name(name).map_err(ForeignError::eval)?;
650 }
651 let mut w = Through { inner: inputs, foreign: &self.foreign };
652 self.inner.evaluate(descriptor, cell, &mut w, budget)
653 }
654
655 fn asof_dependent(&self, descriptor: &FunctionDescriptor) -> bool {
656 self.inner.asof_dependent(descriptor)
657 }
658}
659
660struct Through<'a> {
662 inner: &'a mut dyn Inputs,
663 foreign: &'a Foreign,
664}
665
666impl Through<'_> {
667 fn pre(&mut self, name: &str, args: &Args, at: Option<&str>) -> Result<(), EvalError> {
668 if !self.foreign.is_foreign(name) {
669 return Ok(());
670 }
671 self.foreign.ensure_name(name).map_err(ForeignError::eval)?;
672 let Some(b) = self.inner.binding_peek(name, at)? else {
673 return Ok(());
674 };
675 if b.descriptor.lang != "stored" {
676 return Ok(());
677 }
678 let (ns, f) = name.rsplit_once('/').unwrap_or((name, ""));
679 let cell = Cell { ns: ns.to_string(), fn_name: f.to_string(), fn_hash: b.fn_hash.clone(), args: args.clone() };
680 self.foreign.ensure_cell(&cell).map_err(ForeignError::eval)?;
681 Ok(())
682 }
683}
684
685impl Inputs for Through<'_> {
686 fn read(&mut self, fn_name: &str, args: &Args) -> Result<Scalar, EvalError> {
687 self.pre(fn_name, args, None)?;
688 self.inner.read(fn_name, args)
689 }
690
691 fn read_cell(&mut self, fn_name: &str, args: &Args) -> Result<Input, EvalError> {
692 self.pre(fn_name, args, None)?;
693 self.inner.read_cell(fn_name, args)
694 }
695
696 fn read_asof(&mut self, fn_name: &str, args: &Args, t: &str) -> Result<Input, EvalError> {
697 self.pre(fn_name, args, Some(t))?;
698 self.inner.read_asof(fn_name, args, t)
699 }
700
701 fn read_slice(&mut self, fn_name: &str, pattern: &SlicePattern) -> Result<Vec<Member>, EvalError> {
702 if self.foreign.is_foreign(fn_name) {
703 self.foreign.ensure_name(fn_name).map_err(ForeignError::eval)?;
704 if let Some(b) = self.inner.binding_peek(fn_name, None)? {
705 if b.descriptor.lang == "stored" {
706 return Err(ForeignError::unavailable(format!(
707 "{fn_name}: slices of foreign stored functions are not read in 0.1.0"
708 ))
709 .eval());
710 }
711 }
712 }
713 self.inner.read_slice(fn_name, pattern)
714 }
715
716 fn read_versions(&mut self, fn_name: &str, args: &Args, from: &str, to: &str) -> Result<Vec<Input>, EvalError> {
717 self.pre(fn_name, args, None)?;
718 self.inner.read_versions(fn_name, args, from, to)
719 }
720
721 fn binding(&mut self, fn_name: &str, at: Option<&str>) -> Result<Option<FnBinding>, EvalError> {
722 self.foreign.ensure_name(fn_name).map_err(ForeignError::eval)?;
723 self.inner.binding(fn_name, at)
724 }
725
726 fn asof(&mut self) -> String {
727 self.inner.asof()
728 }
729
730 fn binding_peek(&mut self, fn_name: &str, at: Option<&str>) -> Result<Option<FnBinding>, EvalError> {
731 self.foreign.ensure_name(fn_name).map_err(ForeignError::eval)?;
732 self.inner.binding_peek(fn_name, at)
733 }
734
735 fn asof_compare(&mut self, t: &str) -> Result<std::cmp::Ordering, EvalError> {
736 self.inner.asof_compare(t)
737 }
738
739 fn read_blob(&mut self, sha256: &str, length: u64) -> Result<Vec<u8>, EvalError> {
740 self.inner.read_blob(sha256, length)
741 }
742}