step1 script

This commit is contained in:
folex
2019-08-15 18:46:20 +03:00
parent 0815a14ff2
commit aa4d9e1b02
9 changed files with 52 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ pub type AppResult<T> = ::std::result::Result<T, Box<Error>>;
#[derive(Deserialize)]
#[serde(tag = "action")]
pub enum Request {
Post { msg: String, handle: String },
Post { message: String, handle: String },
Fetch { handle: Option<String> },
}

View File

@@ -22,7 +22,7 @@ fn init() {
fn run(arg: String) -> String {
// Parse and handle JSON request
let result = api::parse(arg).and_then(|request| match request {
Request::Post { msg, handle } => add_post(msg, handle),
Request::Post { message, handle } => add_post(message, handle),
Request::Fetch { handle } => fetch_posts(handle),
});

View File

@@ -8,17 +8,22 @@ mkdir -p wasm
echo "Building..."
cargo +nightly build --target wasm32-unknown-unknown --release >/dev/null
cp target/wasm32-unknown-unknown/release/*.wasm ./wasm/
echo
# Run it all on 30000 port with default Fluence API
echo "Running..."
docker rm -f frun &>/dev/null || true
echo 'docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest'
docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest >/dev/null
echo
# Wait for app to be initialized
sleep 1 && (docker logs -f frun 2>&1 &) | grep -q initialized && sleep 1
# Send our username to the application
echo -e "Sending request...\n"
echo -e "Sending request..."
echo "curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'$USER --compressed"
echo
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$USER" --compressed | jq -r .result.data | base64 -D)

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -e
mkdir -p wasm
# Build fluid WASM module
echo "Building..."
cargo +nightly build --target wasm32-unknown-unknown --release >/dev/null
cp target/wasm32-unknown-unknown/release/*.wasm ./wasm/
echo
# Run it all on 30000 port with default Fluence API
echo "Running..."
docker rm -f frun &>/dev/null || true
echo 'docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest'
docker run -d --name frun --rm -v "$(pwd)/wasm:/code" -p 30000:30000 fluencelabs/frun:latest >/dev/null
echo
# Wait for app to be initialized
sleep 1 && (docker logs -f frun 2>&1 &) | grep -q initialized && sleep 1
# Send our username to the application
echo -e "Sending request..."
# Assign json to a variable using heredoc technique
JSON=$(cat <<JSON
{"action":"Post","message":"I'm nice, you're nice, it's nice!","handle":"Random Joe"}
JSON
)
# Send json as a request, and receive result
RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D)
# Parse result as JSON and print to console
echo -e "$RESPONSE" | jq .
# Remove frun container
echo -e "Stopping..."
docker rm -f frun >/dev/null

View File

@@ -7,7 +7,7 @@ pub type AppResult<T> = ::std::result::Result<T, Box<Error>>;
#[derive(Deserialize)]
#[serde(tag = "action")]
pub enum Request {
Post { msg: String, handle: String },
Post { message: String, handle: String },
Fetch { handle: Option<String> },
}

View File

@@ -20,7 +20,7 @@ fn init() {
fn run(arg: String) -> String {
// Parse and handle JSON request
let result = api::parse(arg).and_then(|request| match request {
Request::Post { msg, handle } => add_post(msg, handle),
Request::Post { message, handle } => add_post(message, handle),
Request::Fetch { handle } => fetch_posts(handle),
});

View File

@@ -1,8 +1,4 @@
use std::str::FromStr;
use crate::api::AppResult;
use crate::database;
use crate::errors::err_msg;
use log;
pub fn create_scheme() -> AppResult<()> {

View File

@@ -7,7 +7,7 @@ pub type AppResult<T> = ::std::result::Result<T, Box<Error>>;
#[derive(Deserialize)]
#[serde(tag = "action")]
pub enum Request {
Post { msg: String, handle: String },
Post { message: String, handle: String },
Fetch { handle: Option<String> },
}

View File

@@ -22,7 +22,7 @@ fn init() {
fn run(arg: String) -> String {
// Parse and handle JSON request
let result = api::parse(arg).and_then(|request| match request {
Request::Post { msg, handle } => add_post(msg, handle),
Request::Post { message, handle } => add_post(message, handle),
Request::Fetch { handle } => fetch_posts(handle),
});