Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Jobs Runtime API #350

Merged
merged 2 commits into from
Dec 18, 2023
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
31 changes: 30 additions & 1 deletion pallets/jobs/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use parity_scale_codec::Codec;
use sp_runtime::{traits::MaybeDisplay, Serialize};

pub use tangle_primitives::jobs::RpcResponseJobsData;
use tangle_primitives::jobs::{JobId, JobKey, RpcResponseJobsData, RpcResponsePhaseOneResult};

sp_api::decl_runtime_apis! {
pub trait JobsApi<AccountId> where
Expand All @@ -42,5 +42,34 @@ sp_api::decl_runtime_apis! {
/// Returns a `Result` containing a vector of `RpcResponseJobsData<AccountId>` if the
/// operation is successful
fn query_jobs_by_validator(validator: AccountId) -> Result<Vec<RpcResponseJobsData<AccountId>>, String>;
/// Queries a job by its key and ID.
///
/// # Arguments
///
/// * `job_key` - The key of the job.
/// * `job_id` - The ID of the job.
///
/// # Returns
///
/// An optional `RpcResponseJobsData` containing the account ID of the job.
fn query_job_by_id(job_key: JobKey, job_id: JobId) -> Option<RpcResponseJobsData<AccountId>>;

/// Queries the phase one result of a job by its key and ID.
///
/// # Arguments
///
/// * `job_key` - The key of the job.
/// * `job_id` - The ID of the job.
///
/// # Returns
///
/// An `Option` containing the phase one result of the job, wrapped in an `RpcResponsePhaseOneResult`.
fn query_phase_one_by_id(job_key: JobKey, job_id: JobId) -> Option<RpcResponsePhaseOneResult<AccountId>>;

/// Queries next job ID.
///
/// # Returns
/// Next job ID.
fn query_next_job_id() -> JobId;
}
}
15 changes: 15 additions & 0 deletions primitives/src/types/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,21 @@ pub struct RpcResponseJobsData<AccountId> {
pub key: Option<Vec<u8>>,
}

#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct RpcResponsePhaseOneResult<AccountId> {
/// The owner's account ID.
pub owner: AccountId,
/// The type of the job result.
pub result: Vec<u8>,
/// permitted caller to use this result
pub permitted_caller: Option<AccountId>,
/// Key type if applicable
pub key_type: Option<DkgKeyType>,
/// The type of the job submission.
pub job_type: JobType<AccountId>,
}

#[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum JobResult {
Expand Down
Loading