zombienet_orchestrator/shared/
types.rs1use std::{
2 collections::HashMap,
3 net::TcpListener,
4 path::PathBuf,
5 sync::{Arc, RwLock},
6};
7
8use configuration::shared::{
9 resources::Resources,
10 types::{Arg, AssetLocation, Command, Image, Port},
11};
12use serde::{Deserialize, Serialize};
13
14pub type Accounts = HashMap<String, NodeAccount>;
15
16#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
17pub struct NodeAccount {
18 pub address: String,
19 pub public_key: String,
20}
21
22impl NodeAccount {
23 pub fn new(addr: impl Into<String>, pk: impl Into<String>) -> Self {
24 Self {
25 address: addr.into(),
26 public_key: pk.into(),
27 }
28 }
29}
30
31#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
32pub struct NodeAccounts {
33 pub seed: String,
34 pub accounts: Accounts,
35}
36
37#[derive(Clone, Default, Debug, Serialize, Deserialize)]
38pub struct ParkedPort(
39 pub(crate) Port,
40 #[serde(skip)] pub(crate) Arc<RwLock<Option<TcpListener>>>,
41);
42
43impl ParkedPort {
44 pub(crate) fn new(port: u16, listener: TcpListener) -> ParkedPort {
45 let listener = Arc::new(RwLock::new(Some(listener)));
46 ParkedPort(port, listener)
47 }
48
49 pub(crate) fn drop_listener(&self) {
50 let mut l = self.1.write().unwrap();
52 *l = None;
53 }
54}
55
56#[derive(Debug, Clone, Default)]
57pub struct ChainDefaultContext<'a> {
58 pub default_command: Option<&'a Command>,
59 pub default_image: Option<&'a Image>,
60 pub default_resources: Option<&'a Resources>,
61 pub default_db_snapshot: Option<&'a AssetLocation>,
62 pub default_args: Vec<&'a Arg>,
63}
64
65#[derive(Debug, Clone)]
66pub struct RegisterParachainOptions {
67 pub id: u32,
68 pub wasm_path: PathBuf,
69 pub state_path: PathBuf,
70 pub node_ws_url: String,
71 pub onboard_as_para: bool,
72 pub seed: Option<[u8; 32]>,
73 pub finalization: bool,
74}
75
76pub struct RuntimeUpgradeOptions {
77 pub wasm: AssetLocation,
79 pub node_name: Option<String>,
81 pub seed: Option<[u8; 32]>,
83}
84
85impl RuntimeUpgradeOptions {
86 pub fn new(wasm: AssetLocation) -> Self {
87 Self {
88 wasm,
89 node_name: None,
90 seed: None,
91 }
92 }
93}
94#[derive(Debug, Clone)]
95pub struct ParachainGenesisArgs {
96 pub genesis_head: String,
97 pub validation_code: String,
98 pub parachain: bool,
99}