Skip to content

Commit

Permalink
Update Jobs Runtime API (#350)
Browse files Browse the repository at this point in the history
* Update JobsApi trait and add
RpcResponsePhaseOneResult struct

* fix clippy
  • Loading branch information
shekohex authored Dec 18, 2023
1 parent d71eae1 commit b37a913
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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

0 comments on commit b37a913

Please sign in to comment.