forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(event streaming): implement push-only streaming channels and SSE (…
…#1945) This implements streaming channels using mpsc(underlying part of SSE) and SSE for sending data to clients continuously, NETWORK event is implemented to show the new functionality. All platforms other than WASM are supported. --------- Signed-off-by: onur-ozkan <work@onurozkan.dev>
- Loading branch information
1 parent
2ce6e4a
commit e9559c2
Showing
23 changed files
with
659 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Listening event-stream from komodo-defi-framework | ||
|
||
1. Start komodo-defi-framework with event streaming activated | ||
2. Run a local HTTP server | ||
- if you use Python 3, run: | ||
``` | ||
python3 -m http.server 8000 | ||
``` | ||
- if you use Python 2, run: | ||
``` | ||
python -m SimpleHTTPServer 8000 | ||
``` | ||
|
||
You should now be able to observe events from the komodo-defi-framework through the SSE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<body> | ||
|
||
<h1>Events</h1> | ||
<div id="result"></div> | ||
|
||
<script> | ||
if (typeof (EventSource) !== "undefined") { | ||
var source = new EventSource("http://localhost:7783/event-stream", { | ||
withCredentials: false, | ||
}); | ||
source.onmessage = function (event) { | ||
var currentDatetime = new Date().toLocaleString(); | ||
var eventData = currentDatetime + ": " + event.data + "<hr/>"; | ||
document.getElementById("result").insertAdjacentHTML("afterbegin", eventData); | ||
}; | ||
} else { | ||
document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events..."; | ||
} | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>MM2 example</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<div> | ||
<label for="wid_conf_input">Config JSON</label> | ||
<br> | ||
<textarea id="wid_conf_input" cols="100" rows="7">{"gui":"WASMTEST","mm2":1,"passphrase":"wasmtest","allow_weak_password":true,"rpc_password":"testpsw","netid":7777,"coins":[{"coin":"ETH","protocol":{"type":"ETH"}},{"coin":"RICK","overwintered":1,"txversion":4,"protocol":{"type":"UTXO"}},{"coin":"MORTY","overwintered":1,"txversion":4,"protocol":{"type":"UTXO"}}]}</textarea> | ||
<br> | ||
<button id="wid_run_mm2_button" disabled="disabled">Start MM2</button> | ||
<button id="wid_stop_mm2_button" disabled="disabled">Stop MM2</button> | ||
<br> | ||
<br> | ||
<label for="wid_rpc_input">RPC payload JSON</label> | ||
<br> | ||
<textarea id="wid_rpc_input" cols="100" rows="9">[{"userpass":"testpsw","method":"electrum","mm2":1,"coin":"RICK","tx_history":true,"servers":[{"url":"electrum1.cipig.net:30017","protocol":"WSS"}]},{"userpass":"testpsw","method":"electrum","mm2":1,"coin":"MORTY","tx_history":true,"servers":[{"url":"electrum1.cipig.net:30018","protocol":"WSS"}]},{"userpass":"testpsw","method":"enable","mm2":1,"coin":"ETH","swap_contract_address":"0x8500AFc0bc5214728082163326C2FF0C73f4a871","urls":["http://eth1.cipig.net:8555"]}]</textarea> | ||
<br> | ||
<button id="wid_mm2_rpc_button" disabled="disabled">Submit request</button> | ||
</div> | ||
<div> | ||
<label for="wid_conf_input">Config JSON</label> | ||
<br> | ||
<textarea id="wid_conf_input" cols="100" | ||
rows="7">{"gui":"WASMTEST","mm2":1,"passphrase":"wasmtest","allow_weak_password":true,"rpc_password":"testpsw","netid":7777,"coins":[{"coin":"ETH","protocol":{"type":"ETH"}},{"coin":"RICK","overwintered":1,"txversion":4,"protocol":{"type":"UTXO"}},{"coin":"MORTY","overwintered":1,"txversion":4,"protocol":{"type":"UTXO"}}]}</textarea> | ||
<br> | ||
<button id="wid_run_mm2_button" disabled="disabled">Start MM2</button> | ||
<button id="wid_stop_mm2_button" disabled="disabled">Stop MM2</button> | ||
<br> | ||
<br> | ||
<label for="wid_rpc_input">RPC payload JSON</label> | ||
<br> | ||
<textarea id="wid_rpc_input" cols="100" | ||
rows="9">[{"userpass":"testpsw","method":"electrum","mm2":1,"coin":"RICK","tx_history":true,"servers":[{"url":"electrum1.cipig.net:30017","protocol":"WSS"}]},{"userpass":"testpsw","method":"electrum","mm2":1,"coin":"MORTY","tx_history":true,"servers":[{"url":"electrum1.cipig.net:30018","protocol":"WSS"}]},{"userpass":"testpsw","method":"enable","mm2":1,"coin":"ETH","swap_contract_address":"0x8500AFc0bc5214728082163326C2FF0C73f4a871","urls":["http://eth1.cipig.net:8555"]}]</textarea> | ||
<br> | ||
<button id="wid_mm2_rpc_button" disabled="disabled">Submit request</button> | ||
</div> | ||
|
||
</body> | ||
<script src="script.js" type="module"></script> | ||
</html> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "mm2_event_stream" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
async-trait = "0.1" | ||
cfg-if = "1.0" | ||
common = { path = "../common" } | ||
parking_lot = "0.12" | ||
serde = { version = "1", features = ["derive", "rc"] } | ||
tokio = { version = "1", features = ["sync"] } | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1", features = ["sync", "macros", "time", "rt"] } | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
wasm-bindgen-test = { version = "0.3.2" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::EventStreamConfiguration; | ||
use async_trait::async_trait; | ||
|
||
#[async_trait] | ||
pub trait EventBehaviour { | ||
/// Unique name of the event. | ||
const EVENT_NAME: &'static str; | ||
|
||
/// Event handler that is responsible for broadcasting event data to the streaming channels. | ||
async fn handle(self, interval: f64); | ||
|
||
/// Spawns the `Self::handle` in a separate thread if the event is active according to the mm2 configuration. | ||
/// Does nothing if the event is not active. | ||
fn spawn_if_active(self, config: &EventStreamConfiguration); | ||
} |
Oops, something went wrong.