From 6d8d6a8bf764c34261477cb92c623933f0b6ebcd Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 1 Aug 2023 14:29:24 +0530 Subject: [PATCH 1/3] chore: create YAML for Polkadot Payout and notification --- workflow/examples/PayoutNotification.yaml | 87 +++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 workflow/examples/PayoutNotification.yaml 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 From 29b6591928c3a0e4045cf67386d737f8152a2658 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 1 Aug 2023 14:29:59 +0530 Subject: [PATCH 2/3] chore: fix tackle hooks for toml file --- workflow/providers/hooks/constants.py | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/workflow/providers/hooks/constants.py b/workflow/providers/hooks/constants.py index f84ad01e..14938e27 100644 --- a/workflow/providers/hooks/constants.py +++ b/workflow/providers/hooks/constants.py @@ -111,15 +111,22 @@ def cargo_generator(task_list): 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" +serde_json = {{ version = "1.0", features = ["raw_value"] }} +serde = {{ version = "1.0", features = ["derive"] }} +codec = {{ package = "parity-scale-codec", features = [ + "derive", +], version = "3.1.5" }} +substrate_macro = "0.1.3" +openwhisk-rust = "0.1.2" +sp-core = {{ version = "6.0.0", default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", rev = "eb1a2a8" }} +sp-runtime = {{ version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "eb1a2a8" }} +substrate-api-client = {{ git = "https://github.com/HugoByte/substrate-api-client.git", default-features = false, features = ["staking-xt"], branch ="wasm-support"}} +pallet-staking = {{ git = "https://github.com/paritytech/substrate.git", package = "pallet-staking" ,rev = "eb1a2a8" }} """ else: @@ -176,6 +183,20 @@ def global_import_generator(task_list): use types::*; extern crate alloc; use core::alloc::Layout; +use sp_core::H256; +use substrate_macro::Polkadot; +use codec::{{Encode, Decode}}; +use sp_runtime::AccountId32; +#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug)] +pub struct StakingLedger {{ + pub stash: AccountId32, + #[codec(compact)] + pub total: u128, + #[codec(compact)] + pub active: u128, + pub unlocking: Vec, + pub claimed_rewards: Vec, +}} """ else: global_imports = f""" From 1a1b77f8597394151735f27711c367df86a19bb6 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 1 Aug 2023 15:12:17 +0530 Subject: [PATCH 3/3] chore: update contants in hook --- workflow/providers/hooks/constants.py | 72 +-------------------------- 1 file changed, 2 insertions(+), 70 deletions(-) diff --git a/workflow/providers/hooks/constants.py b/workflow/providers/hooks/constants.py index 14938e27..160b6156 100644 --- a/workflow/providers/hooks/constants.py +++ b/workflow/providers/hooks/constants.py @@ -103,10 +103,7 @@ 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"] @@ -128,38 +125,11 @@ def cargo_generator(task_list): substrate-api-client = {{ git = "https://github.com/HugoByte/substrate-api-client.git", default-features = false, features = ["staking-xt"], branch ="wasm-support"}} pallet-staking = {{ git = "https://github.com/paritytech/substrate.git", package = "pallet-staking" ,rev = "eb1a2a8" }} -""" - 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 = [ - "derive", -], version = "3.1.5" }} -substrate_macro = "0.1.3" -openwhisk-rust = "0.1.2" -sp-core = {{ version = "6.0.0", default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", rev = "eb1a2a8" }} -sp-runtime = {{ version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", rev = "eb1a2a8" }} -substrate-api-client = {{ git = "https://github.com/HugoByte/substrate-api-client.git", default-features = false, features = ["staking-xt"], branch ="wasm-support"}} -pallet-staking = {{ git = "https://github.com/paritytech/substrate.git", package = "pallet-staking" ,rev = "eb1a2a8" }} - """ 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; @@ -198,43 +168,5 @@ def global_import_generator(task_list): pub claimed_rewards: Vec, }} """ - 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::*; -use traits::*; -use types::*; -extern crate alloc; -use core::alloc::Layout; -use sp_core::H256; -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, - #[codec(compact)] - pub total: u128, - #[codec(compact)] - pub active: u128, - pub unlocking: Vec, - pub claimed_rewards: Vec, -}} -""" return global_imports