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

feat: constructors for Tangle and EVM #447

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
583 changes: 410 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

Submodule forge-std updated 1 files
+1 −1 package.json
7 changes: 2 additions & 5 deletions blueprints/incredible-squaring-eigenlayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ async fn main() {
client: aggregator_client,
env: env.clone(),
};
let x_square_eigen = XsquareEigenEventHandler {
ctx,
contract: contract.clone(),
contract_instance: Default::default(),
};

let x_square_eigen = XsquareEigenEventHandler::new(contract.clone(), ctx);

let aggregator_context = AggregatorContext::new(
server_address,
Expand Down
6 changes: 1 addition & 5 deletions blueprints/incredible-squaring-symbiotic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ async fn main() {
provider,
);

let x_square = blueprint::XsquareEventHandler {
context: blueprint::MyContext {},
contract: contract.clone(),
contract_instance: Default::default(),
};
let x_square = blueprint::XsquareEventHandler::new(contract, blueprint::MyContext {});

info!("~~~ Executing the incredible squaring blueprint ~~~");
let symb_config = SymbioticConfig::default();
Expand Down
2 changes: 1 addition & 1 deletion blueprints/incredible-squaring/contracts/lib/forge-std
Submodule forge-std updated 1 files
+1 −1 package.json
17 changes: 6 additions & 11 deletions blueprints/incredible-squaring/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::{eyre::eyre, Result};
use color_eyre::Result;
use gadget_sdk::info;
use gadget_sdk::runners::tangle::TangleConfig;
use gadget_sdk::runners::BlueprintRunner;
Expand All @@ -7,17 +7,12 @@ use incredible_squaring_blueprint as blueprint;

#[gadget_sdk::main(env)]
async fn main() {
let client = env.client().await.map_err(|e| eyre!(e))?;
let signer = env.first_sr25519_signer().map_err(|e| eyre!(e))?;
let x_square = blueprint::XsquareEventHandler::new(&env, blueprint::MyContext).await?;

info!("Starting the event watcher for {} ...", signer.account_id());

let x_square = blueprint::XsquareEventHandler {
service_id: env.service_id().expect("No service ID found"),
context: blueprint::MyContext,
client,
signer,
};
info!(
"Starting the event watcher for {} ...",
x_square.signer.account_id()
);

info!("~~~ Executing the incredible squaring blueprint ~~~");
let tangle_config = TangleConfig::default();
Expand Down
20 changes: 6 additions & 14 deletions blueprints/tangle-raw-event-listener/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
use color_eyre::{eyre::eyre, Result};
use color_eyre::Result;
use gadget_sdk::info;
use gadget_sdk::runners::{tangle::TangleConfig, BlueprintRunner};
use gadget_sdk::tangle_subxt::subxt::tx::Signer;
use tangle_raw_event_listener_blueprint as blueprint;

#[gadget_sdk::main(env)]
async fn main() {
let client = env.client().await.map_err(|e| eyre!(e))?;
let signer = env.first_sr25519_signer().map_err(|e| eyre!(e))?;

info!("Starting the event watcher for {} ...", signer.account_id());

let x_square = blueprint::RawEventHandler {
service_id: env.service_id().expect("No service ID found"),
context: blueprint::MyContext,
client,
signer,
};

let x_square = blueprint::RawEventHandler::new(&env, blueprint::MyContext).await?;
let tangle_config = TangleConfig::default();

info!("~~~ Executing the incredible squaring blueprint ~~~");
info!(
"~~~ Executing the incredible squaring blueprint for {:?} ~~~",
x_square.signer.address()
);
BlueprintRunner::new(tangle_config, env)
.job(x_square)
.run()
Expand Down
22 changes: 0 additions & 22 deletions blueprints/tangle-raw/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions blueprints/tangle-raw/build.rs

This file was deleted.

24 changes: 0 additions & 24 deletions blueprints/tangle-raw/src/lib.rs

This file was deleted.

37 changes: 0 additions & 37 deletions blueprints/tangle-raw/src/main.rs

This file was deleted.

51 changes: 0 additions & 51 deletions macros/blueprint-proc-macro/src/event_listener/tangle.rs

This file was deleted.

39 changes: 27 additions & 12 deletions macros/blueprint-proc-macro/src/job.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::event_listener::evm::{
generate_evm_event_handler, get_evm_instance_data, get_evm_job_processor_wrapper,
use crate::shared::{pascal_case, type_to_field_type};
use crate::special_impls::evm::{
generate_evm_specific_impl, get_evm_instance_data, get_evm_job_processor_wrapper,
};
use crate::event_listener::tangle::{
generate_additional_tangle_logic, get_tangle_job_processor_wrapper,
use crate::special_impls::tangle::{
generate_tangle_specific_impl, get_tangle_job_processor_wrapper,
};
use crate::shared::{pascal_case, type_to_field_type};
use gadget_blueprint_proc_macro_core::{FieldType, JobDefinition, JobMetadata};
use indexmap::{IndexMap, IndexSet};
use proc_macro::TokenStream;
Expand Down Expand Up @@ -77,7 +77,13 @@ pub(crate) fn job_impl(args: &JobArgs, input: &ItemFn) -> syn::Result<TokenStrea
proc_macro2::TokenStream::default()
} else {
// Specialized code for the event workflow or otherwise
generate_additional_logic(input, args, SUFFIX)
generate_additional_logic(
input,
&args.event_listener,
SUFFIX,
&param_map,
&args.params,
)
};

let autogen_struct = if args.skip_codegen {
Expand Down Expand Up @@ -626,16 +632,21 @@ fn get_asyncness(input: &ItemFn) -> proc_macro2::TokenStream {
#[allow(clippy::too_many_lines)]
pub fn generate_additional_logic(
input: &ItemFn,
job_args: &JobArgs,
event_listener_args: &EventListenerArgs,
suffix: &str,
param_map: &IndexMap<Ident, Type>,
job_params: &[Ident],
) -> proc_macro2::TokenStream {
let (_fn_name, _fn_name_string, struct_name) = generate_fn_name_and_struct(input, suffix);
let event_listener_args = &job_args.event_listener;

match job_args.event_listener.get_event_listener().listener_type {
ListenerType::Evm => generate_evm_event_handler(&struct_name, event_listener_args),
match event_listener_args.get_event_listener().listener_type {
ListenerType::Evm => {
generate_evm_specific_impl(&struct_name, event_listener_args, param_map, job_params)
}

ListenerType::Tangle => generate_additional_tangle_logic(&struct_name),
ListenerType::Tangle => {
generate_tangle_specific_impl(&struct_name, param_map, job_params, event_listener_args)
}

ListenerType::Custom => proc_macro2::TokenStream::default(),
}
Expand Down Expand Up @@ -1014,7 +1025,11 @@ impl EventListenerArgs {
let index = Index::from(i);
match self.get_event_listener().listener_type {
ListenerType::Tangle => {
crate::tangle::field_type_to_param_token(&ident, t, panic_on_decode_fail)
crate::special_impls::tangle::field_type_to_param_token(
&ident,
t,
panic_on_decode_fail,
)
}
ListenerType::Evm => {
quote! {
Expand Down
5 changes: 1 addition & 4 deletions macros/blueprint-proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ mod report;
/// Shared utilities for the Blueprint Macros
mod shared;

mod event_listener;

/// Utilities for Tangle Blueprint macro generation
mod tangle;
mod special_impls;

mod sdk_main;

Expand Down
29 changes: 18 additions & 11 deletions macros/blueprint-proc-macro/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::job::{
declared_params_to_field_types, generate_autogen_struct, get_current_call_id_field_name,
get_job_id_field_name, get_result_type, EventListenerArgs, ResultsKind,
declared_params_to_field_types, generate_additional_logic, generate_autogen_struct,
get_current_call_id_field_name, get_job_id_field_name, get_result_type, EventListenerArgs,
ResultsKind,
};
use crate::shared::{pascal_case, type_to_field_type};
use gadget_blueprint_proc_macro_core::{
Expand Down Expand Up @@ -131,15 +132,20 @@ pub(crate) fn report_impl(args: &ReportArgs, input: &ItemFn) -> syn::Result<Toke
suffix,
&event_listener_calls,
);
/*let event_handler_gen = if args.skip_codegen {
proc_macro2::TokenStream::new()

// Generate Event Workflow, if not being skipped
let additional_specific_logic = if args.skip_codegen {
proc_macro2::TokenStream::default()
} else {
if let ReportType::QoS = args.report_type {
generate_qos_report_event_handler(args, input, &params_type, &result_type)
} else {
proc_macro2::TokenStream::new()
}
};*/
// Specialized code for the event workflow or otherwise
generate_additional_logic(
input,
&args.event_listeners,
suffix,
&param_types,
&args.params,
)
};

let call_id_static_name = get_current_call_id_field_name(input);
let job_id = if let Some(job_id) = job_id {
Expand Down Expand Up @@ -171,6 +177,8 @@ pub(crate) fn report_impl(args: &ReportArgs, input: &ItemFn) -> syn::Result<Toke
#[allow(unused_variables)]
#input

#additional_specific_logic

#(#event_listener_gen)*
};

Expand Down Expand Up @@ -203,7 +211,6 @@ pub(crate) struct ReportArgs {
verifier: Verifier,
/// Optional: Event handler type for the report.
/// `#[report(event_handler_type = "tangle")]`
#[allow(dead_code)]
pub(crate) event_listeners: EventListenerArgs,
/// Optional: Skip code generation for this report.
/// `#[report(skip_codegen)]`
Expand Down
Loading
Loading