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

fix: update tackle hook #68

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
87 changes: 87 additions & 0 deletions workflow/examples/PayoutNotification.yaml
Original file line number Diff line number Diff line change
@@ -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<H256>"
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<H256>"
#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"
55 changes: 4 additions & 51 deletions workflow/providers/hooks/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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;
Expand All @@ -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::*;
Expand All @@ -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,
Expand All @@ -216,4 +168,5 @@ def global_import_generator(task_list):
pub claimed_rewards: Vec<u32>,
}}
"""

return global_imports
Loading