rm old service dirs

This commit is contained in:
boneyard93501 2022-07-11 13:35:18 -05:00
parent fb69c0cce6
commit d393905549
19 changed files with 0 additions and 684 deletions

View File

@ -1,73 +0,0 @@
data FunctionAddress:
peer_id: string
service_id: string
data Provider:
name: string
url: string
data EVMResult:
stdout: string
stderr: string
service MyOp("op"):
-- identity(x:string) -> string
array_length(providers: []Provider) -> i64
-- array_length(nodes: []string) -> i64
service MultiProviderQuery("service-id"):
get_block_number(provider: Provider) -> EVMResult
func get_service_id_no_try(node: string, services: []FunctionAddress) -> string:
res: *string
for service <- services:
if service.peer_id == node:
res <<- service.service_id
<- res[0]
--func custom_result(out_string: string, err_string: string) -> EVMResult:
-- r: *EVMResult
-- r.stdout <- out_string
-- r.stderr <- err_string
-- <- r
--func custom_num(number: i64) -> i64:
-- num: *i64
-- num <<- number
-- <- num[0]
func get_service_id_try(node: string, services: []FunctionAddress) -> string:
res: *string
for service <- services try:
if service.peer_id == node:
res <<- service.service_id
<- res[0]
func get_service_id_par(node: string, services: []FunctionAddress) -> string:
res: *string
for service <- services par:
if service.peer_id == node:
res <<- service.service_id
<- res[0]
-- func get_block_number(providers: []Provider, nodes: []string, services: []FunctionAddress) -> []string:
func get_block_number(providers: []Provider, nodes: []string, services: []FunctionAddress) -> []EVMResult:
-- result: *string
result: *EVMResult
for node <- nodes par:
for provider <- providers par:
on node:
service_id <- get_service_id_no_try(node, services)
MultiProviderQuery service_id
try:
-- res <- get_block_number(provider.url)
-- result <<- (provider.name, node, res)
result <- MultiProviderQuery.get_block_number(provider)
-- catch e:
-- result <- custom_result(e)
<- result

View File

@ -1,25 +0,0 @@
data FunctionAddress:
peer_id: string
service_id: string
func get_service_id_no_try(node: string, services: []FunctionAddress) -> string:
res: *string
for service <- services:
if service.peer_id == node:
res <<- service.service_id
<- res[0]
func get_service_id_try(node: string, services: []FunctionAddress) -> string:
res: *string
for service <- services try:
if service.peer_id == node:
res <<- service.service_id
<- res[0]
func get_service_id_par(node: string, services: []FunctionAddress) -> string:
res: *string
for service <- services par:
if service.peer_id == node:
res <<- service.service_id
<- res[0]

View File

@ -1,31 +0,0 @@
{
"arg1": [
{
"name": "infura",
"url": "https://mainnet.infura.io/v3/<Your API KEY>"
},
{
"name": "alchemy",
"url": "https://eth-mainnet.alchemyapi.io/v2/<Your API KEY>"
},
{ "name": "link", "url": "https://main-light.eth.linkpool.io" }
],
"arg2": [
{
"peer_id": "12D3KooWJ4bTHirdTFNZpCS72TAzwtdmavTBkkEXtzo6wHL25CtE",
"service_id": "d9124884-3c42-43d6-9a1f-1b645d073c3f"
},
{
"peer_id": "12D3KooWAKNos2KogexTXhrkMZzFYpLHuWJ4PgoAhurSAv7o5CWA",
"service_id": "3c321110-b069-42c6-b5e0-aed73d976a60"
},
{
"peer_id": "12D3KooWMMGdfVEJ1rWe1nH1nehYDzNEHhg5ogdfiGk88AupCMnf",
"service_id": "84d4d018-0c13-4d6d-8c11-599a3919911c"
}
],
"arg3": {
"peer_id": "12D3KooWAKNos2KogexTXhrkMZzFYpLHuWJ4PgoAhurSAv7o5CWA",
"service_id": "366e3fdd-0d8d-4f8f-bae6-e2e541a17550"
}
}

View File

@ -1,12 +0,0 @@
{
"multi-provider-query": {
"modules": [
{
"name": "simple-quorum",
"path": "./artifacts/simple_quorum.wasm",
"max_heap_size": "128 MiB",
"logger_enabled": [true]
}
]
}
}

View File

@ -1,14 +0,0 @@
[package]
name = "curl_adapter"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"
publish = false
[[bin]]
path = "src/main.rs"
name = "curl_adapter"
[dependencies]
marine-rs-sdk = "0.6.14"
log = "0.4.8"

View File

@ -1,37 +0,0 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed 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.
*/
#![allow(improper_ctypes)]
use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest;
use marine_rs_sdk::MountedBinaryResult;
module_manifest!();
pub fn main() {}
#[marine]
pub fn curl_request(cmd: Vec<String>) -> MountedBinaryResult {
curl(cmd)
}
#[marine]
#[link(wasm_import_module = "host")]
extern "C" {
fn curl(cmd: Vec<String>) -> MountedBinaryResult;
}

View File

@ -1,24 +0,0 @@
[package]
name = "multi_provider_query"
version = "0.1.5"
authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"]
edition = "2018"
description = "multi-provider-query, a Marine wasi module"
license = "Apache-2.0"
[[bin]]
name = "multi_provider_query"
path = "src/main.rs"
[dependencies]
marine-rs-sdk = { version = "0.6.15", features = ["logger"] }
log = "0.4.14"
serde_json = "1.0.81"
serde = "1.0.137"
[dev-dependencies]
marine-rs-sdk-test = "0.6.0"
[dev]
[profile.release]
opt-level = "s"

View File

@ -1,159 +0,0 @@
/*
* Copyright 2022 Fluence Labs Limited
*
* Licensed 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.
*/
use marine_rs_sdk::{marine, module_manifest, MountedBinaryResult};
use serde::{Deserialize, Serialize};
use serde_json;
use std::sync::atomic::{AtomicUsize, Ordering};
pub static NONCE_COUNTER: AtomicUsize = AtomicUsize::new(1);
module_manifest!();
fn main() {}
fn get_nonce() -> u64 {
NONCE_COUNTER.fetch_add(1, Ordering::SeqCst) as u64
}
#[marine]
pub struct ProviderInfo {
pub url: String,
pub name: String,
}
#[marine]
pub struct EVMResult {
pub provider: String,
pub stdout: String,
pub stderr: String,
}
#[derive(Serialize, Deserialize)]
struct RpcData {
jsonrpc: String,
method: String,
params: Vec<String>,
id: u64,
}
#[derive(Serialize, Deserialize, Debug)]
struct RpcResponseError {
code: i32,
message: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct RpcResponse {
jsonrpc: String,
error: Option<RpcResponseError>,
result: Option<String>,
}
impl RpcData {
fn new(method: String, params: Vec<String>) -> Self {
let nonce = get_nonce();
RpcData {
jsonrpc: "2.0".to_owned(),
method: method,
params: params,
id: nonce,
}
}
}
fn curl_cmd_builder(url: String, data: String) -> Vec<String> {
let curl_cmd: Vec<String> = vec![
url,
"-X".to_string(),
"POST".to_string(),
"-H".to_string(),
"Accept: application/json".to_string(),
"-H".to_string(),
"Content-Type: application/json".to_string(),
"-d".to_string(),
data,
];
curl_cmd
}
fn get_curl_response(curl_cmd: Vec<String>) -> RpcResponse {
let response = curl_request(curl_cmd);
let response = String::from_utf8(response.stdout).unwrap();
let response: Result<RpcResponse, _> = serde_json::from_str(&response);
match response {
Ok(r) => r,
Err(e) => RpcResponse {
jsonrpc: "".to_owned(),
error: Some(RpcResponseError {
code: -1,
message: e.to_string(),
}),
result: None,
},
}
}
#[marine]
// see https://eth.wiki/json-rpc/API#eth_blocknumbers
fn get_block_number(provider: ProviderInfo) -> EVMResult {
let method = "eth_blockNumber";
let params: Vec<String> = vec![];
let url = provider.url;
let data = RpcData::new(method.to_owned(), params);
let data = serde_json::to_string(&data).unwrap();
let curl_cmd = curl_cmd_builder(url, data);
let response = get_curl_response(curl_cmd);
if response.error.is_none() {
let raw_response = response.result.unwrap();
let block_height = u64::from_str_radix(raw_response.trim_start_matches("0x"), 16);
let result = match block_height {
Ok(r) => {
let j_res = serde_json::json!({ "block-height": r });
EVMResult {
provider: provider.name,
stdout: j_res.to_string(),
stderr: "".to_owned(),
}
}
Err(e) => {
let err = format!("unable to convert {} to u64 with error {}", raw_response, e);
EVMResult {
provider: provider.name,
stdout: "".to_owned(),
stderr: err,
}
}
};
return result;
}
EVMResult {
provider: provider.name,
stdout: "".to_owned(),
stderr: serde_json::to_string(&response.error).unwrap(),
}
}
#[marine]
#[link(wasm_import_module = "curl_adapter")]
extern "C" {
pub fn curl_request(cmd: Vec<String>) -> MountedBinaryResult;
}

View File

@ -1,25 +0,0 @@
[package]
name = "simple-quorum"
version = "0.1.0"
authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"]
edition = "2018"
description = "simple-quorum, a Marine wasi module"
license = "Apache-2.0"
[[bin]]
name = "simple_quorum"
path = "src/main.rs"
[dependencies]
marine-rs-sdk = { version = "0.6.15", features = ["logger"] }
log = "0.4.14"
serde_json = "1.0.81"
serde = "1.0.137"
streaming-stats = "0.2.3"
[dev-dependencies]
marine-rs-sdk-test = "0.6.0"
[dev]
[profile.release]
opt-level = "s"

View File

@ -1,117 +0,0 @@
/*
* Copyright 2022 Fluence Labs Limited
*
* Licensed 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.
*/
use marine_rs_sdk::{marine, module_manifest};
use std::collections::HashMap;
module_manifest!();
fn main() {}
// very simple mode calculator with much room for improvement
// see https://github.com/BurntSushi/rust-stats for inspiration
fn mode<'a>(data: impl ExactSizeIterator<Item = &'a EVMResult>) -> (u32, u64) {
let frequencies = data
.into_iter()
.fold(HashMap::<u64, u32>::new(), |mut freqs, value| {
*freqs
.entry(
match serde_json::from_str::<serde_json::Value>(&value.stdout) {
Ok(r) => r["block-height"].as_u64().unwrap(),
Err(_e) => 0 as u64,
},
)
.or_insert(0) += 1;
freqs
});
let mode = frequencies
.iter()
.max_by_key(|&(_, count)| count)
.map(|(value, _)| value)
.unwrap();
(*frequencies.get(&mode).unwrap(), *mode)
}
fn mean<'a>(data: impl ExactSizeIterator<Item = &'a u64>) -> Option<f64> {
let n = data.len() as u64;
if n < 1 {
return None;
}
let res = (data.sum::<u64>() / n) as f64;
Some(res)
}
#[marine]
pub struct EVMResult {
pub provider: String,
pub stdout: String,
pub stderr: String,
}
#[marine]
#[derive(Default, Debug)]
pub struct Quorum {
pub n: u32,
pub mode: u64,
pub freq: u32,
pub err_str: String,
}
#[marine]
pub fn point_estimate(data: Vec<EVMResult>, min_points: u32) -> Quorum {
if data.len() < min_points as usize {
return Quorum {
err_str: format!(
"Expected at least {} points but only got {}.",
min_points,
data.len()
),
..<_>::default()
};
}
if data.len() < 1 {
return Quorum {
err_str: format!("Expected at least one timestamp."),
..<_>::default()
};
}
let (freq, mode) = mode(data.iter());
Quorum {
n: data.len() as u32,
mode,
freq,
..<_>::default()
}
}
#[marine]
pub fn int_div(nom: u64, denom: u64) -> f64 {
nom as f64 / denom as f64
}
#[marine]
pub fn is_quorum(nom: u64, denom: u64, threshold: f64) -> bool {
let div = nom as f64 / denom as f64;
if div >= threshold {
return true;
}
false
}

View File

@ -1,24 +0,0 @@
[package]
name = "multi_provider_query"
version = "0.1.5"
authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"]
edition = "2018"
description = "multi-provider-query, a Marine wasi module"
license = "Apache-2.0"
[[bin]]
name = "multi_provider_query"
path = "src/main.rs"
[dependencies]
marine-rs-sdk = { version = "0.6.15", features = ["logger"] }
log = "0.4.14"
serde_json = "1.0.81"
serde = "1.0.137"
[dev-dependencies]
marine-rs-sdk-test = "0.6.0"
[dev]
[profile.release]
opt-level = "s"

View File

@ -1,40 +0,0 @@
/*
* Copyright 2022 Fluence Labs Limited
*
* Licensed 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.
*/
use marine_rs_sdk::{marine, module_manifest, MountedBinaryResult};
module_manifest!();
fn main() {}
#[marine]
pub struct ProviderInfo {
pub url: String,
}
#[marine]
pub struct EVMResult {
pub stdout: String,
pub stderr: String,
}
#[marine]
fn count_providers(providers: Vec<ProviderInfo>) -> u64 {
providers.len() as u64
}
#[marine]
fn provider_results(results: Vec<EVMResult>) {}

View File

@ -1,5 +0,0 @@
debug/
target/
Cargo.lock
**/*.bk
**/*.bak

View File

@ -1,22 +0,0 @@
[package]
name = "utilities"
version = "0.1.5"
authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"]
edition = "2018"
description = "utilities, a Marine wasi module"
license = "Apache-2.0"
[[bin]]
name = "utilities"
path = "src/main.rs"
[dependencies]
marine-rs-sdk = { version = "0.6.15", features = ["logger"] }
log = "0.4.14"
[dev-dependencies]
marine-rs-sdk-test = "0.6.0"
[dev]
[profile.release]
opt-level = "s"

View File

@ -1,6 +0,0 @@
modules_dir = "artifacts/"
[[module]]
name = "utilities"
max_heap_size = "10 KiB"
logger_enabled = true

View File

@ -1,18 +0,0 @@
# Marine Starter Template
Get started quickly with your Wasm project with this template.
To use this template you should have the following components available:
* Rust [installation instructions](https://www.rust-lang.org/tools/install)
* Cargo Generate [installation instructions](https://github.com/cargo-generate/cargo-generate#installation)
* Marine [installation instructions](https://github.com/cargo-generate/cargo-generate#installation)
Use the template with `cargo generate`:
```bash
cargo generate cargo generate --git https://github.com/boneyard93501/fluence-template.git
```
Which will prompt you for the project name and then generate the project, which will be your directory name. `cd` into your new directory and run `./scripts/build.sh` to compile the supplied __greeting__ function to a Wasm file ready for deployment.
Check out the [Fluence documentation](https://doc.fluence.dev/docs/) for more details on Marine and Aqua.

View File

@ -1,11 +0,0 @@
{
"utilities": {
"name": "utilities",
"modules": [
{
"name": "utilities",
"path": "./artifacts/utilities.wasm"
}
]
}
}

View File

@ -1,7 +0,0 @@
#!/usr/bin/env bash -o errexit -o nounset -o pipefail
cargo update --aggressive
mkdir -p artifacts
rm -f artifacts/*.wasm
marine build --release
cp target/wasm32-wasi/release/utilities.wasm artifacts/

View File

@ -1,34 +0,0 @@
/*
* Copyright 2022 Fluence Labs Limited
*
* Licensed 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.
*/
use marine_rs_sdk::{marine, module_manifest, WasmLoggerBuilder};
module_manifest!();
pub fn main() {
WasmLoggerBuilder::new().build().unwrap();
}
#[marine]
pub struct CustomResult {
stdout: String,
stderr: String,
provider_name: String,
error: bool,
}
#[marine]
pub fn to_struct(name: String, stdout: String, stderr: String) -> String {}