diff --git a/rs/types/management_canister_types/src/http.rs b/rs/types/management_canister_types/src/http.rs index 4de5e3baf1a5..a7d7753981d3 100644 --- a/rs/types/management_canister_types/src/http.rs +++ b/rs/types/management_canister_types/src/http.rs @@ -391,3 +391,100 @@ pub struct CanisterHttpResponsePayload { } impl Payload<'_> for CanisterHttpResponsePayload {} + +/// The result type for the `flexible_http_request` management canister endpoint. +/// +/// ```text +/// type flexible_http_request_result = variant { +/// ok: vec http_request_result; +/// err: flexible_http_request_err; +/// }; +/// ``` +#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)] +pub enum FlexibleHttpRequestResult { + #[serde(rename = "ok")] + Ok(Vec), + #[serde(rename = "err")] + Err(FlexibleHttpRequestErr), +} + +/// The error type returned by `flexible_http_request`. +/// +/// ```text +/// type flexible_http_request_err = record { +/// global_error: opt variant { ... }; +/// node_details : vec record { ... }; +/// message: text; +/// }; +/// ``` +#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)] +pub struct FlexibleHttpRequestErr { + pub global_error: Option, + pub node_details: Vec, + pub message: String, +} + +/// Why the flexible HTTP outcall failed globally. +#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)] +pub enum FlexibleHttpGlobalError { + #[serde(rename = "invalid_parameters")] + InvalidParameters(candid::Reserved), + #[serde(rename = "timeout")] + Timeout(candid::Reserved), + #[serde(rename = "out_of_cycles")] + OutOfCycles(candid::Reserved), + #[serde(rename = "responses_too_large")] + ResponsesTooLarge(candid::Reserved), +} + +/// Per-node detail in a flexible HTTP outcall error. +/// +/// ```text +/// record { +/// node_id: principal; +/// report: http_request_resource_report; +/// error: opt record { code: text; message: text }; +/// } +/// ``` +#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)] +pub struct FlexibleHttpNodeDetail { + pub node_id: candid::Principal, + pub report: HttpRequestResourceReport, + pub error: Option, +} + +/// Per-node resource usage accounting for an HTTP outcall. +/// +/// ```text +/// type http_request_resource_report = record { +/// raw_response_bytes: opt variant { used: nat64; exceeded: reserved }; +/// http_roundtrip_time_ms: opt variant { used: nat64; exceeded: reserved }; +/// transform_instructions: opt variant { used: nat64; exceeded: reserved }; +/// transformed_response_bytes: opt variant { used: nat64; exceeded: reserved }; +/// cycles: opt variant { used: nat; exceeded: reserved }; +/// }; +/// ``` +#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)] +pub struct HttpRequestResourceReport { + pub raw_response_bytes: Option>, + pub http_roundtrip_time_ms: Option>, + pub transform_instructions: Option>, + pub transformed_response_bytes: Option>, + pub cycles: Option>, +} + +/// Tracks whether a resource was used or exceeded its budget. +#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)] +pub enum ResourceUsage { + #[serde(rename = "used")] + Used(T), + #[serde(rename = "exceeded")] + Exceeded(candid::Reserved), +} + +/// Error details from a specific node during a flexible HTTP outcall. +#[derive(Clone, Eq, PartialEq, Hash, Debug, CandidType, Deserialize, Serialize)] +pub struct FlexibleHttpNodeError { + pub code: String, + pub message: String, +} diff --git a/rs/types/management_canister_types/src/lib.rs b/rs/types/management_canister_types/src/lib.rs index adf7c622d2ef..d0e079d175bf 100644 --- a/rs/types/management_canister_types/src/lib.rs +++ b/rs/types/management_canister_types/src/lib.rs @@ -12,9 +12,10 @@ pub use data_size::*; pub use http::{ ALLOWED_HTTP_OUTCALLS_PRICING_VERSIONS, BoundedHttpHeaders, CanisterHttpRequestArgs, CanisterHttpResponsePayload, DEFAULT_HTTP_OUTCALLS_PRICING_VERSION, - FlexibleCanisterHttpRequestArgs, HttpHeader, HttpMethod, PRICING_VERSION_LEGACY, - PRICING_VERSION_PAY_AS_YOU_GO, ReplicationCounts, TransformArgs, TransformContext, - TransformFunc, + FlexibleCanisterHttpRequestArgs, FlexibleHttpGlobalError, FlexibleHttpNodeDetail, + FlexibleHttpNodeError, FlexibleHttpRequestErr, FlexibleHttpRequestResult, HttpHeader, + HttpMethod, HttpRequestResourceReport, PRICING_VERSION_LEGACY, PRICING_VERSION_PAY_AS_YOU_GO, + ReplicationCounts, ResourceUsage, TransformArgs, TransformContext, TransformFunc, }; use ic_base_types::{ CanisterId, EnvironmentVariables, NodeId, NumBytes, PrincipalId, RegistryVersion, SnapshotId,