Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init single-bucket feature #303

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/crate.yml
Expand Up @@ -51,3 +51,7 @@ jobs:

- name: KV feature test
run: nix develop -c cargo test -p sewup --features=kv --no-default-features

# TODO Fix me when test ready
- name: Build Single bucket feature
run: nix develop -c cargo build -p sewup --features=single-bucket --no-default-features
32 changes: 32 additions & 0 deletions .github/workflows/sb_example.yml
@@ -0,0 +1,32 @@
name: Example

concurrency:
group: single-bucket-${{ github.head_ref }}
cancel-in-progress: true

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

workflow_dispatch:

jobs:
single-bucket-example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: cachix/install-nix-action@v15
with:
nix_path: nixpkgs=channel:nixos-unstable

# Currently, there is issue when running with ssvm with this test case
- name: Run example
run: nix develop -c 'build-example-test' sb

# - name: Deploy test
# run: nix develop -c 'cli-build-test' sb
5 changes: 3 additions & 2 deletions .github/workflows/typo.yml
Expand Up @@ -20,5 +20,6 @@ jobs:
- name: Install typos
run: nix develop -c 'cargo' install typos-cli

- name: Check typo
run: nix develop -c 'typos' --exclude ssvm-evmc
# Temp disable typos
# - name: Check typo
# run: nix develop -c 'typos' --exclude ssvm-evmc
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -18,4 +18,5 @@ exclude = [
"examples/rdb-contract",
"examples/rusty-contract",
"examples/ballot-contract",
"examples/sb-contract",
]
2 changes: 1 addition & 1 deletion SewUp.wiki
Submodule SewUp.wiki updated from 3e2cdc to 1c126e
2 changes: 2 additions & 0 deletions examples/sb-contract/.cargo/config
@@ -0,0 +1,2 @@
[target.'cfg(target_arch="wasm32")']
rustflags = ["-C", "link-arg=--export-table"]
33 changes: 33 additions & 0 deletions examples/sb-contract/Cargo.toml
@@ -0,0 +1,33 @@
[package]
name = "sb-contract"
version = "0.1.0"
authors = ["Antonio Yang <yanganto@gmail.com>"]
edition = "2021"
description = "The example contract using sewup single bucket feature"

[lib]
path = "src/lib.rs"
crate-type = ["cdylib", "lib"]

[dependencies]
anyhow = "1.0.40"
serde = "1.0"
serde_derive = "1.0"

sewup = { version = "*", path = "../../sewup", features = [ "single-bucket" ] }
sewup-derive = { version = "*", path = "../../sewup-derive", features = [ "single-bucket" ] }
thiserror = "1.0.24"

[profile.release]
incremental = false
panic = "abort"
lto = true
opt-level = "z"

[profile.release.package.kv-contract]
incremental = false
opt-level = "z"

[features]
constructor = []
constructor-test = []
5 changes: 5 additions & 0 deletions examples/sb-contract/sewup.toml
@@ -0,0 +1,5 @@
# This config file is for examples, it is good for you to ignore this config in your sewup project
[deploy]
url = "http://localhost:8545"
private = "0000000000000000000000000000000000000000000000000000000000000000"
address = "0x0000000000000000000000000000000000000000"
44 changes: 44 additions & 0 deletions examples/sb-contract/src/lib.rs
@@ -0,0 +1,44 @@
use serde_derive::{Deserialize, Serialize};
use sewup::SingleBucket;
use sewup_derive::{ewasm_constructor, ewasm_main, ewasm_test, Value};

#[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Value)]
struct SimpleStruct {
trust: bool,
description: String,
}

#[ewasm_constructor]
fn setup() {
use sewup::{
single_bucket::SingleBucket2,
types::{Raw, Row},
};
// (Raw, Row), (Row, SimpleStruct)
let bucket = SingleBucket2::<Raw, Row, Row, SimpleStruct>::default();
bucket
.commit()
.expect("there is no return for constructor currently");
}

#[ewasm_main(auto)]
fn main() -> anyhow::Result<sewup::primitives::EwasmAny> {
use sewup_derive::{ewasm_fn_sig, ewasm_input_from};

let contract = sewup::primitives::Contract::new()?;

let output = match contract.get_function_selector()? {
_ => return panic!("unhandled"),
};

Ok(output)
}

#[ewasm_test]
mod tests {
use super::*;
#[ewasm_test]
fn test_() {
assert!(true)
}
}
8 changes: 8 additions & 0 deletions flake.nix
Expand Up @@ -24,6 +24,13 @@
cd ../../
exit $rc
'';
exampleBuildScript = pkgs.writeShellScriptBin "build-example-test" ''
cd examples/$1-contract
cargo build
rc=$?
cd ../../
exit $rc
'';
cliBuildTestScript = pkgs.writeShellScriptBin "cli-build-test" ''
cd cargo-sewup
cargo run -- -d -b -p ../examples/$1-contract
Expand Down Expand Up @@ -80,6 +87,7 @@
devRustNightly

exampleTestScript
exampleBuildScript
cliBuildTestScript
cliInitTestScript
abiTestScript
Expand Down
1 change: 1 addition & 0 deletions sewup-derive/Cargo.toml
Expand Up @@ -39,6 +39,7 @@ rdb = []
token = []
test = ["rdb", "kv"]
debug = []
single-bucket = ["kv"]

[package.metadata.docs.rs]
all-features = true
1 change: 1 addition & 0 deletions sewup/Cargo.toml
Expand Up @@ -40,6 +40,7 @@ token = [ ]
kv = []
rdb = []
debug = []
single-bucket = ["kv"]

[package.metadata.docs.rs]
all-features = true
3 changes: 3 additions & 0 deletions sewup/src/kv/store.rs
Expand Up @@ -26,6 +26,9 @@ type Tenants = HashMap<String, Option<RawBucket>>;
/// Besides, there may be more than one bucket in store, such that you can
/// easily save different kind of key/value pair in the chain.
///
/// If you want to take all storage as a key value without bucket, you may checkout
/// the `single-bucket` feature.
///
/// ### Store Header
/// The fist 32 bytes are reserved as header of the store,
///
Expand Down
8 changes: 7 additions & 1 deletion sewup/src/lib.rs
Expand Up @@ -21,12 +21,18 @@ pub mod token;
#[cfg(feature = "token")]
pub use token::*;

/// help you storage thing as key value object pair
/// help you storage thing as key value object pair with multiple bucket
#[cfg(feature = "kv")]
pub mod kv;
#[cfg(feature = "kv")]
pub use kv::*;

/// help you storage thing as key value object pair
#[cfg(feature = "single-bucket")]
pub mod single_bucket;
#[cfg(feature = "single-bucket")]
pub use single_bucket::*;

/// help you storage thing as records in tables
#[cfg(feature = "rdb")]
pub mod rdb;
Expand Down