From b34c6f0e3844d43ac15f4fe4f8a1f3fd124958c0 Mon Sep 17 00:00:00 2001 From: Thomas Braun <38082993+tbraun96@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:02:16 -0500 Subject: [PATCH] fix(blueprint-proc-macro): fix bug where job IDs are not written in order to blueprint.json (#542) * fix(blueprint-proc-macro): fix bug where job IDs are not written in order to the blueprint.json file * lint --- blueprint-metadata/src/lib.rs | 4 ++++ blueprints/incredible-squaring/contracts/lib/tnt-core | 2 +- macros/blueprint-proc-macro-core/src/lib.rs | 1 + macros/blueprint-proc-macro/src/job.rs | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/blueprint-metadata/src/lib.rs b/blueprint-metadata/src/lib.rs index f9d9fd5b4..9ab99df92 100644 --- a/blueprint-metadata/src/lib.rs +++ b/blueprint-metadata/src/lib.rs @@ -152,6 +152,10 @@ fn extract_jobs_from_module<'a>( _ => continue, } } + + // Sort jobs by job_id field + jobs.sort_by(|a, b| a.job_id.cmp(&b.job_id)); + jobs } diff --git a/blueprints/incredible-squaring/contracts/lib/tnt-core b/blueprints/incredible-squaring/contracts/lib/tnt-core index 7ce2100bd..df6d5d6da 160000 --- a/blueprints/incredible-squaring/contracts/lib/tnt-core +++ b/blueprints/incredible-squaring/contracts/lib/tnt-core @@ -1 +1 @@ -Subproject commit 7ce2100bdb57472524a130488dace41a56cf3515 +Subproject commit df6d5d6da3c82217405c408d3c0b11369bb3e5c2 diff --git a/macros/blueprint-proc-macro-core/src/lib.rs b/macros/blueprint-proc-macro-core/src/lib.rs index f32e5ced8..9363ca0e4 100644 --- a/macros/blueprint-proc-macro-core/src/lib.rs +++ b/macros/blueprint-proc-macro-core/src/lib.rs @@ -142,6 +142,7 @@ pub struct ServiceMetadata<'a> { /// It contains the input and output fields of the job with the permitted caller. #[derive(Default, Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct JobDefinition<'a> { + pub job_id: u64, /// The metadata of the job. pub metadata: JobMetadata<'a>, /// These are parameters that are required for this job. diff --git a/macros/blueprint-proc-macro/src/job.rs b/macros/blueprint-proc-macro/src/job.rs index 0907dcabd..e56bec9ed 100644 --- a/macros/blueprint-proc-macro/src/job.rs +++ b/macros/blueprint-proc-macro/src/job.rs @@ -151,7 +151,11 @@ pub fn generate_job_const_block( ) -> syn::Result { let (fn_name_string, job_def_name, job_id_name) = get_job_id_field_name(input); // Creates Job Definition using input parameters + let job_id_as_u64 = u64::from_str(&job_id.to_string()).map_err(|err| { + syn::Error::new_spanned(job_id, format!("Failed to convert job id to u64: {err}")) + })?; let job_def = JobDefinition { + job_id: job_id_as_u64, metadata: JobMetadata { name: fn_name_string.clone().into(), // filled later on during the rustdoc gen.