snops_common/
action_models.rs1use std::str::FromStr;
2
3use indexmap::{IndexMap, IndexSet};
4use serde::{Deserialize, Serialize};
5
6use crate::{
7 key_source::KeySource,
8 node_targets::{NodeTarget, NodeTargets},
9 state::{CannonId, DocHeightRequest, InternedId},
10};
11
12#[derive(Deserialize, Serialize, Clone)]
13pub struct WithTargets<T = ()>
14where
15 T: Serialize,
16{
17 pub nodes: NodeTargets,
18 #[serde(flatten)]
19 pub data: T,
20}
21
22impl From<Vec<NodeTarget>> for WithTargets<()> {
23 fn from(nodes: Vec<NodeTarget>) -> Self {
24 Self {
25 nodes: NodeTargets::from(nodes),
26 data: (),
27 }
28 }
29}
30impl From<NodeTargets> for WithTargets<()> {
31 fn from(nodes: NodeTargets) -> Self {
32 Self { nodes, data: () }
33 }
34}
35
36fn committee_0_key() -> KeySource {
37 KeySource::Committee(Some(0))
38}
39
40fn credits_aleo() -> String {
41 "credits.aleo".to_owned()
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(rename_all = "snake_case")]
46pub struct ExecuteAction {
47 #[serde(default = "committee_0_key")]
50 pub private_key: KeySource,
51 pub fee_private_key: Option<KeySource>,
54 #[serde(default = "credits_aleo")]
56 pub program: String,
57 pub function: String,
59 #[serde(default)]
61 pub cannon: CannonId,
62 pub inputs: Vec<AleoValue>,
64 #[serde(default)]
66 pub priority_fee: Option<u64>,
67 #[serde(default)]
69 pub fee_record: Option<String>,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(rename_all = "snake_case")]
74pub struct DeployAction {
75 #[serde(default = "committee_0_key")]
78 pub private_key: KeySource,
79 pub fee_private_key: Option<KeySource>,
82 pub program: String,
84 #[serde(default)]
86 pub cannon: CannonId,
87 #[serde(default)]
89 pub priority_fee: Option<u64>,
90 #[serde(default)]
92 pub fee_record: Option<String>,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum AleoValue {
98 Key(KeySource),
100 Other(String),
102}
103
104impl FromStr for AleoValue {
105 type Err = String;
106
107 fn from_str(s: &str) -> Result<Self, Self::Err> {
108 Ok(KeySource::from_str(s)
109 .map(AleoValue::Key)
110 .unwrap_or_else(|_| AleoValue::Other(s.to_owned())))
111 }
112}
113
114#[derive(Serialize, Deserialize, Debug, Clone)]
115pub struct Reconfig {
116 #[serde(default, skip_serializing_if = "Option::is_none")]
117 pub online: Option<bool>,
118 #[serde(default, skip_serializing_if = "Option::is_none")]
119 pub height: Option<DocHeightRequest>,
120 #[serde(default, skip_serializing_if = "Option::is_none")]
121 pub peers: Option<NodeTargets>,
122 #[serde(default, skip_serializing_if = "Option::is_none")]
123 pub validators: Option<NodeTargets>,
124 #[serde(default, skip_serializing_if = "Option::is_none")]
125 pub binary: Option<InternedId>,
126 #[serde(default, skip_serializing_if = "Option::is_none")]
127 pub private_key: Option<KeySource>,
128 #[serde(default, skip_serializing_if = "Option::is_none")]
129 pub set_env: Option<IndexMap<String, String>>,
130 #[serde(default, skip_serializing_if = "Option::is_none")]
131 pub del_env: Option<IndexSet<String>>,
132}