-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from proximax-storage/sdk/initial
[SC: 30] Basic Rust SDK
- Loading branch information
Showing
16 changed files
with
727 additions
and
0 deletions.
There are no files selected for viewing
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,4 @@ | ||
/target | ||
**/*.rs.bk | ||
.idea | ||
*.iml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
name = "xpx_supercontracts_sdk" | ||
version = "0.1.0" | ||
authors = ["ProxymaX Core Development Team"] | ||
description = "ProximaX Supercontracts Rust SDK" | ||
edition = "2018" | ||
homepage = "https://www.proximax.io/" | ||
documentation = "https://docs.rs/xpx-supercontracts-sdk" | ||
readme = "README.md" | ||
keywords = ["distributed", "blockchain", "sdk", "supercontract", "xpx", "proximax"] | ||
categories = ["cryptography", "sdk"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/proximax-storage/rust-xpx-supercontracts-sdk" | ||
|
||
|
||
[dependencies] | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
failure = "0.1.5" | ||
|
||
[[example]] | ||
name = "ping" | ||
crate-type = ["cdylib"] | ||
|
||
[[example]] | ||
name = "debug" | ||
crate-type = ["cdylib"] | ||
|
||
[[example]] | ||
name = "http" | ||
crate-type = ["cdylib"] | ||
|
||
[[example]] | ||
name = "storage" | ||
crate-type = ["cdylib"] |
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,44 @@ | ||
# ProximaX Supercontracts Rust SDK | ||
|
||
Official ProximaX Supercontracts SDK Library in Rust lang. | ||
|
||
## Getting Started | ||
All Supercontracts stuff include in dependency: | ||
```toml | ||
[dependencies] | ||
xpx_supercontracts_sdk = "0.1" | ||
``` | ||
|
||
To start new development new Supercontrac follow this steps: | ||
1. `cargo new sc-app` | ||
|
||
2. Add to `Cargo.toml`: | ||
```toml | ||
[dependencies] | ||
xpx_supercontracts_sdk = "0.1" | ||
``` | ||
|
||
3. Add to `src/main.rs`: | ||
```rust | ||
extern xpx_supercontracts_sdk; | ||
use xpx_supercontracts_sdk::utils::ping; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn app_main() -> i64 { | ||
ping(100).unwrap() | ||
} | ||
``` | ||
|
||
4. Build: `cargo build --target wasm32-unknown-unknown --release` | ||
5. If build success result contains in: `target` | ||
5. Convert to Wat/Wast format: `wasm2wat sc-app` | ||
|
||
## SDK Documentation | ||
See `Docs` directory. | ||
|
||
## Exampels | ||
* See `eamples` directory | ||
* Build specific exmaple: `cargo build --target wasm32-unknown-unknown --example ping` | ||
|
||
### License: Apache 2.0 | ||
Copyright (c) 2019 ProximaX Limited |
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,44 @@ | ||
# Rust SDK Documentation | ||
|
||
## Functions | ||
### utils::ping | ||
* description: Send ping message to `WasmVM`. Successful | ||
result should be incremented value. Useful for most | ||
simple request/response message tests for `WasmVM`. | ||
* params: `msg: usize` | ||
* return: `Result<i64>` | ||
|
||
#### Example | ||
```rust | ||
use xpx_supercontracts_sdk::utils::ping; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn app_main() -> i64 { | ||
ping(100).unwrap() | ||
} | ||
|
||
``` | ||
|
||
### utils::debug_message | ||
* description: Send debug message to `WasmVM`. It's | ||
convenient basic function for development debugging. | ||
Message that was sent will display in `WasmVM` stdout | ||
as information log message. It not affect basic | ||
Supercontract execution but should be removed | ||
from `release` version, because it will spend `Gas` | ||
(unit ticks). | ||
* params: `msg: &String` | ||
* return: `()` | ||
|
||
#### Example | ||
```rust | ||
use xpx_supercontracts_sdk::statuses::STATUS_SUCCESS; | ||
use xpx_supercontracts_sdk::utils::debug_message; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn app_main() -> i64 { | ||
let msg = "Debug message".to_string(); | ||
debug_message(msg); | ||
STATUS_SUCCESS | ||
} | ||
``` |
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,13 @@ | ||
# ProximaX Supercontracts Rust SDK examples | ||
|
||
That directory provide basic examples for **How-To** work with SDK. | ||
|
||
### Examples list | ||
* `ping`git c | ||
* `http` | ||
* `debug` | ||
|
||
## How to use | ||
Run command `cargo build --target wasm32-unknown-unknown --example <example-name>` | ||
|
||
Ex: `cargo build --target wasm32-unknown-unknown --example ping` |
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,10 @@ | ||
// Example for `debug_message` WasmVM function. | ||
use xpx_supercontracts_sdk::statuses::STATUS_SUCCESS; | ||
use xpx_supercontracts_sdk::utils::debug_message; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn app_main() -> i64 { | ||
let msg = "Debug message".to_string(); | ||
debug_message(msg); | ||
STATUS_SUCCESS | ||
} |
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,20 @@ | ||
// Example for `http_get` WasmVM function. | ||
use std::collections::HashMap; | ||
use xpx_supercontracts_sdk::http::{http_get, HttpRequest}; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn app_main() -> i64 { | ||
let mut headers: HashMap<String, String> = HashMap::new(); | ||
headers.insert("content-type".to_string(), "text/html".to_string()); | ||
let req = HttpRequest { | ||
url: "http://google.com/".to_string(), | ||
headers: headers, | ||
}; | ||
let resp = http_get(&req); | ||
if let Err(err) = resp { | ||
// Return error status | ||
return err as i64; | ||
} | ||
// Return response body length | ||
resp.unwrap().len() as i64 | ||
} |
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,7 @@ | ||
// Example for `ping` WasmVM function. | ||
use xpx_supercontracts_sdk::utils::ping; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn app_main() -> i64 { | ||
ping(100).unwrap() | ||
} |
Oops, something went wrong.