soroban_tools/oracle/
impl.rs

1/*
2    Copyright (c) 2023-2024 Frederic Kyung-jin Rezeau (오경진 吳景振)
3
4    This file is part of soroban-kit.
5
6    Licensed under the MIT License, this software is provided "AS IS",
7    no liability assumed. For details, see the LICENSE file in the
8    root directory.
9
10    Author: Fred Kyung-jin Rezeau <fred@litemint.com>
11*/
12
13use soroban_sdk::{contracttype, Address, Env, IntoVal, TryFromVal, Val, Vec};
14
15// Events interface for Oracle contracts.
16pub trait Events<T, V>
17where
18    T: Clone + IntoVal<Env, Val> + TryFromVal<Env, Val>,
19    V: Clone + IntoVal<Env, Val> + TryFromVal<Env, Val>,
20{
21    fn on_request(_env: &Env, _topic: &T, _envelope: &Envelope) {}
22    fn on_sync_receive(_env: &Env, _topic: &T, _envelope: &Envelope, _data: &V) {}
23    fn on_async_receive(_env: &Env, _topic: &T, _envelope: &Envelope, _data: &V) {}
24    fn on_subscribe(_env: &Env, _topic: &T, _envelope: &Envelope) -> Option<V> {
25        None
26    }
27    fn on_publish(env: &Env, _topic: &T, _data: &V, _publisher: &Address) -> Vec<Envelope> {
28        Vec::<Envelope>::new(env)
29    }
30}
31
32// Envelope for cross-contract calls.
33#[contracttype]
34#[derive(Clone, Debug, Eq, PartialEq)]
35pub struct Envelope {
36    pub subscriber: Address,
37    pub broker: Address,
38    pub router: Address,
39}