-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add readme and producer example (#108)
* chore: added example for producer * chore: update the read me
- Loading branch information
Showing
6 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,58 @@ | ||
# Aurras Lite Runtime | ||
A runtime leveraging Secure Scuttlebutt for event streaming, designed to facilitate the seamless execution of workflows on the user side in response to specific events. | ||
This runtime harnesses the capabilities of Secure Scuttlebutt, a decentralized messaging protocol, to efficiently stream events securely across a network. As events are emitted, the runtime captures and processes them, initiating corresponding workflows tailored to the user's preferences and requirements. | ||
|
||
![alt text](../../docs/runtime-lite.png) | ||
|
||
# Pre-requisites | ||
- [SSB-server](https://github.com/ssbc/ssb-server) | ||
- [Rust](https://www.rust-lang.org/tools/install) | ||
|
||
|
||
## Setup | ||
1. Install the ssb-server and start it. | ||
|
||
ssb-server start | ||
2. Run the client producer or consumer or client | ||
|
||
corgo run --bin consumer | ||
|
||
### Integration test setup | ||
1. Setup a network, got the script folder | ||
|
||
./ssb-up.sh start | ||
|
||
2. Create an invite | ||
|
||
./ssb-up.sh create-invite | ||
|
||
3. Copy the invite and run | ||
|
||
./ssb-up.sh accept-invite <paste copied invite here> | ||
|
||
4. Export the secret for connecting the client | ||
|
||
./ssb-up.sh copy-secret | ||
*Note:* This will export the secret to secret folder in the current directory. | ||
|
||
5. Move to lite directort and create a .env file and export the secret path port for consumer. | ||
|
||
SECRET=../aurras/runtime/lite/scripts/secret/consumer_secret | ||
PORT=8015 | ||
|
||
6. Run the consumer client | ||
|
||
congo run --bin consumer | ||
|
||
7. Run a local polakdot chain for test purpose | ||
|
||
docker run -p 9944:9944 parity/polkadot:v1.0.0 --dev --rpc-external | ||
|
||
8. Run the basic example for producer with required environment variables | ||
|
||
PUB_ADDRESS="@pjrBmtifFU9P9NhoHRiPbn3O3xGUXtsLWJXhxLEpkug=.ed25519" | ||
PRODUCER_SECRET=./runtime/lite/scripts/secret/consumer_secret | ||
PRODUCER_PORT=8014 | ||
*Note:* Get the pub address using script `./ssb-up.sh pub-whoami` | ||
|
||
9. Make transfer event on the chain manually. |
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,94 @@ | ||
use dotenv::dotenv; | ||
use kuska_ssb::{api::dto::content::Mention, keystore::read_patchwork_config}; | ||
use runtime::kuska_ssb_client::client::Client; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
dotenv().ok(); | ||
println!("start"); | ||
let secret = std::env::var("PRODUCER_SECRET").unwrap_or_else(|_| { | ||
let home_dir = dirs::home_dir().unwrap(); | ||
std::format!("{}/.ssb/secret", home_dir.to_string_lossy()) | ||
}); | ||
|
||
let port = std::env::var("PRODUCER_PORT").unwrap_or("8014".to_string()); | ||
let pub_address = std::env::var("PUB_ADDRESS").expect("Pub address must be provided"); | ||
|
||
let mut file = async_std::fs::File::open(secret).await.unwrap(); | ||
let key = read_patchwork_config(&mut file).await.unwrap(); | ||
|
||
let mut client = Client::new(Some(key), "0.0.0.0".to_string(), port) | ||
.await | ||
.unwrap(); | ||
|
||
use subxt::{OnlineClient, PolkadotConfig}; | ||
|
||
#[subxt::subxt(runtime_metadata_path = "./src/modules/utils/polkadot_metadata_small.scale")] | ||
pub mod polkadot {} | ||
|
||
let api = OnlineClient::<PolkadotConfig>::new().await.unwrap(); | ||
|
||
// Subscribe to all finalized blocks: | ||
let mut blocks_sub = api.blocks().subscribe_finalized().await.unwrap(); | ||
|
||
// For each block, print a bunch of information about it: | ||
while let Some(block) = blocks_sub.next().await { | ||
let block = block.unwrap(); | ||
|
||
let block_number = block.header().number; | ||
let block_hash = block.hash(); | ||
|
||
println!("Block #{block_number}:"); | ||
println!(" Hash: {block_hash}"); | ||
println!(" Extrinsics:"); | ||
|
||
// Code for automate transfer | ||
// use subxt_signer::sr25519::dev; | ||
// if block_number == 10 { | ||
// let dest = dev::bob().public_key().into(); | ||
// let tx = polkadot::tx().balances().transfer_allow_death(dest, 10_000); | ||
// let from = dev::alice(); | ||
// let _events = api | ||
// .tx() | ||
// .sign_and_submit_then_watch_default(&tx, &from) | ||
// .await | ||
// .unwrap(); | ||
// } | ||
|
||
// Log each of the extrinsic with it's associated events: | ||
let extrinsics = block.extrinsics().await.unwrap(); | ||
for ext in extrinsics.iter() { | ||
let ext = ext.unwrap(); | ||
let events = ext.events().await.unwrap(); | ||
let transfer = events | ||
.find_first::<polkadot::balances::events::Transfer>() | ||
.unwrap(); | ||
|
||
match transfer { | ||
Some(transfer) => { | ||
let from_addr = transfer.from.to_string(); | ||
let to_addr = transfer.from.to_string(); | ||
let amount = transfer.amount; | ||
println!("{from_addr:?}"); | ||
|
||
let value = format!( | ||
"{{\"from\":\"{}\",\"to\":\"{}\",\"amount\":\"{}\"}}", | ||
from_addr, to_addr, amount | ||
); | ||
|
||
let menttion = Mention { | ||
link: pub_address.clone(), | ||
name: None, | ||
}; | ||
|
||
let result = client | ||
.publish(&value.to_string(), Some(vec![menttion])) | ||
.await; | ||
// assert!(result.is_ok()); | ||
// break 'outer; | ||
} | ||
None => (), | ||
} | ||
} | ||
} | ||
} |
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