Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/declarations/mission_control/mission_control.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface CyclesMonitoringStartConfig {
orbiters_strategy: [] | [SegmentsMonitoringStrategy];
mission_control_strategy: [] | [CyclesMonitoringStrategy];
satellites_strategy: [] | [SegmentsMonitoringStrategy];
ufos_strategy: [] | [SegmentsMonitoringStrategy];
}
export interface CyclesMonitoringStatus {
monitored_ids: Array<Principal>;
Expand All @@ -61,6 +62,7 @@ export interface CyclesMonitoringStopConfig {
satellite_ids: [] | [Array<Principal>];
try_mission_control: [] | [boolean];
orbiter_ids: [] | [Array<Principal>];
ufo_ids: [] | [Array<Principal>];
}
export type CyclesMonitoringStrategy = { BelowThreshold: CyclesThreshold };
export interface CyclesThreshold {
Expand Down Expand Up @@ -200,6 +202,13 @@ export type TransferError_1 =
| { CreatedInFuture: { ledger_time: bigint } }
| { TooOld: null }
| { InsufficientFunds: { balance: bigint } };
export interface Ufo {
updated_at: bigint;
metadata: Array<[string, string]>;
created_at: bigint;
settings: [] | [Settings];
ufo_id: Principal;
}
export interface User {
updated_at: bigint;
metadata: Array<[string, string]>;
Expand Down Expand Up @@ -233,6 +242,7 @@ export interface _SERVICE {
list_mission_control_controllers: ActorMethod<[], Array<[Principal, AccessKey]>>;
list_orbiters: ActorMethod<[], Array<[Principal, Orbiter]>>;
list_satellites: ActorMethod<[], Array<[Principal, Satellite]>>;
list_ufos: ActorMethod<[], Array<[Principal, Ufo]>>;
set_config: ActorMethod<[[] | [Config]], undefined>;
set_metadata: ActorMethod<[Array<[string, string]>], undefined>;
set_mission_control_controllers: ActorMethod<[Array<Principal>, SetAccessKey], undefined>;
Expand All @@ -248,11 +258,14 @@ export interface _SERVICE {
[Array<Principal>, Array<Principal>, SetAccessKey],
undefined
>;
set_ufo: ActorMethod<[Principal, [] | [string]], Ufo>;
set_ufo_metadata: ActorMethod<[Principal, Array<[string, string]>], Ufo>;
start_monitoring: ActorMethod<[], undefined>;
stop_monitoring: ActorMethod<[], undefined>;
top_up: ActorMethod<[Principal, Tokens], undefined>;
unset_orbiter: ActorMethod<[Principal], undefined>;
unset_satellite: ActorMethod<[Principal], undefined>;
unset_ufo: ActorMethod<[Principal], undefined>;
update_and_start_monitoring: ActorMethod<[MonitoringStartConfig], undefined>;
update_and_stop_monitoring: ActorMethod<[MonitoringStopConfig], undefined>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ export const idlFactory = ({ IDL }) => {
scope: AccessKeyScope,
expires_at: IDL.Opt(IDL.Nat64)
});
const Ufo = IDL.Record({
updated_at: IDL.Nat64,
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
created_at: IDL.Nat64,
settings: IDL.Opt(Settings),
ufo_id: IDL.Principal
});
const SetAccessKey = IDL.Record({
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
kind: IDL.Opt(AccessKeyKind),
Expand All @@ -193,15 +200,17 @@ export const idlFactory = ({ IDL }) => {
const CyclesMonitoringStartConfig = IDL.Record({
orbiters_strategy: IDL.Opt(SegmentsMonitoringStrategy),
mission_control_strategy: IDL.Opt(CyclesMonitoringStrategy),
satellites_strategy: IDL.Opt(SegmentsMonitoringStrategy)
satellites_strategy: IDL.Opt(SegmentsMonitoringStrategy),
ufos_strategy: IDL.Opt(SegmentsMonitoringStrategy)
});
const MonitoringStartConfig = IDL.Record({
cycles_config: IDL.Opt(CyclesMonitoringStartConfig)
});
const CyclesMonitoringStopConfig = IDL.Record({
satellite_ids: IDL.Opt(IDL.Vec(IDL.Principal)),
try_mission_control: IDL.Opt(IDL.Bool),
orbiter_ids: IDL.Opt(IDL.Vec(IDL.Principal))
orbiter_ids: IDL.Opt(IDL.Vec(IDL.Principal)),
ufo_ids: IDL.Opt(IDL.Vec(IDL.Principal))
});
const MonitoringStopConfig = IDL.Record({
cycles_config: IDL.Opt(CyclesMonitoringStopConfig)
Expand Down Expand Up @@ -238,6 +247,7 @@ export const idlFactory = ({ IDL }) => {
),
list_orbiters: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Orbiter))], []),
list_satellites: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Satellite))], []),
list_ufos: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Ufo))], []),
set_config: IDL.Func([IDL.Opt(Config)], [], []),
set_metadata: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [], []),
set_mission_control_controllers: IDL.Func([IDL.Vec(IDL.Principal), SetAccessKey], [], []),
Expand All @@ -263,11 +273,14 @@ export const idlFactory = ({ IDL }) => {
[],
[]
),
set_ufo: IDL.Func([IDL.Principal, IDL.Opt(IDL.Text)], [Ufo], []),
set_ufo_metadata: IDL.Func([IDL.Principal, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [Ufo], []),
start_monitoring: IDL.Func([], [], []),
stop_monitoring: IDL.Func([], [], []),
top_up: IDL.Func([IDL.Principal, Tokens], [], []),
unset_orbiter: IDL.Func([IDL.Principal], [], []),
unset_satellite: IDL.Func([IDL.Principal], [], []),
unset_ufo: IDL.Func([IDL.Principal], [], []),
update_and_start_monitoring: IDL.Func([MonitoringStartConfig], [], []),
update_and_stop_monitoring: IDL.Func([MonitoringStopConfig], [], [])
});
Expand Down
17 changes: 15 additions & 2 deletions src/declarations/mission_control/mission_control.factory.did.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ export const idlFactory = ({ IDL }) => {
scope: AccessKeyScope,
expires_at: IDL.Opt(IDL.Nat64)
});
const Ufo = IDL.Record({
updated_at: IDL.Nat64,
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
created_at: IDL.Nat64,
settings: IDL.Opt(Settings),
ufo_id: IDL.Principal
});
const SetAccessKey = IDL.Record({
metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
kind: IDL.Opt(AccessKeyKind),
Expand All @@ -193,15 +200,17 @@ export const idlFactory = ({ IDL }) => {
const CyclesMonitoringStartConfig = IDL.Record({
orbiters_strategy: IDL.Opt(SegmentsMonitoringStrategy),
mission_control_strategy: IDL.Opt(CyclesMonitoringStrategy),
satellites_strategy: IDL.Opt(SegmentsMonitoringStrategy)
satellites_strategy: IDL.Opt(SegmentsMonitoringStrategy),
ufos_strategy: IDL.Opt(SegmentsMonitoringStrategy)
});
const MonitoringStartConfig = IDL.Record({
cycles_config: IDL.Opt(CyclesMonitoringStartConfig)
});
const CyclesMonitoringStopConfig = IDL.Record({
satellite_ids: IDL.Opt(IDL.Vec(IDL.Principal)),
try_mission_control: IDL.Opt(IDL.Bool),
orbiter_ids: IDL.Opt(IDL.Vec(IDL.Principal))
orbiter_ids: IDL.Opt(IDL.Vec(IDL.Principal)),
ufo_ids: IDL.Opt(IDL.Vec(IDL.Principal))
});
const MonitoringStopConfig = IDL.Record({
cycles_config: IDL.Opt(CyclesMonitoringStopConfig)
Expand Down Expand Up @@ -238,6 +247,7 @@ export const idlFactory = ({ IDL }) => {
),
list_orbiters: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Orbiter))], ['query']),
list_satellites: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Satellite))], ['query']),
list_ufos: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Ufo))], ['query']),
set_config: IDL.Func([IDL.Opt(Config)], [], []),
set_metadata: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [], []),
set_mission_control_controllers: IDL.Func([IDL.Vec(IDL.Principal), SetAccessKey], [], []),
Expand All @@ -263,11 +273,14 @@ export const idlFactory = ({ IDL }) => {
[],
[]
),
set_ufo: IDL.Func([IDL.Principal, IDL.Opt(IDL.Text)], [Ufo], []),
set_ufo_metadata: IDL.Func([IDL.Principal, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [Ufo], []),
start_monitoring: IDL.Func([], [], []),
stop_monitoring: IDL.Func([], [], []),
top_up: IDL.Func([IDL.Principal, Tokens], [], []),
unset_orbiter: IDL.Func([IDL.Principal], [], []),
unset_satellite: IDL.Func([IDL.Principal], [], []),
unset_ufo: IDL.Func([IDL.Principal], [], []),
update_and_start_monitoring: IDL.Func([MonitoringStartConfig], [], []),
update_and_stop_monitoring: IDL.Func([MonitoringStopConfig], [], [])
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ export const createSatelliteWizard = async ({
strategy: monitoringStrategy,
ids: [canisterId]
}),
orbiters_strategy: toNullable()
orbiters_strategy: toNullable(),
ufos_strategy: toNullable()
})
}
});
Expand Down Expand Up @@ -536,7 +537,8 @@ export const createOrbiterWizard = async ({
orbiters_strategy: toNullable({
strategy: monitoringStrategy,
ids: [canisterId]
})
}),
ufos_strategy: toNullable()
})
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ const setMonitoringCyclesStrategy = async ({
strategy: moduleStrategy
}
]
: []
: [],
// TODO: support for ufo
ufos_strategy: toNullable()
})
}
});
Expand Down Expand Up @@ -398,7 +400,9 @@ const stopMonitoringCycles = async ({
cycles_config: toNullable({
try_mission_control: toNullable(stopMissionControl),
satellite_ids: satellites.length > 0 ? toNullable(satellites) : [],
orbiter_ids: orbiters.length > 0 ? toNullable(orbiters) : []
orbiter_ids: orbiters.length > 0 ? toNullable(orbiters) : [],
// TODO: support for ufo
ufo_ids: toNullable()
})
}
});
Expand Down
1 change: 1 addition & 0 deletions src/libs/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod state {
pub type MissionControlId = SegmentId;
pub type SatelliteId = SegmentId;
pub type OrbiterId = SegmentId;
pub type UfoId = SegmentId;

pub type Metadata = HashMap<String, String>;

Expand Down
13 changes: 13 additions & 0 deletions src/mission_control/mission_control.did
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type CyclesMonitoringStartConfig = record {
orbiters_strategy : opt SegmentsMonitoringStrategy;
mission_control_strategy : opt CyclesMonitoringStrategy;
satellites_strategy : opt SegmentsMonitoringStrategy;
ufos_strategy : opt SegmentsMonitoringStrategy;
};
type CyclesMonitoringStatus = record {
monitored_ids : vec principal;
Expand All @@ -41,6 +42,7 @@ type CyclesMonitoringStopConfig = record {
satellite_ids : opt vec principal;
try_mission_control : opt bool;
orbiter_ids : opt vec principal;
ufo_ids : opt vec principal;
};
type CyclesMonitoringStrategy = variant { BelowThreshold : CyclesThreshold };
type CyclesThreshold = record { fund_cycles : nat; min_cycles : nat };
Expand Down Expand Up @@ -155,6 +157,13 @@ type TransferError_1 = variant {
TooOld;
InsufficientFunds : record { balance : nat };
};
type Ufo = record {
updated_at : nat64;
metadata : vec record { text; text };
created_at : nat64;
settings : opt Settings;
ufo_id : principal;
};
type User = record {
updated_at : nat64;
metadata : vec record { text; text };
Expand Down Expand Up @@ -189,6 +198,7 @@ service : (InitMissionControlArgs) -> {
) query;
list_orbiters : () -> (vec record { principal; Orbiter }) query;
list_satellites : () -> (vec record { principal; Satellite }) query;
list_ufos : () -> (vec record { principal; Ufo }) query;
set_config : (opt Config) -> ();
set_metadata : (vec record { text; text }) -> ();
set_mission_control_controllers : (vec principal, SetAccessKey) -> ();
Expand All @@ -204,11 +214,14 @@ service : (InitMissionControlArgs) -> {
vec principal,
SetAccessKey,
) -> ();
set_ufo : (principal, opt text) -> (Ufo);
set_ufo_metadata : (principal, vec record { text; text }) -> (Ufo);
start_monitoring : () -> ();
stop_monitoring : () -> ();
top_up : (principal, Tokens) -> ();
unset_orbiter : (principal) -> ();
unset_satellite : (principal) -> ();
unset_ufo : (principal) -> ();
update_and_start_monitoring : (MonitoringStartConfig) -> ();
update_and_stop_monitoring : (MonitoringStopConfig) -> ();
}
1 change: 1 addition & 0 deletions src/mission_control/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ mod mgmt;
mod monitoring;
mod orbiters;
mod satellites;
mod ufos;
mod wallet;
27 changes: 27 additions & 0 deletions src/mission_control/src/api/ufos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::factory::store::{get_ufos, set_ufo_metadata as set_ufo_metadata_store};
use crate::factory::ufo::{attach_ufo, detach_ufo};
use crate::guards::caller_is_user_or_admin_controller;
use crate::types::state::{Ufo, Ufos};
use ic_cdk_macros::{query, update};
use junobuild_shared::ic::UnwrapOrTrap;
use junobuild_shared::types::state::{Metadata, UfoId};

#[query(guard = "caller_is_user_or_admin_controller")]
fn list_ufos() -> Ufos {
get_ufos()
}

#[update(guard = "caller_is_user_or_admin_controller")]
fn set_ufo(ufo_id: UfoId, name: Option<String>) -> Ufo {
attach_ufo(&ufo_id, &name).unwrap_or_trap()
}

#[update(guard = "caller_is_user_or_admin_controller")]
fn unset_ufo(ufo_id: UfoId) {
detach_ufo(&ufo_id).unwrap_or_trap()
}

#[update(guard = "caller_is_user_or_admin_controller")]
fn set_ufo_metadata(ufo_id: UfoId, metadata: Metadata) -> Ufo {
set_ufo_metadata_store(&ufo_id, &metadata).unwrap_or_trap()
}
1 change: 1 addition & 0 deletions src/mission_control/src/factory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mod msg;
pub mod orbiter;
pub mod satellite;
pub mod store;
pub mod ufo;
1 change: 1 addition & 0 deletions src/mission_control/src/factory/msg.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub const ORBITER_NOT_FOUND: &str = "Orbiter not found or not owned by this mission control.";
pub const SATELLITE_NOT_FOUND: &str = "Satellite not found or not owned by this mission control.";
pub const UFO_NOT_FOUND: &str = "UFO not found or not owned by this mission control.";
64 changes: 62 additions & 2 deletions src/mission_control/src/factory/store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::memory::manager::STATE;
use crate::types::core::Segment;
use crate::types::state::{Orbiter, Orbiters, Satellite, Satellites};
use junobuild_shared::types::state::{Metadata, OrbiterId, SatelliteId};
use crate::types::state::{Orbiter, Orbiters, Satellite, Satellites, Ufo, Ufos};
use junobuild_shared::types::state::{Metadata, OrbiterId, SatelliteId, UfoId};
use std::collections::HashMap;
use std::hash::Hash;

Expand Down Expand Up @@ -79,6 +79,66 @@ pub fn set_orbiter_metadata(
})
}

// ---------------------------------------------------------
// UFOs
// ---------------------------------------------------------

pub fn get_ufos() -> Ufos {
STATE.with(|state| state.borrow().heap.ufos.clone().unwrap_or_default())
}

pub fn get_ufo(ufo_id: &UfoId) -> Option<Ufo> {
STATE.with(|state| {
state
.borrow()
.heap
.ufos
.as_ref()
.and_then(|ufos| get_segment_impl(ufo_id, ufos))
})
}

pub fn delete_ufo(ufo_id: &UfoId) -> Option<Ufo> {
STATE.with(|state| {
delete_segment_impl(
ufo_id,
state
.borrow_mut()
.heap
.ufos
.get_or_insert_with(HashMap::new),
)
})
}

pub fn add_ufo(ufo_id: &UfoId, name: &Option<String>) -> Ufo {
STATE.with(|state| {
add_segment_impl(
ufo_id,
&Ufo::from(ufo_id, name),
state
.borrow_mut()
.heap
.ufos
.get_or_insert_with(HashMap::new),
)
})
}

pub fn set_ufo_metadata(ufo_id: &UfoId, metadata: &Metadata) -> Result<Ufo, String> {
STATE.with(|state| {
set_metadata_impl(
ufo_id,
metadata,
state
.borrow_mut()
.heap
.ufos
.get_or_insert_with(HashMap::new),
)
})
}

// ---------------------------------------------------------
// Segments
// ---------------------------------------------------------
Expand Down
Loading
Loading