1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use sapio::contract::DynamicContract;
use sapio::contract::*;
use sapio::*;
use schemars::*;
use serde::*;
struct D<'a> {
v: Vec<fn() -> Option<actions::ThenFunc<'a, D<'a>>>>,
}
impl AnyContract for D<'static> {
type StatefulArguments = ();
type Ref = Self;
fn then_fns<'a>(&'a self) -> &'a [fn() -> Option<actions::ThenFunc<'a, Self>>]
where
Self::Ref: 'a,
{
&self.v
}
fn finish_or_fns<'a>(
&'a self,
) -> &'a [fn() -> Option<actions::FinishOrFunc<'a, Self, Self::StatefulArguments>>] {
&[]
}
fn finish_fns<'a>(&'a self) -> &'a [fn() -> Option<actions::Guard<Self>>] {
&[]
}
fn get_inner_ref<'a>(&'a self) -> &Self {
self
}
}
#[derive(JsonSchema, Deserialize)]
pub struct DynamicExample;
impl DynamicExample {
then! {next |s, ctx| {
let v:
Vec<fn() -> Option<actions::ThenFunc<'static, D<'static>>>>
= vec![];
let d : D = D{v};
let d2 = DynamicContract::<(), String> {
then: vec![|| None, || Some(sapio::contract::actions::ThenFunc{guard: &[], func: |_s, _ctx| Err(CompilationError::TerminateCompilation)})],
finish: vec![],
finish_or: vec![],
data: "E.g., Create a Vault".into(),
};
ctx.template()
.add_output(ctx.funds()/2, &d, None)?
.add_output(ctx.funds()/2, &d2, None)?
.into()
}}
}
impl Contract for DynamicExample {
declare! {then, Self::next}
declare! {non updatable}
}