diff --git a/workflow/examples/PayoutNotification.yaml b/workflow/examples/PayoutNotification.yaml new file mode 100644 index 00000000..803216df --- /dev/null +++ b/workflow/examples/PayoutNotification.yaml @@ -0,0 +1,87 @@ +# ------------------------------------------------------------------------------------------------------- # +# # +# Config file to generate rust code for workflow execution # +# # +# Config file have three different section # +# 1. Tasks # +# 2. Flows # +# 3. WorkFlow # +# # +# Tasks section of config contains list of tasks which refers to actions which needs to be executed # +# Flows section of config contains list of flows which represents order of execution of task # +# Workflow section of config is to define about workflow # +# # +# task hook for generating rust code for actions deployed on openwhisk # +# flow hook for organising order of task execution # + +tasks: + - ->: task + #kind filed spcifies what type of task it is. + #(i.e for now we are focusing on openwhisk actions, future it can be any serverless functions and written in any langunage) + kind: "Polkadot" + name: + "stakingpayout" + #for input struct to provide input for actions + input_args: + - name: "url" + type: "String" + - name: "owner_key" + type: "String" + - name: "address" + type: "String" + - name: "era" + type: "u32" + #for output struct to store output from actions for deserilization + output_args: + - name: "result" + type: "Option" + properties: + chain: "Westend" + operation: "stakingpayout" + + - ->: task + #kind filed spcifies what type of task it is. + #(i.e for now we are focusing on openwhisk actions, future it can be any serverless functions and written in any langunage) + kind: "OpenWhisk" + name: "push_notification" + #for input struct to provide input for actions + input_args: + - name: "token" + type: "String" + - name: "message" + type: "Value" + - name: "result" + type: "Option" + #for output struct to store output from actions for deserilization + output_args: + - name: "action" + type: "String" + properties: + api_host: "https://139.84.142.77:31001" + auth_token: "23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP" + insecure: "true" + namespace: "guest" + +flows: + - ->: flow + #type in flow is used to mention what will be order of execution + type: "Init" + task_name: + "stakingpayout" + #to mention flow what task it is depends on + depends_on: null + + - ->: flow + type: "Term" + task_name: "push_notification" + depends_on: + operation: null + task: + - name: "stakingpayout" + fields: + - result + +workflows: + ->: workflow + name: "workflow" + version: "0.0.1" \ No newline at end of file diff --git a/workflow/providers/hooks/constants.py b/workflow/providers/hooks/constants.py index f84ad01e..160b6156 100644 --- a/workflow/providers/hooks/constants.py +++ b/workflow/providers/hooks/constants.py @@ -103,35 +103,16 @@ def cargo_generator(task_list): cargo_dependencies = "" - for task in task_list: - kind = task['kind'] - if kind == "OpenWhisk": - cargo_dependencies = f""" + cargo_dependencies = f""" [lib] crate-type = ["cdylib"] [dependencies] -serde = "1.0.137" -serde_json = "1.0.81" -serde_derive = "1.0.81" derive-enum-from-into = "0.1.1" -openwhisk-rust = "0.1.2" openwhisk_macro = "0.1.6" paste = "1.0.7" dyn-clone = "1.0.7" workflow_macro = "0.0.3" - -""" - else: - cargo_dependencies = f""" -[lib] -crate-type = ["cdylib"] - -[dependencies] -derive-enum-from-into = "0.1.1" -paste = "1.0.7" -dyn-clone = "1.0.7" -workflow_macro = "0.0.3" serde_json = {{ version = "1.0", features = ["raw_value"] }} serde = {{ version = "1.0", features = ["derive"] }} codec = {{ package = "parity-scale-codec", features = [ @@ -148,11 +129,7 @@ def cargo_generator(task_list): return cargo_dependencies def global_import_generator(task_list): - global_imports = "" - for task in task_list: - kind = task['kind'] - if kind == "OpenWhisk": - global_imports = f""" + global_imports = f""" #![allow(unused_imports)] mod common; @@ -169,30 +146,6 @@ def global_import_generator(task_list): use workflow_macro::Flow; use serde_json::to_value; -use std::convert::TryInto; -use paste::*; -use common::*; -use traits::*; -use types::*; -extern crate alloc; -use core::alloc::Layout; -""" - else: - global_imports = f""" -#![allow(unused_imports)] - -mod common; -mod traits; -mod types; -use dyn_clone::{{clone_trait_object, DynClone}}; -use serde::{{Deserialize, Serialize}}; -use std::collections::HashMap; -use std::fmt::Debug; -use serde_json::{{Value}}; -use derive_enum_from_into::{{EnumFrom,EnumTryInto}}; -use workflow_macro::Flow; -use serde_json::to_value; - use std::convert::TryInto; use paste::*; use common::*; @@ -201,10 +154,9 @@ def global_import_generator(task_list): extern crate alloc; use core::alloc::Layout; use sp_core::H256; +use substrate_macro::Polkadot; use codec::{{Encode, Decode}}; use sp_runtime::AccountId32; -use substrate_macro::Polkadot; - #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug)] pub struct StakingLedger {{ pub stash: AccountId32, @@ -216,4 +168,5 @@ def global_import_generator(task_list): pub claimed_rewards: Vec, }} """ + return global_imports