From a7c9bc41c11fc9c6a25572fbbb8f49292dddcf17 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 22 Aug 2023 11:38:50 +0530 Subject: [PATCH 01/27] chore: add icon event processor --- Cargo.toml | 1 + actions/icon-event-processor/Cargo.toml | 31 ++++ actions/icon-event-processor/deploy.sh | 29 ++++ actions/icon-event-processor/src/lib.rs | 195 ++++++++++++++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 actions/icon-event-processor/Cargo.toml create mode 100755 actions/icon-event-processor/deploy.sh create mode 100644 actions/icon-event-processor/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 8a7ee154..41d1a383 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "actions/push-notification", "actions/event-receiver", "actions/substrate-event-processor", + "actions/icon-event-processor", "actions/user_registration", "actions/user_login", "actions/workflow-invoker", diff --git a/actions/icon-event-processor/Cargo.toml b/actions/icon-event-processor/Cargo.toml new file mode 100644 index 00000000..21c3327e --- /dev/null +++ b/actions/icon-event-processor/Cargo.toml @@ -0,0 +1,31 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +[package] +name = "action-icon-event-processor" +version = "0.1.0" +authors = ["HugoByte "] +repository = "https://github.com/hugobyte/aurras" +license = "Apache-2.0" +edition = "2018" + +[dependencies] +serde_json = "1.0" +serde = "1.0" +serde_derive = "1.0" +actions-common = { git = "https://github.com/HugoByte/aurras", rev = '1f7e117' } +chesterfield = "0.0.1" \ No newline at end of file diff --git a/actions/icon-event-processor/deploy.sh b/actions/icon-event-processor/deploy.sh new file mode 100755 index 00000000..9f8cbbfe --- /dev/null +++ b/actions/icon-event-processor/deploy.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# To run this command +# ./deploy.sh --openwhiskApiHost --openwhiskApiKey --openwhiskNamespace + +openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} +openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} +openwhiskNamespace=${openwhiskNamespace:-guest} +actionHome=${actionHome:-actions/icon-event-processor} + +ACTION="icon-event-processor" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" + +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" + +check wsk + +build + +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" --param event_producer_trigger "icon-produce-event" -a provide-api-key true + +$WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "icon-produce-event" --auth "$openwhiskApiKey" +$WSK_CLI -i --apihost "$openwhiskApiHost" rule update "icon-produce-event-rule" "icon-produce-event" "event-producer" --auth "$openwhiskApiKey" diff --git a/actions/icon-event-processor/src/lib.rs b/actions/icon-event-processor/src/lib.rs new file mode 100644 index 00000000..83b26aee --- /dev/null +++ b/actions/icon-event-processor/src/lib.rs @@ -0,0 +1,195 @@ +extern crate serde_json; + +#[cfg(test)] +use actions_common::Config; +use actions_common::Context; +use chesterfield::sync::{Client, Database}; +use serde_derive::{Deserialize, Serialize}; +use serde_json::{Error, Value}; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +struct Event { + #[serde(rename = "scoreAddress")] + score_address: String, + indexed: Vec, + data: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +struct Input { + topic: String, + brokers: Vec, + event_producer_trigger: String, + event: Event, +} + +struct Action { + params: Input, + context: Option, +} + +impl Action { + pub fn new(params: Input) -> Self { + Action { + params, + context: None, + } + } + #[allow(dead_code)] + #[cfg(test)] + pub fn init(&mut self, config: &Config) { + let db = self.connect_db("http://localhost:5984", "test"); + self.context = Some(Context::new(db, Some(config))); + } + + #[cfg(not(test))] + pub fn init(&mut self) { + let db = self.connect_db("http://localhost:5984", "test"); + self.context = Some(Context::new(db, None)); + } + + #[allow(dead_code)] + fn connect_db(&self, db_url: &str, db_name: &str) -> Database { + let client = Client::new(db_url).unwrap(); + client.database(db_name).unwrap() + } + + pub fn get_context(&mut self) -> &Context { + self.context.as_mut().expect("Action not Initialized!") + } + + pub fn parse_event_data(&self) -> Result { + return match self.params.event.indexed[0].as_str() { + "CallMessage(str,str,int,int,bytes)" => { + return Ok(serde_json::json!({ + "data": self.params.event.data[1], + "req_id": self.params.event.data[0], + "to": self.params.event.indexed[2], + "from": self.params.event.indexed[1] + })); + } + _ => Err(serde::de::Error::custom(format!( + "Section {} Not Defined", + self.params.event.indexed[0] + ))), + }; + } + + pub fn produce_event(&mut self, event: Value) -> Result { + let event_producer_trigger = self.params.event_producer_trigger.clone(); + let topic = self.params.topic.clone(); + let brokers = self.params.brokers.clone(); + self.get_context().invoke_trigger( + &event_producer_trigger, + &serde_json::json!({ + "topic": topic, + "value": event, + "brokers": brokers + }), + ) + } +} + +pub fn main(args: Value) -> Result { + let input = serde_json::from_value::(args)?; + let mut action = Action::new(input); + + #[cfg(not(test))] + action.init(); + let parsed_event = action.parse_event_data()?; + action.produce_event(parsed_event) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_event_data_pass() { + let input = serde_json::from_value::(serde_json::json!({ + "topic": "topic", + "brokers": ["172.17.0.1:9092"], + "event_producer_trigger": "produce_event", + "event": { + "scoreAddress": "cxca002001f46a19562648d3348bc9080175dcad3a", + "indexed": [ + "CallMessage(str,str,int,int,bytes)", + "btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1", + "cxdf97f11ef352727f5d826eec68e569d6471aa9a4", + "0x1" + ], + "data": [ + "0x1", + "0x73656e6443616c6c4d6573736167655f686172646861745f69636f6e30" + ] + }, + })) + .unwrap(); + let action = Action::new(input); + + let response = action.parse_event_data().unwrap(); + + assert_eq!( + response, + serde_json::json!({"data":"0x73656e6443616c6c4d6573736167655f686172646861745f69636f6e30","to":"cxdf97f11ef352727f5d826eec68e569d6471aa9a4","req_id":"0x1","from":"btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1"}) + ); + } + + #[test] + fn parse_call_sent_event_data_pass() { + let input = serde_json::from_value::(serde_json::json!({ + "topic": "topic", + "brokers": ["172.17.0.1:9092"], + "event_producer_trigger": "produce_staking_event", + "event": { + "scoreAddress": "cxca002001f46a19562648d3348bc9080175dcad3a", + "indexed": [ + "CallMessage(str,str,int,int,bytes)", + "btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1", + "cxdf97f11ef352727f5d826eec68e569d6471aa9a4", + "0x1" + ], + "data": [ + "0x1", + "0x73656e6443616c6c4d6573736167655f686172646861745f69636f6e30" + ] + }, + })) + .unwrap(); + let action = Action::new(input); + + let response = action.parse_event_data().unwrap(); + + assert_eq!( + serde_json::from_value::(response["from"].clone()).unwrap(), + "btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1".to_string() + ); + } + + #[test] + #[should_panic(expected = "Section CallMessageSent(str,str,int,int,bytes) Not Defined")] + fn parse_call_message_sent_event_data_method_exception() { + let input = serde_json::from_value::(serde_json::json!({ + "topic": "topic", + "brokers": ["172.17.0.1:9092"], + "event_producer_trigger": "produce_staking_event", + "event": { + "scoreAddress": "cxca002001f46a19562648d3348bc9080175dcad3a", + "indexed": [ + "CallMessageSent(str,str,int,int,bytes)", + "btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1", + "cxdf97f11ef352727f5d826eec68e569d6471aa9a4", + "0x1" + ], + "data": [ + "0x1", + "0x73656e6443616c6c4d6573736167655f686172646861745f69636f6e30" + ] + }, + })) + .unwrap(); + let action = Action::new(input); + + action.parse_event_data().unwrap(); + } +} From 8131c568635584a27aedcd7dbc7b6166c26624b4 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Fri, 1 Sep 2023 01:45:21 +0530 Subject: [PATCH 02/27] chore: add eth event processor --- Cargo.toml | 1 + actions/eth-event-processor/Cargo.toml | 31 +++ actions/eth-event-processor/deploy.sh | 29 +++ actions/eth-event-processor/src/lib.rs | 244 +++++++++++++++++++++++ actions/eth-event-processor/src/types.rs | 24 +++ 5 files changed, 329 insertions(+) create mode 100644 actions/eth-event-processor/Cargo.toml create mode 100755 actions/eth-event-processor/deploy.sh create mode 100644 actions/eth-event-processor/src/lib.rs create mode 100644 actions/eth-event-processor/src/types.rs diff --git a/Cargo.toml b/Cargo.toml index 41d1a383..bf7972bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "actions/event-receiver", "actions/substrate-event-processor", "actions/icon-event-processor", + "actions/eth-event-processor", "actions/user_registration", "actions/user_login", "actions/workflow-invoker", diff --git a/actions/eth-event-processor/Cargo.toml b/actions/eth-event-processor/Cargo.toml new file mode 100644 index 00000000..be918f88 --- /dev/null +++ b/actions/eth-event-processor/Cargo.toml @@ -0,0 +1,31 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +[package] +name = "action-eth-event-processor" +version = "0.1.0" +authors = ["HugoByte "] +repository = "https://github.com/hugobyte/aurras" +license = "Apache-2.0" +edition = "2018" + +[dependencies] +serde_json = "1.0" +serde = "1.0" +serde_derive = "1.0" +actions-common = { git = "https://github.com/HugoByte/aurras", rev = '1f7e117' } +chesterfield = "0.0.1" \ No newline at end of file diff --git a/actions/eth-event-processor/deploy.sh b/actions/eth-event-processor/deploy.sh new file mode 100755 index 00000000..c4ad0498 --- /dev/null +++ b/actions/eth-event-processor/deploy.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# To run this command +# ./deploy.sh --openwhiskApiHost --openwhiskApiKey --openwhiskNamespace + +openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} +openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} +openwhiskNamespace=${openwhiskNamespace:-guest} +actionHome=${actionHome:-actions/eth-event-processor} + +ACTION="eth-event-processor" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" + +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" + +check wsk + +build + +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" --param event_producer_trigger "eth-produce-event" -a provide-api-key true + +$WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "eth-produce-event" --auth "$openwhiskApiKey" +$WSK_CLI -i --apihost "$openwhiskApiHost" rule update "eth-produce-event-rule" "eth-produce-event" "event-producer" --auth "$openwhiskApiKey" diff --git a/actions/eth-event-processor/src/lib.rs b/actions/eth-event-processor/src/lib.rs new file mode 100644 index 00000000..9ef556d6 --- /dev/null +++ b/actions/eth-event-processor/src/lib.rs @@ -0,0 +1,244 @@ +extern crate serde_json; +mod types; + +#[cfg(test)] +use actions_common::Config; +use actions_common::Context; +use chesterfield::sync::{Client, Database}; +use serde_derive::{Deserialize, Serialize}; +use serde_json::{Error, Value}; +use types::*; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +struct Input { + topic: String, + brokers: Vec, + event_producer_trigger: String, + event: Event, +} + +struct Action { + params: Input, + context: Option, +} + +impl Action { + pub fn new(params: Input) -> Self { + Action { + params, + context: None, + } + } + #[allow(dead_code)] + #[cfg(test)] + pub fn init(&mut self, config: &Config) { + let db = self.connect_db("http://localhost:5984", "test"); + self.context = Some(Context::new(db, Some(config))); + } + + #[cfg(not(test))] + pub fn init(&mut self) { + let db = self.connect_db("http://localhost:5984", "test"); + self.context = Some(Context::new(db, None)); + } + + #[allow(dead_code)] + fn connect_db(&self, db_url: &str, db_name: &str) -> Database { + let client = Client::new(db_url).unwrap(); + client.database(db_name).unwrap() + } + + pub fn get_context(&mut self) -> &Context { + self.context.as_mut().expect("Action not Initialized!") + } + + pub fn parse_event_data(&self) -> Result { + return match self.params.event.event.as_str() { + "CallMessage" => { + return Ok(serde_json::json!({ + "data": serde_json::from_value::(self.params.event.args[4].clone()).unwrap(), + "req_id": i64::from_str_radix(&self.params.event.topics[3].clone()[2..], 16).unwrap(), + "to": self.params.event.topics[2].clone(), + "from": self.params.event.topics[1].clone() + })); + } + _ => Err(serde::de::Error::custom(format!( + "Section {} Not Defined", + self.params.event.event + ))), + }; + } + + pub fn produce_event(&mut self, event: Value) -> Result { + let event_producer_trigger = self.params.event_producer_trigger.clone(); + let topic = self.params.topic.clone(); + let brokers = self.params.brokers.clone(); + self.get_context().invoke_trigger( + &event_producer_trigger, + &serde_json::json!({ + "topic": topic, + "value": event, + "brokers": brokers + }), + ) + } +} + +pub fn main(args: Value) -> Result { + let input = serde_json::from_value::(args)?; + let mut action = Action::new(input); + + #[cfg(not(test))] + action.init(); + let parsed_event = action.parse_event_data()?; + action.produce_event(parsed_event) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_event_data_pass() { + let input = serde_json::from_value::(serde_json::json!({ + "topic": "topic", + "brokers": ["172.17.0.1:9092"], + "event_producer_trigger": "produce_event", + "event": { + "blockNumber": 365, + "blockHash": "0xa6918392f79acd0983ad8b42ba59daaf07589d6204cc68defc057cda84ac8e32", + "transactionIndex": 0, + "removed": false, + "address": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82", + "data": "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001d73656e6443616c6c4d6573736167655f69636f6e305f68617264686174000000", + "topics": [ + "0x2cbc78425621c181f9f8a25fc06e44a0ac2b67cd6a31f8ed7918934187f8cc59", + "0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c", + "0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911", + "0x0000000000000000000000000000000000000000000000000000000000000001" + ], + "transactionHash": "0x3cf2006eaa5520175facf358e3a8d50c6d0de20067f957152726542543647132", + "logIndex": 0, + "event": "CallMessage", + "eventSignature": "CallMessage(string,string,uint256,uint256,bytes)", + "args": [ + { + "_isIndexed": true, + "hash": "0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c" + }, + { + "_isIndexed": true, + "hash": "0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911" + }, + { "type": "BigNumber", "hex": "0x01" }, + { "type": "BigNumber", "hex": "0x01" }, + "0x73656e6443616c6c4d6573736167655f69636f6e305f68617264686174" + ] + }, + })) + .unwrap(); + let action = Action::new(input); + + let response = action.parse_event_data().unwrap(); + + assert_eq!( + response, + serde_json::json!({"data":"0x73656e6443616c6c4d6573736167655f69636f6e305f68617264686174","from":"0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c","req_id":1,"to":"0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911"} + ) + ); + } + + #[test] + fn parse_call_sent_event_data_pass() { + let input = serde_json::from_value::(serde_json::json!({ + "topic": "topic", + "brokers": ["172.17.0.1:9092"], + "event_producer_trigger": "produce_staking_event", + "event": { + "blockNumber": 365, + "blockHash": "0xa6918392f79acd0983ad8b42ba59daaf07589d6204cc68defc057cda84ac8e32", + "transactionIndex": 0, + "removed": false, + "address": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82", + "data": "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001d73656e6443616c6c4d6573736167655f69636f6e305f68617264686174000000", + "topics": [ + "0x2cbc78425621c181f9f8a25fc06e44a0ac2b67cd6a31f8ed7918934187f8cc59", + "0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c", + "0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911", + "0x0000000000000000000000000000000000000000000000000000000000000001" + ], + "transactionHash": "0x3cf2006eaa5520175facf358e3a8d50c6d0de20067f957152726542543647132", + "logIndex": 0, + "event": "CallMessage", + "eventSignature": "CallMessage(string,string,uint256,uint256,bytes)", + "args": [ + { + "_isIndexed": true, + "hash": "0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c" + }, + { + "_isIndexed": true, + "hash": "0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911" + }, + { "type": "BigNumber", "hex": "0x01" }, + { "type": "BigNumber", "hex": "0x01" }, + "0x73656e6443616c6c4d6573736167655f69636f6e305f68617264686174" + ] + }, + })) + .unwrap(); + let action = Action::new(input); + + let response = action.parse_event_data().unwrap(); + + assert_eq!( + serde_json::from_value::(response["from"].clone()).unwrap(), + "0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c".to_string() + ); + } + + #[test] + #[should_panic(expected = "Section CallMessageSent Not Defined")] + fn parse_call_message_sent_event_data_method_exception() { + let input = serde_json::from_value::(serde_json::json!({ + "topic": "topic", + "brokers": ["172.17.0.1:9092"], + "event_producer_trigger": "produce_staking_event", + "event": { + "blockNumber": 365, + "blockHash": "0xa6918392f79acd0983ad8b42ba59daaf07589d6204cc68defc057cda84ac8e32", + "transactionIndex": 0, + "removed": false, + "address": "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82", + "data": "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001d73656e6443616c6c4d6573736167655f69636f6e305f68617264686174000000", + "topics": [ + "0x2cbc78425621c181f9f8a25fc06e44a0ac2b67cd6a31f8ed7918934187f8cc59", + "0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c", + "0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911", + "0x0000000000000000000000000000000000000000000000000000000000000001" + ], + "transactionHash": "0x3cf2006eaa5520175facf358e3a8d50c6d0de20067f957152726542543647132", + "logIndex": 0, + "event": "CallMessageSent", + "eventSignature": "CallMessageSent(string,string,uint256,uint256,bytes)", + "args": [ + { + "_isIndexed": true, + "hash": "0xff4555761731a3642885c2ca67fb09e827825033bdf74f1c7f9b4b3151eec14c" + }, + { + "_isIndexed": true, + "hash": "0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911" + }, + { "type": "BigNumber", "hex": "0x01" }, + { "type": "BigNumber", "hex": "0x01" }, + "0x73656e6443616c6c4d6573736167655f69636f6e305f68617264686174" + ] + }, + })) + .unwrap(); + let action = Action::new(input); + + action.parse_event_data().unwrap(); + } +} diff --git a/actions/eth-event-processor/src/types.rs b/actions/eth-event-processor/src/types.rs new file mode 100644 index 00000000..500280aa --- /dev/null +++ b/actions/eth-event-processor/src/types.rs @@ -0,0 +1,24 @@ +use super::*; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Event { + pub address: String, + pub topics: Vec, + pub event: String, + #[serde(rename = "eventSignature")] + pub event_signature: String, + pub data: String, + pub args: Vec, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Address { + #[serde(rename = "_isIndexed")] + pub is_indexed: bool, + pub hash: String, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct BigNumber { + pub hex: String, +} From eeebc6cc5ac8af43191400f4add57dfe8b3d7215 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Wed, 6 Sep 2023 13:00:51 +0530 Subject: [PATCH 03/27] chore: create icon-eth message parser for notification --- Cargo.toml | 1 + actions/icon-eth-notification/Cargo.toml | 21 +++ actions/icon-eth-notification/src/lib.rs | 151 ++++++++++++++++++ .../icon-eth-notification/src/types/mod.rs | 2 + .../icon-eth-notification/src/types/types.rs | 13 ++ actions/icon-event-processor/src/lib.rs | 5 +- 6 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 actions/icon-eth-notification/Cargo.toml create mode 100644 actions/icon-eth-notification/src/lib.rs create mode 100644 actions/icon-eth-notification/src/types/mod.rs create mode 100644 actions/icon-eth-notification/src/types/types.rs diff --git a/Cargo.toml b/Cargo.toml index bf7972bb..6d932c47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ members = [ "actions/workflow-invoker", "actions/workflow_management", "actions/workflow_registration", + "actions/icon-eth-notification", "workflow/openwhisk_macro", "workflow/workflow_macro", "workflow/polkadot_macro", diff --git a/actions/icon-eth-notification/Cargo.toml b/actions/icon-eth-notification/Cargo.toml new file mode 100644 index 00000000..d026d037 --- /dev/null +++ b/actions/icon-eth-notification/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "action-icon-eth-notification" +version = "0.1.0" +authors = ["HugoByte "] +repository = "https://github.com/hugobyte/aurras" +license = "Apache-2.0" +edition = "2018" + +[dependencies] +serde_json = "1.0" +serde = "1.0" +serde_derive = "1.0" +uuid = { version = "0.8", features = ["serde", "v4"] } +chesterfield = "0.0.1" +actions-common = { git = "https://github.com/hugobyte/aurras", rev = '1f7e117' } +rust-crypto = "0.2" + + +[dev-dependencies] +actions-common = { git = "https://github.com/hugobyte/aurras", rev = '1f7e117', features = ["mock_containers"] } +tokio = { version = "1.0.0", features = ["macros"] } \ No newline at end of file diff --git a/actions/icon-eth-notification/src/lib.rs b/actions/icon-eth-notification/src/lib.rs new file mode 100644 index 00000000..391672f9 --- /dev/null +++ b/actions/icon-eth-notification/src/lib.rs @@ -0,0 +1,151 @@ +extern crate serde_json; +mod types; + +#[cfg(test)] +use actions_common::Config; +use actions_common::Context; +// use chesterfield::sync::{Client, Database}; +use crypto::digest::Digest; +use crypto::sha3::Sha3; +use serde_derive::{Deserialize, Serialize}; +use serde_json::{Error, Value}; +use types::Event; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +struct Input { + pub data: Value, +} + +struct Action { + pub params: Input, + context: Option, +} + +impl Action { + pub fn new(params: Input) -> Self { + Action { + params, + context: None, + } + } + + pub fn get_context(&mut self) -> &Context { + self.context.as_mut().expect("Action not Initialized!") + } + + pub fn invoke_push_notification(&mut self, value: &Value) -> Result { + self.get_context().invoke_action("push_notification", value) + } + + pub fn get_keccak_hash(&self, input: String) -> String { + let mut hasher = Sha3::keccak256(); + hasher.input_str(&input); + let res = hasher.result_str(); + "0x".to_string() + &res + } + + pub fn filter_event(&mut self) -> Result { + let event = serde_json::from_value::(self.params.data.clone()).unwrap(); + + if event.from.starts_with("0x") { + let address_hash = self.get_keccak_hash(event.address.clone()); + if event.from == address_hash { + self.invoke_push_notification( + &serde_json::json!({ + "token": event.token.clone(), + "message": { + "title": "Message Recieved On Hardhat Chain", + "body": format!("Message sent to {} Recieved with request id {}", event.to.clone(), event.req_id.clone()) + } + }), + )?; + } else { + return Err("Address is Not matched").map_err(serde::de::Error::custom); + } + } else { + if event.address == event.from { + self.invoke_push_notification( + &serde_json::json!({ + "token": event.token.clone(), + "message": { + "title": "Message Recieved On Icon Chain", + "body": format!("Message sent to {} Recieved with request id {}", event.to.clone(), event.req_id.clone()) + } + }), + )?; + } else { + return Err("Address is Not matched").map_err(serde::de::Error::custom); + } + } + + Ok(serde_json::json!({ + "action": "success" + })) + } +} + +pub fn main(args: Value) -> Result { + let input = serde_json::from_value::(args)?; + let mut action = Action::new(input); + + action.filter_event() +} + +#[cfg(test)] +mod tests { + use crate::{Action, Input, main}; + + #[test] + fn test_get_keccak_hash() { + let action = Action::new(crate::Input { + data: serde_json::json!({}), + }); + let result = action.get_keccak_hash( + "btp://0x3.icon/cx2196b1de35d8e3cb40bcbf0142d29263c212ed5d".to_string(), + ); + assert_eq!( + "0xa1f733357b915d1ede96cec955a028f730cf796d714a5975563f8e12f0875567", + result + ) + } + + // #[test] + // fn test_filter_icon_event() { + // let data = serde_json::json!({"address":"btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1" , + // "token" : "hshfhsdhghn","data":"0x73656e6443616c6c4d6573736167655f686172646861745f69636f6e30", + // "to":"cxdf97f11ef352727f5d826eec68e569d6471aa9a4", + // "req_id":1, + // "from":"btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1"}); + // let input = Input { data }; + // let mut action = Action::new(input); + // action.filter_event(); + // } + + // #[test] + // fn test_filter_hardhat_event() { + // let data = serde_json::json!({"address":"btp://0x3.icon/cx2196b1de35d8e3cb40bcbf0142d29263c212ed5d" , + // "token" : "hshfhsdhghn", + // "data":"0x73656e6443616c6c4d6573736167655f69636f6e305f68617264686174", + // "from":"0xa1f733357b915d1ede96cec955a028f730cf796d714a5975563f8e12f0875567", + // "req_id":1, + // "to":"0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911"}); + + // let input = Input { data }; + // let mut action = Action::new(input); + // action.filter_event(); + // } + + // #[test] + // fn test_filter_event() { + // let data = serde_json::json!({"address":"btp://0x3.icon/cx2196b1de35d8e3cb40bcbf0142d29263c212ed5d" , + // "token" : "hshfhsdhghn", + // "data":"0x73656e6443616c6c4d6573736167655f69636f6e305f68617264686174", + // "from":"0xa1f733357b915d1ede96cec955a028f730cf796d714a5975563f8e12f0875567", + // "req_id":1, + // "to":"0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911"}); + + // let input = serde_json::json!({"data": data}); + + // main(input); + // } +} diff --git a/actions/icon-eth-notification/src/types/mod.rs b/actions/icon-eth-notification/src/types/mod.rs new file mode 100644 index 00000000..258fad5a --- /dev/null +++ b/actions/icon-eth-notification/src/types/mod.rs @@ -0,0 +1,2 @@ +pub mod types; +pub use types::*; diff --git a/actions/icon-eth-notification/src/types/types.rs b/actions/icon-eth-notification/src/types/types.rs new file mode 100644 index 00000000..e31c0fb0 --- /dev/null +++ b/actions/icon-eth-notification/src/types/types.rs @@ -0,0 +1,13 @@ +use serde_derive::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +pub struct Event { + pub address: String, + pub token: String, + pub data: String, + pub req_id: i64, + pub to: String, + pub from: String, + #[serde(default)] + pub tx: String, +} diff --git a/actions/icon-event-processor/src/lib.rs b/actions/icon-event-processor/src/lib.rs index 83b26aee..49af4d41 100644 --- a/actions/icon-event-processor/src/lib.rs +++ b/actions/icon-event-processor/src/lib.rs @@ -63,7 +63,8 @@ impl Action { "CallMessage(str,str,int,int,bytes)" => { return Ok(serde_json::json!({ "data": self.params.event.data[1], - "req_id": self.params.event.data[0], + // "req_id": self.params.event.data[0], + "req_id": i64::from_str_radix(&self.params.event.data[0].clone()[2..], 16).unwrap(), "to": self.params.event.indexed[2], "from": self.params.event.indexed[1] })); @@ -131,7 +132,7 @@ mod tests { assert_eq!( response, - serde_json::json!({"data":"0x73656e6443616c6c4d6573736167655f686172646861745f69636f6e30","to":"cxdf97f11ef352727f5d826eec68e569d6471aa9a4","req_id":"0x1","from":"btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1"}) + serde_json::json!({"data":"0x73656e6443616c6c4d6573736167655f686172646861745f69636f6e30","to":"cxdf97f11ef352727f5d826eec68e569d6471aa9a4","req_id":1,"from":"btp://0x539.hardhat/0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1"}) ); } From ceb73733e22d521a958f9dc3296943e2e7ddc5f4 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Thu, 7 Sep 2023 11:30:50 +0530 Subject: [PATCH 04/27] fix:fixed icon-eth-notification init issue --- actions/icon-eth-notification/src/lib.rs | 32 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/actions/icon-eth-notification/src/lib.rs b/actions/icon-eth-notification/src/lib.rs index 391672f9..2acaa9fc 100644 --- a/actions/icon-eth-notification/src/lib.rs +++ b/actions/icon-eth-notification/src/lib.rs @@ -4,6 +4,7 @@ mod types; #[cfg(test)] use actions_common::Config; use actions_common::Context; +use chesterfield::sync::{Client, Database}; // use chesterfield::sync::{Client, Database}; use crypto::digest::Digest; use crypto::sha3::Sha3; @@ -29,12 +30,34 @@ impl Action { } } + #[cfg(test)] + pub fn init(&mut self, config: &Config) { + let db = self.connect_db("http://admin:p@ssw0rd@172.17.0.1:5984", "icon_filter_db"); + self.context = Some(Context::new(db, Some(config))); + } + + #[cfg(not(test))] + pub fn init(&mut self) { + let db = self.connect_db("http://admin:p@ssw0rd@172.17.0.1:5984", "icon_filter_db"); + self.context = Some(Context::new(db, None)); + } + + fn connect_db(&self, db_url: &str, db_name: &str) -> Database { + let client = Client::new(db_url).unwrap(); + let db = client.database(db_name).unwrap(); + if !db.exists().unwrap() { + db.create().unwrap(); + } + db + } + pub fn get_context(&mut self) -> &Context { self.context.as_mut().expect("Action not Initialized!") } pub fn invoke_push_notification(&mut self, value: &Value) -> Result { - self.get_context().invoke_action("push_notification", value) + self.get_context() + .invoke_trigger("send-push-notification", value) } pub fn get_keccak_hash(&self, input: String) -> String { @@ -87,13 +110,14 @@ impl Action { pub fn main(args: Value) -> Result { let input = serde_json::from_value::(args)?; let mut action = Action::new(input); - + #[cfg(not(test))] + action.init(); action.filter_event() } #[cfg(test)] mod tests { - use crate::{Action, Input, main}; + use crate::Action; #[test] fn test_get_keccak_hash() { @@ -145,7 +169,7 @@ mod tests { // "to":"0x16f7d9e9e594e72a2e6120902a1339f4be2c2f06b73a09dc24c1956d61880911"}); // let input = serde_json::json!({"data": data}); - + // main(input); // } } From ba38996e6d1237bd0268065e3d1893e7d81367c1 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Sun, 10 Sep 2023 13:18:24 +0530 Subject: [PATCH 05/27] chore: Add ui for icon-eth notification --- examples/icon-eth-notification/package.json | 41 +++ .../icon-eth-notification/public/index.html | 47 +++ examples/icon-eth-notification/src/App.js | 25 ++ .../icon-eth-notification/src/config/dev.json | 6 + .../src/config/firebase.js | 13 + .../icon-eth-notification/src/config/index.js | 6 + examples/icon-eth-notification/src/index.js | 12 + .../icon-eth-notification/src/pages/Modal.js | 174 ++++++++++ .../icon-eth-notification/src/pages/index.js | 73 +++++ .../src/pages/main_page.js | 109 +++++++ .../icon-eth-notification/src/pages/nav.js | 53 +++ .../src/pages/sign_in.js | 99 ++++++ .../src/pages/sign_up.js | 75 +++++ .../icon-eth-notification/src/pages/test.css | 0 examples/icon-eth-notification/src/styles.css | 304 ++++++++++++++++++ 15 files changed, 1037 insertions(+) create mode 100644 examples/icon-eth-notification/package.json create mode 100644 examples/icon-eth-notification/public/index.html create mode 100644 examples/icon-eth-notification/src/App.js create mode 100644 examples/icon-eth-notification/src/config/dev.json create mode 100644 examples/icon-eth-notification/src/config/firebase.js create mode 100644 examples/icon-eth-notification/src/config/index.js create mode 100644 examples/icon-eth-notification/src/index.js create mode 100644 examples/icon-eth-notification/src/pages/Modal.js create mode 100644 examples/icon-eth-notification/src/pages/index.js create mode 100644 examples/icon-eth-notification/src/pages/main_page.js create mode 100644 examples/icon-eth-notification/src/pages/nav.js create mode 100644 examples/icon-eth-notification/src/pages/sign_in.js create mode 100644 examples/icon-eth-notification/src/pages/sign_up.js create mode 100644 examples/icon-eth-notification/src/pages/test.css create mode 100644 examples/icon-eth-notification/src/styles.css diff --git a/examples/icon-eth-notification/package.json b/examples/icon-eth-notification/package.json new file mode 100644 index 00000000..60c11497 --- /dev/null +++ b/examples/icon-eth-notification/package.json @@ -0,0 +1,41 @@ +{ + "name": "react-login-form", + "version": "1.0.0", + "description": "", + "keywords": [], + "main": "src/index.js", + "dependencies": { + "firebase": "^9.20.0", + "icon-sdk-js": "^1.4.3", + "react": "^18.0.0", + "react-dom": "^18.0.0", + "react-icons": "^4.11.0", + "react-modal": "^3.16.1", + "react-router-dom": "^6.3.0", + "react-scripts": "5.0.1", + "semantic-ui-react": "^2.1.4", + "styled-components": "^6.0.7", + "web-vitals": "^2.1.4" + }, + "devDependencies": { + "typescript": "3.8.3" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test --env=jsdom", + "eject": "react-scripts eject" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/icon-eth-notification/public/index.html b/examples/icon-eth-notification/public/index.html new file mode 100644 index 00000000..f31ff177 --- /dev/null +++ b/examples/icon-eth-notification/public/index.html @@ -0,0 +1,47 @@ + + + + + + + + + + + + React App + + + + +
+ + + diff --git a/examples/icon-eth-notification/src/App.js b/examples/icon-eth-notification/src/App.js new file mode 100644 index 00000000..9b1a455a --- /dev/null +++ b/examples/icon-eth-notification/src/App.js @@ -0,0 +1,25 @@ +import React, { useState } from "react"; +import "./styles.css"; +import "./pages/test.css" +import { + BrowserRouter as Router, + Route, + Routes, + IndexRoute, + Link, +} from "react-router-dom"; +import Home from "./pages"; +import Main from "./pages/main_page"; +import ModalApp from "./pages/Modal"; + +export default function App() { + return ( + + + } /> + } /> + } /> + + + ); +} diff --git a/examples/icon-eth-notification/src/config/dev.json b/examples/icon-eth-notification/src/config/dev.json new file mode 100644 index 00000000..f4e7811d --- /dev/null +++ b/examples/icon-eth-notification/src/config/dev.json @@ -0,0 +1,6 @@ +{ + "APP_NAME": "substrate-front-end-tutorial", + "DEVELOPMENT_KEYRING": true, + "RPC": {}, + "api": "https://139.84.142.77:31001/api/v1/web/guest/" + } \ No newline at end of file diff --git a/examples/icon-eth-notification/src/config/firebase.js b/examples/icon-eth-notification/src/config/firebase.js new file mode 100644 index 00000000..bd141f39 --- /dev/null +++ b/examples/icon-eth-notification/src/config/firebase.js @@ -0,0 +1,13 @@ +import { initializeApp } from "firebase/app" + +export const config = { + apiKey: "AIzaSyBFKOWwoGtoPXye_S_tWQHVtOzA_mf874o", + authDomain: "aurras.firebaseapp.com", + projectId: "aurras", + storageBucket: "aurras.appspot.com", + messagingSenderId: "513296427653", + appId: "1:513296427653:web:b753ed51e3f52588e7d7ec", + measurementId: "G-555C15PTHS" +} + +export default initializeApp(config); \ No newline at end of file diff --git a/examples/icon-eth-notification/src/config/index.js b/examples/icon-eth-notification/src/config/index.js new file mode 100644 index 00000000..5961df04 --- /dev/null +++ b/examples/icon-eth-notification/src/config/index.js @@ -0,0 +1,6 @@ +import configCommon from './dev.json'; + +import firebase from './firebase'; + +const config = { ...configCommon, firebase}; +export default config; \ No newline at end of file diff --git a/examples/icon-eth-notification/src/index.js b/examples/icon-eth-notification/src/index.js new file mode 100644 index 00000000..ad818b83 --- /dev/null +++ b/examples/icon-eth-notification/src/index.js @@ -0,0 +1,12 @@ +import React from "react"; +import ReactDOM from "react-dom"; + +import App from "./App"; + +const rootElement = document.getElementById("root"); +ReactDOM.render( + + + , + rootElement +); diff --git a/examples/icon-eth-notification/src/pages/Modal.js b/examples/icon-eth-notification/src/pages/Modal.js new file mode 100644 index 00000000..bc827d9f --- /dev/null +++ b/examples/icon-eth-notification/src/pages/Modal.js @@ -0,0 +1,174 @@ +import React, { useState } from 'react'; +import Modal from 'react-modal'; +import config from "../config"; +import { getMessaging } from "firebase/messaging/sw"; +import { getToken } from "firebase/messaging"; + +const customStyles = { + content: { + width: '50%', + top: '50%', + left: '50%', + right: 'auto', + bottom: 'auto', + marginRight: '-50%', + transform: 'translate(-50%, -50%)', + }, +}; + +Modal.setAppElement('#root'); + +function ModalApp(props) { + + const messaging = getMessaging(config.firebase); + const [modalIsOpen, setIsOpen] = React.useState(false); + const [topics, setTopics] = useState([]); + const [selected, setSelected] = useState(""); + const [token, setToken] = useState(""); + const [user_auth, setUserAuth] = useState(props.user_auth_token); + const [address, SetAddress] = useState(""); + const [notification, setNotification] = React.useState({ + visible: false, + title: "", + message: "", + variant: "" + }); + const [busy, setBusy] = useState(false); + getToken(messaging).then(token => setToken(token)) + .catch((err) => { + console.log(err); + }); + function openModal() { + setIsOpen(true); + } + + function selectTopic(event) { + setSelected(event.target.value); + } + + function afterOpenModal() { + fetch(`${config.api}default/workflow-management`) + .then(response => response.json()) + .then(data => { + if (data[0]) setSelected(data[0].doc.trigger) + setTopics(data); + }); + + } + + function closeModal() { + setIsOpen(false); + } + + function register({ auth_token, topic, token , address, action}) { + setBusy(true); + const input = JSON.stringify({ address}) + var requestOptions = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ auth_token, topic, token , input, address:action}), + }; + fetch(`${config.api}default/workflow-management`, requestOptions) + .then(response => response.json()) + .then(data => { + setNotification({ + visible: true, + title: "Success", + message: "Registered!", + variant: "positive" + }) + }) + .catch((error) => { + setNotification({ + visible: true, + title: "Failed", + message: "Not Registered!", + variant: "negative" + }) + }).finally(() => { + setBusy(false); + setTimeout(() => { + setNotification({ + visible: false, + title: "", + message: "", + variant: "" + }) + }, 5000); + }); + } + return ( +
+ + + {/*
+
+
+ +
+
+
*/} + { + notification.visible &&
+ +
+ {notification.title} +
+

{notification.message}

+
+ } + +
+
+ Event Source +
+
+ +
+
+
+
+ Address +
+
+ SetAddress(event.target.value)}/> +
+
+
+
+ Push Notification Token +
+
+ +
+
+
+
+ + +
+
+ + +
+
+ ) +} + +export default ModalApp \ No newline at end of file diff --git a/examples/icon-eth-notification/src/pages/index.js b/examples/icon-eth-notification/src/pages/index.js new file mode 100644 index 00000000..70a93382 --- /dev/null +++ b/examples/icon-eth-notification/src/pages/index.js @@ -0,0 +1,73 @@ + +import React, { useState } from "react"; +import "../styles.css"; +import SignInForm from "./sign_in"; +import SignUpForm from "./sign_up"; + +function Home(){ + +const [type, setType] = useState("signIn"); + const handleOnClick = text => { + if (text !== type) { + setType(text); + return; + } + }; + const containerClass = + "container " + (type === "signUp" ? "right-panel-active" : ""); + return ( +
+

Sign in/up Form

+
+ + +
+
+
+

Welcome Back!

+

+ To keep connected with us please login with your personal info +

+ +
+
+

Hello, Users!

+

Enter your personal details and start journey with us

+ +
+
+
+
+
+ + + + ); + } + + export default Home; + + + + +// const Home = () => { +// return ( +//
+//

Sign Up Successful

+//
+// ); +// }; + +// export default Home; \ No newline at end of file diff --git a/examples/icon-eth-notification/src/pages/main_page.js b/examples/icon-eth-notification/src/pages/main_page.js new file mode 100644 index 00000000..55f56ee3 --- /dev/null +++ b/examples/icon-eth-notification/src/pages/main_page.js @@ -0,0 +1,109 @@ +import React from "react"; + +import { useLocation } from "react-router-dom"; +import { Nav, NavLink, NavMenu } from "./nav"; +import { useState } from "react"; +import ModalApp from "./Modal"; +import { + Menu, + Button, + Dropdown, + Container, + Icon, + Image, + Label, + } from 'semantic-ui-react' + +function Main() { + const location = useLocation(); + const user_auth_token = location.state.auth_token; + console.log(location.state.auth_token); + const [auther, setAuth] = useState(location.state.auth_token); + + const handleLogout = () => { + location.state.auth_token =""; + console.log(location.state.auth_token); + console.log("kaskkkf"); + setAuth("") + }; + + if (auther == ""){ + console.log("please login"); + + } + + + return ( + <> + + +
+

Aurras

+
+ +
+

+

+ Aurras is a middleware that acts as an event processor and a low code workflow orchestration platform. + Aurras is being pitched as a next-generation system for enabling decentralized push notification. + This middleware solution listens to events from blockchain applications and propagates them to a registered pool of MQTT brokers. + The broader architecture consist of parachain from which the middleware listens for the events. +

+

+ Aurras is a middleware that acts as an event processor and a low code workflow orchestration platform. + Aurras is being pitched as a next-generation system for enabling decentralized push notification. + This middleware solution listens to events from blockchain applications and propagates them to a registered pool of MQTT brokers. + The broader architecture consist of parachain from which the middleware listens for the events. +

+ +

+ Aurras is a middleware that acts as an event processor and a low code workflow orchestration platform. + Aurras is being pitched as a next-generation system for enabling decentralized push notification. + This middleware solution listens to events from blockchain applications and propagates them to a registered pool of MQTT brokers. + The broader architecture consist of parachain from which the middleware listens for the events. +

+
+ + {/*
+

+
*/} + +
+

+

Thanks to hugobyte

+
+ + ); +} + +export default Main; diff --git a/examples/icon-eth-notification/src/pages/nav.js b/examples/icon-eth-notification/src/pages/nav.js new file mode 100644 index 00000000..d7d3303d --- /dev/null +++ b/examples/icon-eth-notification/src/pages/nav.js @@ -0,0 +1,53 @@ +import { FaBars } from "react-icons/fa"; +import { NavLink as Link } from "react-router-dom"; +import styled from "styled-components"; + +export const Nav = styled.nav` + background: #ffffff; + height: 85px; + display: flex; + justify-content: space-between; + padding: 0.2rem calc((100vw - 1000px) / 2); + z-index: 12; +`; + +export const NavLink = styled(Link)` + color: #808080; + display: flex; + align-items: center; + text-decoration: none; + padding: 0 1rem; + height: 100%; + cursor: pointer; + &.active { + color: #4d4dff; + } +`; + +export const Bars = styled(FaBars)` + display: none; + color: #808080; + @media screen and (max-width: 768px) { + display: block; + position: absolute; + top: 0; + right: 0; + transform: translate(-100%, 75%); + font-size: 1.8rem; + cursor: pointer; + } +`; + +export const NavMenu = styled.div` + display: flex; + align-items: center; + margin-right: -24px; + /* Second Nav */ + /* margin-right: 24px; */ + /* Third Nav */ + /* width: 100vw; +white-space: nowrap; */ + @media screen and (max-width: 768px) { + display: none; + } +`; \ No newline at end of file diff --git a/examples/icon-eth-notification/src/pages/sign_in.js b/examples/icon-eth-notification/src/pages/sign_in.js new file mode 100644 index 00000000..b5907dc8 --- /dev/null +++ b/examples/icon-eth-notification/src/pages/sign_in.js @@ -0,0 +1,99 @@ +import React from "react"; +import config from "../config"; +import { useNavigate } from 'react-router-dom'; + +function SignInForm() { + const navigate = useNavigate(); + const [state, setState] = React.useState({ + email: "", + password: "", + }); + + const [auth_token, setAuths] = React.useState(""); + + const handleChange = (evt) => { + const value = evt.target.value; + setState({ + ...state, + [evt.target.name]: value, + }); + }; + + const handleOnSubmit = (evt) => { + evt.preventDefault(); + + const { email, password } = state; + + // alert(`You are login with email: ${email} and password: ${password}`); + + var requestOptions = { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ email, password }), + }; + console.log(requestOptions); + fetch(`${config.api}default/user-login.json`, requestOptions) + .then((response) => response.json()) + .then((data) => { + const asd = data; + console.log(asd); + const user = asd["user_token"] + navigate('/main', + { state : { + auth_token : user, + }} + ) + + }) + .catch((err) => { + console.log(err); + }); + + for (const key in state) { + setState({ + ...state, + [key]: "", + }); + } + }; + + return ( +
+
+

Sign in

+ {/* */} + {/* or use your account */} + + + Forgot your password? + + +
+ ); +} + +export default SignInForm; diff --git a/examples/icon-eth-notification/src/pages/sign_up.js b/examples/icon-eth-notification/src/pages/sign_up.js new file mode 100644 index 00000000..22027285 --- /dev/null +++ b/examples/icon-eth-notification/src/pages/sign_up.js @@ -0,0 +1,75 @@ +import React from "react"; +function SignUpForm() { + const [state, setState] = React.useState({ + name: "", + email: "", + password: "" + }); + const handleChange = evt => { + const value = evt.target.value; + setState({ + ...state, + [evt.target.name]: value + }); + }; + + const handleOnSubmit = evt => { + evt.preventDefault(); + + const { name, email, password } = state; + alert( + `You are sign up with name: ${name} email: ${email} and password: ${password}` + ); + + for (const key in state) { + setState({ + ...state, + [key]: "" + }); + } + }; + + return ( +
+
+

Create Account

+ {/* */} + {/* or use your email for registration */} + + + + + +
+ ); +} + +export default SignUpForm; diff --git a/examples/icon-eth-notification/src/pages/test.css b/examples/icon-eth-notification/src/pages/test.css new file mode 100644 index 00000000..e69de29b diff --git a/examples/icon-eth-notification/src/styles.css b/examples/icon-eth-notification/src/styles.css new file mode 100644 index 00000000..c33662eb --- /dev/null +++ b/examples/icon-eth-notification/src/styles.css @@ -0,0 +1,304 @@ +.App { + font-family: sans-serif; + text-align: center; +} + +@import url("https://fonts.googleapis.com/css?family=Montserrat:400,800"); + +* { + box-sizing: border-box; +} + +body { + background: #f6f5f7; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + font-family: "Montserrat", sans-serif; + height: 100vh; + margin: -20px 0 50px; +} + +h1 { + font-weight: bold; + margin: 0; +} + +h2 { + text-align: center; +} + +p { + font-size: 14px; + font-weight: 100; + line-height: 20px; + letter-spacing: 0.5px; + margin: 20px 0 30px; +} + +span { + font-size: 12px; +} + +a { + color: #333; + font-size: 14px; + text-decoration: none; + margin: 15px 0; +} + +button { + border-radius: 20px; + border: 1px solid #ff4b2b; + background-color: #ff4b2b; + color: #ffffff; + font-size: 12px; + font-weight: bold; + padding: 12px 10px; + letter-spacing: 1px; + text-transform: uppercase; + transition: transform 80ms ease-in; +} + +button:active { + transform: scale(0.95); +} + +button:focus { + outline: none; +} + +button.ghost { + background-color: transparent; + border-color: #ffffff; +} + +form { + background-color: #ffffff; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + padding: 0 50px; + height: 100%; + text-align: center; +} + +input { + background-color: #eee; + border: none; + padding: 12px 15px; + margin: 8px 0; + width: 100%; +} + +.container { + background-color: #fff; + border-radius: 10px; + box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); + position: relative; + overflow: hidden; + width: 768px; + max-width: 100%; + min-height: 480px; +} + +.form-container { + position: absolute; + top: 0; + height: 100%; + transition: all 0.6s ease-in-out; +} + +.sign-in-container { + left: 0; + width: 50%; + z-index: 2; +} + +.container.right-panel-active .sign-in-container { + transform: translateX(100%); +} + +.sign-up-container { + left: 0; + width: 50%; + opacity: 0; + z-index: 1; +} + +.container.right-panel-active .sign-up-container { + transform: translateX(100%); + opacity: 1; + z-index: 5; + animation: show 0.6s; +} + +@keyframes show { + 0%, + 49.99% { + opacity: 0; + z-index: 1; + } + + 50%, + 100% { + opacity: 1; + z-index: 5; + } +} + +.overlay-container { + position: absolute; + top: 0; + left: 50%; + width: 50%; + height: 100%; + overflow: hidden; + transition: transform 0.6s ease-in-out; + z-index: 100; +} + +.container.right-panel-active .overlay-container { + transform: translateX(-100%); +} + +.overlay { + background: #ff416c; + background: -webkit-linear-gradient(to right, #ff4b2b, #ff416c); + background: linear-gradient(to right, #ff4b2b, #ff416c); + background-repeat: no-repeat; + background-size: cover; + background-position: 0 0; + color: #ffffff; + position: relative; + left: -100%; + height: 100%; + width: 200%; + transform: translateX(0); + transition: transform 0.6s ease-in-out; +} + +.container.right-panel-active .overlay { + transform: translateX(50%); +} + +.overlay-panel { + position: absolute; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + padding: 0 40px; + text-align: center; + top: 0; + height: 100%; + width: 50%; + transform: translateX(0); + transition: transform 0.6s ease-in-out; +} + +.overlay-left { + transform: translateX(-20%); +} + +.container.right-panel-active .overlay-left { + transform: translateX(0); +} + +.overlay-right { + right: 0; + transform: translateX(0); +} + +.container.right-panel-active .overlay-right { + transform: translateX(20%); +} + +.social-container { + margin: 20px 0; +} + +.social-container a { + border: 1px solid #dddddd; + border-radius: 50%; + display: inline-flex; + justify-content: center; + align-items: center; + margin: 0 5px; + height: 40px; + width: 40px; +} + +footer { + background-color: #222; + color: #fff; + font-size: 14px; + bottom: 0; + position: fixed; + left: 0; + right: 0; + text-align: center; + z-index: 999; +} + +footer p { + margin: 10px 0; +} + +footer i { + color: red; +} + +footer a { + color: #3c97bf; + text-decoration: none; +} + + + +.division{ + background-color: #efffd6; + text-align: left; + font-size: 30px; + color: rgb(29, 150, 90); + padding: 10px; + padding: 0 40px; + display: flex; + align-items: top; + justify-content: left; + /* height: 100px; */ + top:10%; + /* width:30%; */ +} + +.one +{ + background-color:white; + float: left; + width: 100%; + height: 550px; +} +.two +{ + background-color:white; + /* width: 50%; */ + height: 550px; + /* float: left; */ +} +.three +{ + background-color: rgb(17, 182, 168); + /* float: left; */ +} + +p{ + /* width: 50%; */ + justify-content: center; + align-items: center; + flex-direction: column; + font-family: "Montserrat", sans-serif; + width: 850px; + margin: 20px 50px; +} \ No newline at end of file From 838dd7accde5b6844126f1530a5c853034c561d0 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Mon, 11 Sep 2023 13:19:12 +0530 Subject: [PATCH 06/27] style: format code in icon frontend --- .../icon-eth-notification/src/pages/Modal.js | 326 ++++++++++-------- 1 file changed, 180 insertions(+), 146 deletions(-) diff --git a/examples/icon-eth-notification/src/pages/Modal.js b/examples/icon-eth-notification/src/pages/Modal.js index bc827d9f..cf26938f 100644 --- a/examples/icon-eth-notification/src/pages/Modal.js +++ b/examples/icon-eth-notification/src/pages/Modal.js @@ -1,115 +1,131 @@ -import React, { useState } from 'react'; -import Modal from 'react-modal'; +import React, { useState } from "react"; +import Modal from "react-modal"; import config from "../config"; import { getMessaging } from "firebase/messaging/sw"; import { getToken } from "firebase/messaging"; const customStyles = { - content: { - width: '50%', - top: '50%', - left: '50%', - right: 'auto', - bottom: 'auto', - marginRight: '-50%', - transform: 'translate(-50%, -50%)', - }, + content: { + width: "50%", + top: "50%", + left: "50%", + right: "auto", + bottom: "auto", + marginRight: "-50%", + transform: "translate(-50%, -50%)", + }, }; -Modal.setAppElement('#root'); +Modal.setAppElement("#root"); function ModalApp(props) { - - const messaging = getMessaging(config.firebase); - const [modalIsOpen, setIsOpen] = React.useState(false); - const [topics, setTopics] = useState([]); - const [selected, setSelected] = useState(""); - const [token, setToken] = useState(""); - const [user_auth, setUserAuth] = useState(props.user_auth_token); - const [address, SetAddress] = useState(""); - const [notification, setNotification] = React.useState({ - visible: false, - title: "", - message: "", - variant: "" - }); - const [busy, setBusy] = useState(false); - getToken(messaging).then(token => setToken(token)) + const messaging = getMessaging(config.firebase); + const [modalIsOpen, setIsOpen] = React.useState(false); + const [topics, setTopics] = useState([]); + const [selected, setSelected] = useState(""); + const [action, setAction] = useState(""); + const [token, setToken] = useState(""); + const [user_auth, setUserAuth] = useState(props.user_auth_token); + const [address, SetAddress] = useState(""); + const [notification, setNotification] = React.useState({ + visible: false, + title: "", + message: "", + variant: "", + }); + const [busy, setBusy] = useState(false); + getToken(messaging) + .then((token) => setToken(token)) .catch((err) => { - console.log(err); + console.log(err); }); - function openModal() { - setIsOpen(true); - } + function openModal() { + setIsOpen(true); + } - function selectTopic(event) { - setSelected(event.target.value); - } + function selectTopic(event) { + console.log(event.target); + setSelected(event.target.value); + } - function afterOpenModal() { - fetch(`${config.api}default/workflow-management`) - .then(response => response.json()) - .then(data => { - if (data[0]) setSelected(data[0].doc.trigger) - setTopics(data); - }); + function afterOpenModal() { + fetch(`${config.api}default/workflow-management`) + .then((response) => response.json()) + .then((data) => { + if (data[0]) setSelected(data[0].doc.trigger); + setTopics(data); + }); + } - } + function closeModal() { + setIsOpen(false); + } - function closeModal() { - setIsOpen(false); - } + function register({ auth_token, topic, token, address, action }) { + setBusy(true); + const input = JSON.stringify({ address }); + var requestOptions = { + method: "POST", + headers: { + "Content-Type": "application/json", + // "mode": "cors", + // "Access-Control-Allow-Origin": "http://localhost:3000", + // "Access-Control-Allow-Methods": "GET,POST,OPTIONS,PUT,PATCH,DELETE", + // "Access-Control-Allow-Credentials" : "true" - function register({ auth_token, topic, token , address, action}) { - setBusy(true); - const input = JSON.stringify({ address}) - var requestOptions = { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ auth_token, topic, token , input, address:action}), - }; - fetch(`${config.api}default/workflow-management`, requestOptions) - .then(response => response.json()) - .then(data => { - setNotification({ - visible: true, - title: "Success", - message: "Registered!", - variant: "positive" - }) - }) - .catch((error) => { - setNotification({ - visible: true, - title: "Failed", - message: "Not Registered!", - variant: "negative" - }) - }).finally(() => { - setBusy(false); - setTimeout(() => { - setNotification({ - visible: false, - title: "", - message: "", - variant: "" - }) - }, 5000); - }); - } - return ( -
- - - {/*
+ }, + body: { + address: action, + topic: topic, + token: token, + input: input, + auth_token: auth_token, + }, + }; + console.log(requestOptions.body); + fetch(`${config.api}default/workflow-management`, requestOptions) + .then((response) => response.json()) + .then((data) => { + setNotification({ + visible: true, + title: "Success", + message: "Registered!", + variant: "positive", + }); + }) + .catch((error) => { + setNotification({ + visible: true, + title: "Failed", + message: "Not Registered!", + variant: "negative", + }); + }) + .finally(() => { + setBusy(false); + setTimeout(() => { + setNotification({ + visible: false, + title: "", + message: "", + variant: "", + }); + }, 5000); + }); + } + return ( +
+ + + {/*
*/} - { - notification.visible &&
- -
- {notification.title} -
-

{notification.message}

-
- } - -
-
- Event Source -
-
- -
-
-
-
- Address -
-
- SetAddress(event.target.value)}/> -
-
-
-
- Push Notification Token -
-
- -
-
-
-
- - -
-
- + {notification.visible && ( +
+ +
{notification.title}
+

{notification.message}

+
+ )} -
+
+
Event Source
+
+ +
+
+
+
Address
+
+ SetAddress(event.target.value)} + /> +
+
+
+
Push Notification Token
+
+ +
+
+
+
+ + +
- ) + +
+ ); } -export default ModalApp \ No newline at end of file +export default ModalApp; From db1aba327d73c36c6374ee844a0b737e991296b7 Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Mon, 11 Sep 2023 14:15:10 +0530 Subject: [PATCH 07/27] fix: workflow reg error --- .../public/firebase-messaging-sw.js | 8 ++++++ .../icon-eth-notification/src/pages/Modal.js | 26 ++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 examples/icon-eth-notification/public/firebase-messaging-sw.js diff --git a/examples/icon-eth-notification/public/firebase-messaging-sw.js b/examples/icon-eth-notification/public/firebase-messaging-sw.js new file mode 100644 index 00000000..e65f054c --- /dev/null +++ b/examples/icon-eth-notification/public/firebase-messaging-sw.js @@ -0,0 +1,8 @@ +if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('../firebase-messaging-sw.js') + .then(function(registration) { + console.log('Registration successful, scope is:', registration.scope); + }).catch(function(err) { + console.log('Service worker registration failed, error:', err); + }); +} \ No newline at end of file diff --git a/examples/icon-eth-notification/src/pages/Modal.js b/examples/icon-eth-notification/src/pages/Modal.js index cf26938f..62256ccd 100644 --- a/examples/icon-eth-notification/src/pages/Modal.js +++ b/examples/icon-eth-notification/src/pages/Modal.js @@ -3,6 +3,7 @@ import Modal from "react-modal"; import config from "../config"; import { getMessaging } from "firebase/messaging/sw"; import { getToken } from "firebase/messaging"; +import { json } from "react-router-dom"; const customStyles = { content: { @@ -35,7 +36,9 @@ function ModalApp(props) { }); const [busy, setBusy] = useState(false); getToken(messaging) - .then((token) => setToken(token)) + .then((token) => { + setToken(token); + }) .catch((err) => { console.log(err); }); @@ -63,29 +66,34 @@ function ModalApp(props) { function register({ auth_token, topic, token, address, action }) { setBusy(true); - const input = JSON.stringify({ address }); + const input = { address: address }; var requestOptions = { method: "POST", headers: { "Content-Type": "application/json", - // "mode": "cors", - // "Access-Control-Allow-Origin": "http://localhost:3000", + mode: "no-cors", + "Access-Control-Allow-Origin": "*", // "Access-Control-Allow-Methods": "GET,POST,OPTIONS,PUT,PATCH,DELETE", // "Access-Control-Allow-Credentials" : "true" - }, - body: { + body: JSON.stringify({ address: action, topic: topic, token: token, input: input, auth_token: auth_token, - }, + }), }; console.log(requestOptions.body); - fetch(`${config.api}default/workflow-management`, requestOptions) - .then((response) => response.json()) + + console.log(requestOptions.headers); + fetch(`${config.api}default/workflow-management.json`, requestOptions) + .then((response) => { + console.log(response); + response.json(); + }) .then((data) => { + console.log(data); setNotification({ visible: true, title: "Success", From 5a9b2bf41f0391928acf0a3e803a036968ecd0be Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Mon, 11 Sep 2023 15:51:00 +0530 Subject: [PATCH 08/27] chore: user registration in icon frontend --- .../src/pages/sign_up.js | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/examples/icon-eth-notification/src/pages/sign_up.js b/examples/icon-eth-notification/src/pages/sign_up.js index 22027285..c402d9e7 100644 --- a/examples/icon-eth-notification/src/pages/sign_up.js +++ b/examples/icon-eth-notification/src/pages/sign_up.js @@ -1,30 +1,56 @@ import React from "react"; +import config from "../config"; + function SignUpForm() { const [state, setState] = React.useState({ name: "", email: "", - password: "" + password: "", }); - const handleChange = evt => { + const handleChange = (evt) => { const value = evt.target.value; setState({ ...state, - [evt.target.name]: value + [evt.target.name]: value, }); }; - const handleOnSubmit = evt => { + const handleOnSubmit = (evt) => { evt.preventDefault(); const { name, email, password } = state; - alert( - `You are sign up with name: ${name} email: ${email} and password: ${password}` - ); + + var requestOptions = { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ name, email, password }), + }; + console.log(requestOptions); + fetch(`${config.api}default/user-registration.json`, requestOptions) + .then((response) => response.json()) + .then((data) => { + alert( + `You are sign up with name: ${name} email: ${email} and password: ${password}` + ); + }) + .catch((err) => { + console.log(err); + alert(`Error ${err}`); + }); + + for (const key in state) { + setState({ + ...state, + [key]: "", + }); + } for (const key in state) { setState({ ...state, - [key]: "" + [key]: "", }); } }; From 1836770b70d3694cd48adbc547f2a872ec8ffa0f Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 12 Sep 2023 11:32:23 +0530 Subject: [PATCH 09/27] chore: update the main page for table --- .../icon-eth-notification/src/pages/Modal.js | 3 +- .../src/pages/main_page.js | 129 +++++++++++------- .../src/pages/sign_in.js | 19 +-- 3 files changed, 92 insertions(+), 59 deletions(-) diff --git a/examples/icon-eth-notification/src/pages/Modal.js b/examples/icon-eth-notification/src/pages/Modal.js index 62256ccd..f0a9e98d 100644 --- a/examples/icon-eth-notification/src/pages/Modal.js +++ b/examples/icon-eth-notification/src/pages/Modal.js @@ -73,13 +73,14 @@ function ModalApp(props) { "Content-Type": "application/json", mode: "no-cors", "Access-Control-Allow-Origin": "*", + authorization: localStorage.getItem("authToken") // "Access-Control-Allow-Methods": "GET,POST,OPTIONS,PUT,PATCH,DELETE", // "Access-Control-Allow-Credentials" : "true" }, body: JSON.stringify({ address: action, topic: topic, - token: token, + token: localStorage.getItem("authToken"), input: input, auth_token: auth_token, }), diff --git a/examples/icon-eth-notification/src/pages/main_page.js b/examples/icon-eth-notification/src/pages/main_page.js index 55f56ee3..94d9153b 100644 --- a/examples/icon-eth-notification/src/pages/main_page.js +++ b/examples/icon-eth-notification/src/pages/main_page.js @@ -2,17 +2,17 @@ import React from "react"; import { useLocation } from "react-router-dom"; import { Nav, NavLink, NavMenu } from "./nav"; -import { useState } from "react"; -import ModalApp from "./Modal"; +import { useState } from "react"; +import ModalApp from "./Modal"; import { - Menu, - Button, - Dropdown, - Container, - Icon, - Image, - Label, - } from 'semantic-ui-react' + Menu, + Button, + Dropdown, + Container, + Icon, + Image, + Label, +} from "semantic-ui-react"; function Main() { const location = useLocation(); @@ -20,22 +20,26 @@ function Main() { console.log(location.state.auth_token); const [auther, setAuth] = useState(location.state.auth_token); + const [activeScreen, setActiveScreen] = useState("home"); + + function handleChangeActiveScreen(screen) { + setActiveScreen(screen); + } + const handleLogout = () => { - location.state.auth_token =""; - console.log(location.state.auth_token); - console.log("kaskkkf"); - setAuth("") + location.state.auth_token = ""; + console.log(location.state.auth_token); + console.log("kaskkkf"); + setAuth(""); + localStorage.clear(); }; - if (auther == ""){ + if (auther == "") { console.log("please login"); - } - return ( <> -
-
-

-

- Aurras is a middleware that acts as an event processor and a low code workflow orchestration platform. - Aurras is being pitched as a next-generation system for enabling decentralized push notification. - This middleware solution listens to events from blockchain applications and propagates them to a registered pool of MQTT brokers. - The broader architecture consist of parachain from which the middleware listens for the events. -

-

- Aurras is a middleware that acts as an event processor and a low code workflow orchestration platform. - Aurras is being pitched as a next-generation system for enabling decentralized push notification. - This middleware solution listens to events from blockchain applications and propagates them to a registered pool of MQTT brokers. - The broader architecture consist of parachain from which the middleware listens for the events. -

+ {activeScreen === "home" && ( +
+

+

+ Aurras is a middleware that acts as an event processor and a low + code workflow orchestration platform. Aurras is being pitched as a + next-generation system for enabling decentralized push notification. + This middleware solution listens to events from blockchain + applications and propagates them to a registered pool of MQTT + brokers. The broader architecture consist of parachain from which + the middleware listens for the events. +

+

+ Aurras is a middleware that acts as an event processor and a low + code workflow orchestration platform. Aurras is being pitched as a + next-generation system for enabling decentralized push notification. + This middleware solution listens to events from blockchain + applications and propagates them to a registered pool of MQTT + brokers. The broader architecture consist of parachain from which + the middleware listens for the events. +

-

- Aurras is a middleware that acts as an event processor and a low code workflow orchestration platform. - Aurras is being pitched as a next-generation system for enabling decentralized push notification. - This middleware solution listens to events from blockchain applications and propagates them to a registered pool of MQTT brokers. - The broader architecture consist of parachain from which the middleware listens for the events. -

-
+

+ Aurras is a middleware that acts as an event processor and a low + code workflow orchestration platform. Aurras is being pitched as a + next-generation system for enabling decentralized push notification. + This middleware solution listens to events from blockchain + applications and propagates them to a registered pool of MQTT + brokers. The broader architecture consist of parachain from which + the middleware listens for the events. +

+
+ )} + + {activeScreen === "table" && table
} + + {/*

diff --git a/examples/icon-eth-notification/src/pages/sign_in.js b/examples/icon-eth-notification/src/pages/sign_in.js index b5907dc8..9e4be5bf 100644 --- a/examples/icon-eth-notification/src/pages/sign_in.js +++ b/examples/icon-eth-notification/src/pages/sign_in.js @@ -1,6 +1,6 @@ import React from "react"; import config from "../config"; -import { useNavigate } from 'react-router-dom'; +import { useNavigate } from "react-router-dom"; function SignInForm() { const navigate = useNavigate(); @@ -37,17 +37,20 @@ function SignInForm() { fetch(`${config.api}default/user-login.json`, requestOptions) .then((response) => response.json()) .then((data) => { + console.log(data); const asd = data; console.log(asd); - const user = asd["user_token"] - navigate('/main', - { state : { - auth_token : user, - }} - ) - + const user = asd["user_token"]; + localStorage.setItem("authToken", user); + navigate( + "/main" + // { state : { + // auth_token : user, + // }} + ); }) .catch((err) => { + alert(`Error ${err}`); console.log(err); }); From 6a55173b4cfcba965d6948a421174a7564084031 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 12 Sep 2023 12:03:47 +0530 Subject: [PATCH 10/27] chore:update invalid password redirection --- .../src/pages/main_page.js | 11 +++++--- .../src/pages/sign_in.js | 26 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/icon-eth-notification/src/pages/main_page.js b/examples/icon-eth-notification/src/pages/main_page.js index 94d9153b..0c33669d 100644 --- a/examples/icon-eth-notification/src/pages/main_page.js +++ b/examples/icon-eth-notification/src/pages/main_page.js @@ -13,12 +13,13 @@ import { Image, Label, } from "semantic-ui-react"; +import { useNavigate } from "react-router-dom"; function Main() { const location = useLocation(); - const user_auth_token = location.state.auth_token; - console.log(location.state.auth_token); - const [auther, setAuth] = useState(location.state.auth_token); + const navigate = useNavigate(); + // const user_auth_token = location.state.auth_token; + const [auther, setAuth] = useState(localStorage.getItem("authToken")); const [activeScreen, setActiveScreen] = useState("home"); @@ -35,7 +36,9 @@ function Main() { }; if (auther == "") { - console.log("please login"); + // console.log("please login"); + alert(" Please Login"); + navigate("/"); } return ( diff --git a/examples/icon-eth-notification/src/pages/sign_in.js b/examples/icon-eth-notification/src/pages/sign_in.js index 9e4be5bf..18fdce51 100644 --- a/examples/icon-eth-notification/src/pages/sign_in.js +++ b/examples/icon-eth-notification/src/pages/sign_in.js @@ -37,17 +37,21 @@ function SignInForm() { fetch(`${config.api}default/user-login.json`, requestOptions) .then((response) => response.json()) .then((data) => { - console.log(data); - const asd = data; - console.log(asd); - const user = asd["user_token"]; - localStorage.setItem("authToken", user); - navigate( - "/main" - // { state : { - // auth_token : user, - // }} - ); + console.log(data["error"]); + if (data.error != "") { + alert("Invalid username or password please login again"); + navigate("/"); + } else { + const asd = data; + const user = asd["user_token"]; + localStorage.setItem("authToken", user); + navigate( + "/main" + // { state : { + // auth_token : user, + // }} + ); + } }) .catch((err) => { alert(`Error ${err}`); From 96f7aed36a6a5d7734bdba8c6e989063ad58071c Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 12 Sep 2023 12:12:00 +0530 Subject: [PATCH 11/27] fix: redirect issue in icon frontend signin page --- examples/icon-eth-notification/src/pages/sign_in.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/icon-eth-notification/src/pages/sign_in.js b/examples/icon-eth-notification/src/pages/sign_in.js index 18fdce51..0647b517 100644 --- a/examples/icon-eth-notification/src/pages/sign_in.js +++ b/examples/icon-eth-notification/src/pages/sign_in.js @@ -38,7 +38,7 @@ function SignInForm() { .then((response) => response.json()) .then((data) => { console.log(data["error"]); - if (data.error != "") { + if (data.error != undefined) { alert("Invalid username or password please login again"); navigate("/"); } else { From 7ab90f689bfc26f670b6d92bac6217b8ec469508 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 12 Sep 2023 12:24:44 +0530 Subject: [PATCH 12/27] chore: removed table button from main page in icon frontend --- examples/icon-eth-notification/src/pages/Modal.js | 2 +- examples/icon-eth-notification/src/pages/main_page.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/icon-eth-notification/src/pages/Modal.js b/examples/icon-eth-notification/src/pages/Modal.js index f0a9e98d..7a4e9282 100644 --- a/examples/icon-eth-notification/src/pages/Modal.js +++ b/examples/icon-eth-notification/src/pages/Modal.js @@ -174,7 +174,7 @@ function ModalApp(props) {
SetAddress(event.target.value)} /> diff --git a/examples/icon-eth-notification/src/pages/main_page.js b/examples/icon-eth-notification/src/pages/main_page.js index 0c33669d..a16e2958 100644 --- a/examples/icon-eth-notification/src/pages/main_page.js +++ b/examples/icon-eth-notification/src/pages/main_page.js @@ -116,15 +116,14 @@ function Main() {
)} - {activeScreen === "table" && table
} - + {/* {activeScreen === "table" && table
} + */} {/*

From 1ba65ad3c57dcb5035b6cb773aac72935017ab87 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Wed, 13 Sep 2023 13:17:19 +0530 Subject: [PATCH 13/27] chore: update token issue on register --- .../src/config/firebase.js | 20 +++++++++---------- .../icon-eth-notification/src/pages/Modal.js | 7 +++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/icon-eth-notification/src/config/firebase.js b/examples/icon-eth-notification/src/config/firebase.js index bd141f39..1047c09b 100644 --- a/examples/icon-eth-notification/src/config/firebase.js +++ b/examples/icon-eth-notification/src/config/firebase.js @@ -1,13 +1,13 @@ -import { initializeApp } from "firebase/app" +import { initializeApp } from "firebase/app"; export const config = { - apiKey: "AIzaSyBFKOWwoGtoPXye_S_tWQHVtOzA_mf874o", - authDomain: "aurras.firebaseapp.com", - projectId: "aurras", - storageBucket: "aurras.appspot.com", - messagingSenderId: "513296427653", - appId: "1:513296427653:web:b753ed51e3f52588e7d7ec", - measurementId: "G-555C15PTHS" -} + apiKey: "AIzaSyBQ6bxRG-BHLIF9W-20Imad4VnMvWEQdPE", + authDomain: "aurras-15d80.firebaseapp.com", + projectId: "aurras-15d80", + storageBucket: "aurras-15d80.appspot.com", + messagingSenderId: "625844804761", + appId: "1:625844804761:web:b5c14238120c1873796c08", + measurementId: "G-1QJ2WE25BE", +}; -export default initializeApp(config); \ No newline at end of file +export default initializeApp(config); diff --git a/examples/icon-eth-notification/src/pages/Modal.js b/examples/icon-eth-notification/src/pages/Modal.js index 7a4e9282..1d22a52e 100644 --- a/examples/icon-eth-notification/src/pages/Modal.js +++ b/examples/icon-eth-notification/src/pages/Modal.js @@ -64,7 +64,7 @@ function ModalApp(props) { setIsOpen(false); } - function register({ auth_token, topic, token, address, action }) { + function register({ topic, token, address, action }) { setBusy(true); const input = { address: address }; var requestOptions = { @@ -80,9 +80,9 @@ function ModalApp(props) { body: JSON.stringify({ address: action, topic: topic, - token: localStorage.getItem("authToken"), + token: token, input: input, - auth_token: auth_token, + auth_token: localStorage.getItem("authToken"), }), }; console.log(requestOptions.body); @@ -191,7 +191,6 @@ function ModalApp(props) {
)} - {/* {activeScreen === "table" && table
} - */} - - {/*
-

-
*/} -

Thanks to hugobyte

diff --git a/examples/icon-eth-notification/src/pages/Modal.js b/examples/icon-eth-notification/src/pages/Modal.js index d04c3f98..67cfd93e 100644 --- a/examples/icon-eth-notification/src/pages/Modal.js +++ b/examples/icon-eth-notification/src/pages/Modal.js @@ -77,8 +77,6 @@ function ModalApp(props) { mode: "no-cors", "Access-Control-Allow-Origin": "*", authorization: localStorage.getItem("authToken"), - // "Access-Control-Allow-Methods": "GET,POST,OPTIONS,PUT,PATCH,DELETE", - // "Access-Control-Allow-Credentials" : "true" }, body: JSON.stringify({ address: action, @@ -137,15 +135,6 @@ function ModalApp(props) { style={customStyles} contentLabel="Register Icon Notification" > - {/*
-
-
- -
-
-
*/} {notification.visible && (
diff --git a/examples/icon-eth-notification/src/pages/Navigate.js b/examples/icon-eth-notification/src/pages/Navigate.js index d7d3303d..018ad562 100644 --- a/examples/icon-eth-notification/src/pages/Navigate.js +++ b/examples/icon-eth-notification/src/pages/Navigate.js @@ -1,7 +1,7 @@ import { FaBars } from "react-icons/fa"; import { NavLink as Link } from "react-router-dom"; import styled from "styled-components"; - + export const Nav = styled.nav` background: #ffffff; height: 85px; @@ -10,7 +10,7 @@ export const Nav = styled.nav` padding: 0.2rem calc((100vw - 1000px) / 2); z-index: 12; `; - + export const NavLink = styled(Link)` color: #808080; display: flex; @@ -23,7 +23,7 @@ export const NavLink = styled(Link)` color: #4d4dff; } `; - + export const Bars = styled(FaBars)` display: none; color: #808080; @@ -37,7 +37,7 @@ export const Bars = styled(FaBars)` cursor: pointer; } `; - + export const NavMenu = styled.div` display: flex; align-items: center; @@ -50,4 +50,4 @@ white-space: nowrap; */ @media screen and (max-width: 768px) { display: none; } -`; \ No newline at end of file +`; diff --git a/examples/icon-eth-notification/src/pages/SignIn.js b/examples/icon-eth-notification/src/pages/SignIn.js index 0647b517..75c8b594 100644 --- a/examples/icon-eth-notification/src/pages/SignIn.js +++ b/examples/icon-eth-notification/src/pages/SignIn.js @@ -24,8 +24,6 @@ function SignInForm() { const { email, password } = state; - // alert(`You are login with email: ${email} and password: ${password}`); - var requestOptions = { method: "POST", headers: { @@ -45,12 +43,7 @@ function SignInForm() { const asd = data; const user = asd["user_token"]; localStorage.setItem("authToken", user); - navigate( - "/main" - // { state : { - // auth_token : user, - // }} - ); + navigate("/main"); } }) .catch((err) => { @@ -70,18 +63,6 @@ function SignInForm() {

Sign in

- {/* */} - {/* or use your account */}

Create Account

- {/* */} - {/* or use your email for registration */} { +function Home() { + const [type, setType] = useState("signIn"); + const handleOnClick = (text) => { if (text !== type) { setType(text); return; @@ -51,23 +49,7 @@ const [type, setType] = useState("signIn");
- - - ); - } - - export default Home; - - +} - -// const Home = () => { -// return ( -//
-//

Sign Up Successful

-//
-// ); -// }; - -// export default Home; \ No newline at end of file +export default Home; diff --git a/examples/icon-eth-notification/src/styles.css b/examples/icon-eth-notification/src/styles.css index 090c8395..869568d0 100644 --- a/examples/icon-eth-notification/src/styles.css +++ b/examples/icon-eth-notification/src/styles.css @@ -268,9 +268,7 @@ footer a { display: flex; align-items: top; justify-content: left; - /* height: 100px; */ top:10%; - /* width:30%; */ } .one @@ -283,18 +281,14 @@ footer a { .two { background-color:white; - /* width: 50%; */ height: 550px; - /* float: left; */ } .three { background-color: rgb(17, 182, 168); - /* float: left; */ } .para{ - /* width: 50%; */ font-size: 14px; font-weight: 100; From c2ee80b5d982ece55ecd2ec42d4f0dcd8d0b0041 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Tue, 19 Sep 2023 11:34:13 +0530 Subject: [PATCH 21/27] chore: update trigger for icon notification --- actions/workflow-invoker/deploy.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/actions/workflow-invoker/deploy.sh b/actions/workflow-invoker/deploy.sh index 23b3019e..382a2954 100755 --- a/actions/workflow-invoker/deploy.sh +++ b/actions/workflow-invoker/deploy.sh @@ -23,7 +23,9 @@ check wsk build $WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ ---auth "$openwhiskApiKey" --param polkadot_payout_trigger "send-payout-notify" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "workflow_management_db" -a provide-api-key true +--auth "$openwhiskApiKey" --param polkadot_payout_trigger "call-actions-trigger" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "workflow_management_db" -a provide-api-key true -$WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "send-payout-notify" --auth "$openwhiskApiKey" -# $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "payout_notify-rule" "send-payout-notify" "payout_notify" --auth "$openwhiskApiKey" // after deploying the action for polkadot payout +$WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "call-actions-trigger" --auth "$openwhiskApiKey" +$WSK_CLI -i --apihost "$openwhiskApiHost" rule update "icon-eth-notification-rule" "call-actions-trigger" "icon-eth-notification" --auth "$openwhiskApiKey" + +# $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "payout_notify-rule" "call-actions-trigger" "payout_notify" --auth "$openwhiskApiKey" # after deploying the action for polkadot payout From 668f439c31e29cb5d0969ee05085aaa94c388405 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Wed, 27 Sep 2023 01:23:44 +0530 Subject: [PATCH 22/27] chore: update workflow invoker action for invoke action instead of invoking trigger --- actions/workflow-invoker/deploy.sh | 6 +++--- actions/workflow-invoker/src/lib.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/actions/workflow-invoker/deploy.sh b/actions/workflow-invoker/deploy.sh index 382a2954..27296422 100755 --- a/actions/workflow-invoker/deploy.sh +++ b/actions/workflow-invoker/deploy.sh @@ -23,9 +23,9 @@ check wsk build $WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ ---auth "$openwhiskApiKey" --param polkadot_payout_trigger "call-actions-trigger" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "workflow_management_db" -a provide-api-key true +--auth "$openwhiskApiKey" --param invoke_action_name "icon-eth-notification" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "workflow_management_db" -a provide-api-key true -$WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "call-actions-trigger" --auth "$openwhiskApiKey" -$WSK_CLI -i --apihost "$openwhiskApiHost" rule update "icon-eth-notification-rule" "call-actions-trigger" "icon-eth-notification" --auth "$openwhiskApiKey" +# $WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "call-actions-trigger" --auth "$openwhiskApiKey" +# $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "icon-eth-notification-rule" "call-actions-trigger" "icon-eth-notification" --auth "$openwhiskApiKey" # $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "payout_notify-rule" "call-actions-trigger" "payout_notify" --auth "$openwhiskApiKey" # after deploying the action for polkadot payout diff --git a/actions/workflow-invoker/src/lib.rs b/actions/workflow-invoker/src/lib.rs index f8c99b7f..38f1dc15 100644 --- a/actions/workflow-invoker/src/lib.rs +++ b/actions/workflow-invoker/src/lib.rs @@ -14,7 +14,7 @@ use types::Topic; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] struct Input { messages: Vec, - polkadot_payout_trigger: String, + invoke_action_name: String, db_name: String, db_url: String, } @@ -63,16 +63,16 @@ impl Action { Ok(parsed.data) } - pub fn invoke_trigger(&mut self, payload: &mut Vec) -> Result { + pub fn invoke_action(&mut self, payload: &mut Vec) -> Result { let mut failed_triggers = vec![]; for message in payload.iter_mut() { let data = serde_json::from_str::(&self.params.messages[0].value).unwrap(); update_with(message, &data); - let trigger = self.params.polkadot_payout_trigger.clone(); + let trigger = self.params.invoke_action_name.clone(); if self .get_context() - .invoke_trigger(&trigger, &serde_json::json!({"data": message})) + .invoke_action(&trigger, &serde_json::json!({"data": message})) .is_err() { failed_triggers.push(self.params.messages[0].value.clone()); @@ -97,7 +97,7 @@ pub fn main(args: Value) -> Result { action.init(); let mut payload = action.fetch_input()?; - action.invoke_trigger(&mut payload) + action.invoke_action(&mut payload) } #[cfg(test)] @@ -122,7 +122,7 @@ mod tests { let mut action = Action::new(Input { db_url: url.clone(), db_name: "test".to_string(), - polkadot_payout_trigger: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), + invoke_action_name: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), messages: vec![Message { topic: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), value: serde_json::json!({ "era" :0}).to_string(), @@ -146,7 +146,7 @@ mod tests { let action = Action::new(Input { db_url: "url".to_string(), db_name: "test".to_string(), - polkadot_payout_trigger: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), + invoke_action_name: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), messages: vec![Message { topic: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), value: serde_json::json!({ "era" :0}).to_string(), From 4aecc04095498faed8057dfc66dcc75be08cf30b Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Thu, 28 Sep 2023 13:01:24 +0530 Subject: [PATCH 23/27] chore: update event registration deply script --- register_event_source_polkadot.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/register_event_source_polkadot.sh b/register_event_source_polkadot.sh index 488e1c30..91f2594d 100755 --- a/register_event_source_polkadot.sh +++ b/register_event_source_polkadot.sh @@ -7,8 +7,8 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} eventRegistrationAction=${eventRegistrationAction:-event-registration} -name=${name:-workflow-invoker} -polkaDotPayout=${polkaDotPayout:-workflow-invoker} +name=${name:-payout-notifiacation} # provide the action name to be invoked when event comes +workflowInvoker=${workflowInvoker:-workflow-invoker} SCRIPTS_DIR="$PWD/scripts" source "$SCRIPTS_DIR/accept_params.sh" @@ -20,6 +20,6 @@ check jq TRIGGER=$($WSK_CLI -i --apihost "$openwhiskApiHost" action invoke "/${openwhiskNamespace}/${eventRegistrationAction}" \ --auth "$openwhiskApiKey" --param name "$name" --blocking --result | $JSON_PARSER -r '.trigger') -$WSK_CLI -i --apihost "$openwhiskApiHost" rule update "$TRIGGER-polkadot-payout" $TRIGGER $polkaDotPayout --auth "$openwhiskApiKey" +$WSK_CLI -i --apihost "$openwhiskApiHost" rule update "$TRIGGER-polkadot-payout" $TRIGGER $workflowInvoker --auth "$openwhiskApiKey" echo "Add TOPICS=
=$TRIGGER as environment variable for the substrate based event feed service, where
can be balances, system etc" \ No newline at end of file From 020013cce3857c2ceaa5dd1c4210a086984f0af8 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Wed, 4 Oct 2023 15:29:29 +0530 Subject: [PATCH 24/27] chore: updated deploy script in icon-eth-notification --- actions/icon-eth-notification/deploy.sh | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 actions/icon-eth-notification/deploy.sh diff --git a/actions/icon-eth-notification/deploy.sh b/actions/icon-eth-notification/deploy.sh new file mode 100755 index 00000000..d921e60b --- /dev/null +++ b/actions/icon-eth-notification/deploy.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# To run this command +# ./deploy.sh --openwhiskApiHost --openwhiskApiKey --openwhiskNamespace + +openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} +openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} +openwhiskNamespace=${openwhiskNamespace:-guest} +actionHome=${actionHome:-actions/icon-eth-notification} + +ACTION="icon-eth-notification" +ACTION_TYPE="rust" +SCRIPTS_DIR="$PWD/scripts" +SRC_DIR="$PWD/${actionHome}" +TEMP_DIR="$PWD/${actionHome}/temp" + +source "$SCRIPTS_DIR/accept_params.sh" +source "$SCRIPTS_DIR/check_dependencies.sh" +source "$SCRIPTS_DIR/build_action.sh" + +check wsk + +build + +$WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ +--auth "$openwhiskApiKey" -a provide-api-key true From 18423e2823e0ed2a261cf91491410f7b2aaf65b5 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Wed, 4 Oct 2023 18:12:54 +0530 Subject: [PATCH 25/27] chore:updated main deploy script for icon notification --- deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index e0ba66b1..73d85408 100755 --- a/deploy.sh +++ b/deploy.sh @@ -6,10 +6,10 @@ openwhiskApiHost=${openwhiskApiHost:-https://localhost:31001} openwhiskApiKey=${openwhiskApiKey:-23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP} openwhiskNamespace=${openwhiskNamespace:-guest} -build=${build:-push-notification,balance-filter,event-receiver,event-registration,balance-notification-registration,event-producer,kafka-provider-feed,kafka-provider-web,substrate-event-processor,user-registration,user-login,workflow-invoker,workflow-registration,workflow-management} +build=${build:-push-notification,balance-filter,event-receiver,event-registration,balance-notification-registration,event-producer,kafka-provider-feed,kafka-provider-web,substrate-event-processor,user-registration,user-login,workflow-invoker,workflow-registration,workflow-management,eth-event-processor,icon-event-processor,icon-eth-notification} skip=${skip:-} -actions=("actions/push-notification" "actions/balance-filter" "actions/event-receiver" "actions/event-registration" "actions/balance-notification-registration" "actions/event-producer" "actions/kafka-provider-feed" "actions/kafka-provider-web" "actions/substrate-event-processor" "actions/user-registration" "actions/user-login" "actions/workflow-invoker" "actions/workflow-registration" "actions/workflow-management") +actions=("actions/push-notification" "actions/balance-filter" "actions/event-receiver" "actions/event-registration" "actions/balance-notification-registration" "actions/event-producer" "actions/kafka-provider-feed" "actions/kafka-provider-web" "actions/substrate-event-processor" "actions/user-registration" "actions/user-login" "actions/workflow-invoker" "actions/workflow-registration" "actions/workflow-management","actions/eth-event-processor","actions/icon-event-processor","actions/icon-eth-notification") source ./scripts/accept_params.sh source ./scripts/util.sh From f395c1ef995eda272d27e493e2e6093a55c064b7 Mon Sep 17 00:00:00 2001 From: Ajay Kumar <87293689+ajaykumargdr@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:58:25 +0530 Subject: [PATCH 26/27] feat: implement invoking action based on topic in workflow invoker (#79) * chore: Add a method to fetch the action name that needs to be invoked from the database * fix: debug parsing action name from json value which is fetched from the database * chore: add method for fetching invoking action name from the database & add test cases to test the method * fix: debug error in get_action_name_fail test case * style: Format code according to coding standards --- actions/workflow-invoker/deploy.sh | 2 +- actions/workflow-invoker/src/lib.rs | 111 +++++++++++++++++++++++++--- 2 files changed, 103 insertions(+), 10 deletions(-) diff --git a/actions/workflow-invoker/deploy.sh b/actions/workflow-invoker/deploy.sh index 27296422..f5905d75 100755 --- a/actions/workflow-invoker/deploy.sh +++ b/actions/workflow-invoker/deploy.sh @@ -23,7 +23,7 @@ check wsk build $WSK_CLI -i --apihost "$openwhiskApiHost" action update ${ACTION} "$TEMP_DIR/main.zip" --docker "$DOCKER_IMAGE" \ ---auth "$openwhiskApiKey" --param invoke_action_name "icon-eth-notification" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "workflow_management_db" -a provide-api-key true +--auth "$openwhiskApiKey" --param invoke_action_name "icon-eth-notification" --param db_url "http://admin:p@ssw0rd@172.17.0.1:5984" --param db_name "workflow_management_db" --param event_registration_db "event_registration_db" -a provide-api-key true # $WSK_CLI -i --apihost "$openwhiskApiHost" trigger update "call-actions-trigger" --auth "$openwhiskApiKey" # $WSK_CLI -i --apihost "$openwhiskApiHost" rule update "icon-eth-notification-rule" "call-actions-trigger" "icon-eth-notification" --auth "$openwhiskApiKey" diff --git a/actions/workflow-invoker/src/lib.rs b/actions/workflow-invoker/src/lib.rs index 38f1dc15..a59475a5 100644 --- a/actions/workflow-invoker/src/lib.rs +++ b/actions/workflow-invoker/src/lib.rs @@ -14,7 +14,7 @@ use types::Topic; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] struct Input { messages: Vec, - invoke_action_name: String, + event_registration_db: String, db_name: String, db_url: String, } @@ -63,23 +63,54 @@ impl Action { Ok(parsed.data) } + // fetching the action name from database + fn get_action_name(&mut self) -> Result { + // creating connection with the event registration database + let db = self.connect_db(&self.params.db_url, &self.params.event_registration_db); + let context = Context::new(db, None); + + let data: Value = match context.get_document(&self.params.messages[0].topic) { + Ok(document) => document, + Err(_) => { + return Err(format!( + "topic {} is not exists in the database", + &self.params.messages[0].topic + )) + .map_err(serde::de::Error::custom); + } + }; + + // getting action name from the document + let action_name: String = + serde_json::from_value( + data + .get("name") + .unwrap() + .clone() + ).unwrap(); + + Ok(action_name) + } + pub fn invoke_action(&mut self, payload: &mut Vec) -> Result { - let mut failed_triggers = vec![]; + let mut failed_actions = vec![]; + + let action_name = self.get_action_name().unwrap(); + for message in payload.iter_mut() { let data = serde_json::from_str::(&self.params.messages[0].value).unwrap(); update_with(message, &data); - let trigger = self.params.invoke_action_name.clone(); if self .get_context() - .invoke_action(&trigger, &serde_json::json!({"data": message})) + .invoke_action(&action_name, &serde_json::json!({"data": message})) .is_err() { - failed_triggers.push(self.params.messages[0].value.clone()); + failed_actions.push(self.params.messages[0].value.clone()); } } - if !failed_triggers.is_empty() { - return Err(format!("error in triggers {:?}", failed_triggers)) + if !failed_actions.is_empty() { + return Err(format!("error in triggers {:?}", failed_actions)) .map_err(serde::de::Error::custom); } Ok(serde_json::json!({ @@ -122,7 +153,7 @@ mod tests { let mut action = Action::new(Input { db_url: url.clone(), db_name: "test".to_string(), - invoke_action_name: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), + event_registration_db: "event_registration_db".to_string(), messages: vec![Message { topic: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), value: serde_json::json!({ "era" :0}).to_string(), @@ -137,6 +168,7 @@ mod tests { let _ = workflow_management_db_context .insert_document(&doc, Some(action.params.messages[0].topic.clone())); let res = action.fetch_input(); + assert!(res.is_ok()); couchdb.delete().await.expect("Stopping Container Failed"); } @@ -146,7 +178,7 @@ mod tests { let action = Action::new(Input { db_url: "url".to_string(), db_name: "test".to_string(), - invoke_action_name: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), + event_registration_db: "event_registration_db".to_string(), messages: vec![Message { topic: "418a8b8c-02b8-11ec-9a03-0242ac130003".to_string(), value: serde_json::json!({ "era" :0}).to_string(), @@ -163,4 +195,65 @@ mod tests { serde_json::json!({"url":"todo!()","era":0,"owner_key":"todo!()","validator":"todo!()"}) ) } + + #[tokio::test] + async fn get_action_name_pass() { + let config = Config::new(); + let couchdb = CouchDB::new("admin".to_string(), "password".to_string()) + .await + .unwrap(); + sleep(Duration::from_millis(5000)).await; + let url = format!("http://admin:password@localhost:{}", couchdb.port()); + let mut action = Action::new(Input { + db_url: url.clone(), + db_name: "test".to_string(), + event_registration_db: "event_registration_db".to_string(), + messages: vec![Message { + topic: "0a36fd24-84ac-420e-9187-912929c782ea".to_string(), + value: serde_json::json!({ "era" :0}).to_string(), + }], + }); + action.init(&config); + + let event_registration_db = + action.connect_db(&action.params.db_url, "event_registration_db"); + let event_registration_db_context = Context::new(event_registration_db, None); + + let json_value = r#"{"name": "icon-eth-notification", "trigger": "0a36fd24-84ac-420e-9187-912929c782ea"}"#; + let doc: Value = serde_json::from_str(json_value).unwrap(); + + let _ = event_registration_db_context + .insert_document(&doc, Some(action.params.messages[0].topic.clone())); + + let invoke_action_name = action.get_action_name().unwrap(); + assert_eq!(&invoke_action_name, "icon-eth-notification"); + + couchdb.delete().await.expect("Stopping Container Failed"); + } + + #[tokio::test] + #[should_panic = "topic 0a36fd24-84ac-420e-9187-912929c782ea is not exists in the database"] + async fn get_action_name_fail() { + let config = Config::new(); + let couchdb = CouchDB::new("admin".to_string(), "password".to_string()) + .await + .unwrap(); + sleep(Duration::from_millis(5000)).await; + let url = format!("http://admin:password@localhost:{}", couchdb.port()); + let mut action = Action::new(Input { + db_url: url.clone(), + db_name: "test".to_string(), + event_registration_db: "event_registration_db".to_string(), + messages: vec![Message { + topic: "0a36fd24-84ac-420e-9187-912929c782ea".to_string(), + value: serde_json::json!({ "era" :0}).to_string(), + }], + }); + action.init(&config); + + let invoke_action_name = action.get_action_name().unwrap(); + assert_eq!(&invoke_action_name, "icon-eth-notification"); + + couchdb.delete().await.expect("Stopping Container Failed"); + } } From 514a067a689b3c1aa5eea53f9fb45ae783c62653 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Sun, 12 May 2024 21:42:19 +0530 Subject: [PATCH 27/27] fix: issue in workflow invoker action params --- actions/workflow-invoker/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/workflow-invoker/src/lib.rs b/actions/workflow-invoker/src/lib.rs index 1e9faeaf..3d4c1980 100644 --- a/actions/workflow-invoker/src/lib.rs +++ b/actions/workflow-invoker/src/lib.rs @@ -58,7 +58,7 @@ impl Action { } pub fn fetch_input(&mut self) -> Result, Error> { - let id = self.params.messages.clone()[0].topic.clone(); + let id: String = self.params.messages.clone()[0].topic.clone(); let data = self.get_context().get_document(&id)?; let parsed = serde_json::from_value::(data)?; Ok(parsed.data) @@ -93,14 +93,14 @@ impl Action { Ok(action_name) } - pub fn invoke_action(&mut self, payload: &mut Vec) -> Result { + pub fn invoke_action(&mut self, payload: &mut [UserData]) -> Result { let mut failed_actions = vec![]; let action_name = self.get_action_name().unwrap(); for message in payload.iter_mut() { let data = serde_json::from_str::(&self.params.messages[0].value).unwrap(); - update_with(&mut user.input_data, &data); + update_with(&mut message.input_data, &data); if self .get_context()