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

feat: initialize clarinet-sdk with the core js lib #1068

Merged
merged 13 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"components/clarinet-deployments",
"components/clarinet-files",
"components/clarinet-utils",
"components/clarinet-sdk",
"components/clarity-jupyter-kernel",
"components/clarity-lsp",
"components/clarity-repl",
Expand Down
1 change: 1 addition & 0 deletions components/clarinet-deployments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Into<StacksEpochId> for EpochSpec {
}
}

#[derive(Debug, Clone)]
pub struct DeploymentGenerationArtifacts {
pub asts: BTreeMap<QualifiedContractIdentifier, ContractAST>,
pub deps: BTreeMap<QualifiedContractIdentifier, DependencySet>,
Expand Down
8 changes: 4 additions & 4 deletions components/clarinet-files/src/wasm_fs_accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ struct WFSWriteRequest<'a> {
}

pub struct WASMFileSystemAccessor {
client_request_tx: JsFunction,
client_request: JsFunction,
}

impl WASMFileSystemAccessor {
pub fn new(client_request_tx: JsFunction) -> WASMFileSystemAccessor {
WASMFileSystemAccessor { client_request_tx }
pub fn new(client_request: JsFunction) -> WASMFileSystemAccessor {
WASMFileSystemAccessor { client_request }
}

fn get_request_promise<T: Serialize>(
&self,
action: String,
data: &T,
) -> FileAccessorResult<JsValue> {
let request_promise = self.client_request_tx.call2(
let request_promise = self.client_request.call2(
&JsValue::NULL,
&JsValue::from(action),
&encode_to_js(data).unwrap(),
Expand Down
3 changes: 3 additions & 0 deletions components/clarinet-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
src-ts/sdk
node_modules/
76 changes: 76 additions & 0 deletions components/clarinet-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[package]
edition = "2021"
name = "clarinet-sdk"
version = "0.0.1"

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

[dependencies]
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0"
clarinet-files = { path = "../clarinet-files", default-features = false }
clarity-repl = { path = "../clarity-repl", default-features = false, optional = true }
clarinet-deployments = { path = "../clarinet-deployments", default-features = false }
# WASM
console_error_panic_hook = { version = "0.1", optional = true }
js-sys = { version = "0.3", optional = true }
serde-wasm-bindgen = { version = "0.5", optional = true }
wasm-bindgen = { version = "0.2", optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
web-sys = { version = "0.3", features = ["console"], optional = true }

[features]
default = ["wasm"]
wasm = [
"wasm-bindgen",
"wasm-bindgen-futures",
"serde-wasm-bindgen",
"js-sys",
"web-sys",
"console_error_panic_hook",
"clarinet-deployments/wasm",
"clarity-repl/wasm",
"clarinet-files/wasm",
]

# DEV
[profile.dev]
inherits = "release"
opt-level = 3
debug = false
debug-assertions = false
incremental = false
codegen-units = 256

[profile.dev.build-override]
inherits = "release"
opt-level = 3

[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

[package.metadata.wasm-pack.profile.dev.wasm-bindgen]
debug-js-glue = false
demangle-name-section = true
dwarf-debug-info = false

# RELEASE
[profile.release]
opt-level = 3
debug = false
debug-assertions = false
lto = true
incremental = false
codegen-units = 16

[package.metadata.wasm-pack.profile.release]
wasm-opt = false
# wasm-opt = ['-O1']

[package.metadata.wasm-pack.profile.release.wasm-bindgen]
debug-js-glue = false
demangle-name-section = true
dwarf-debug-info = false
43 changes: 43 additions & 0 deletions components/clarinet-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Clarinet SDK

## Core

### Usage

```ts
import { Cl } from "@stacks/transactions";
import { initVM } from "obscurity-sdk";

async function main() {
const vm = await initVM();
const accounts = vm.getAccounts();
const w1 = accounts.get("wallet_1");
if (!w1) return;

const call = vm.callPublicFn("counter", "increment", [Cl.uint(1)], w1);
console.log(call.result); // Cl.int(Cl.ok(true))

const counter = vm.getDataVar("counter", "counter");
console.log(counter); // Cl.int(2)
}

main();
```

## Contributing

Clone the clarinet repo adn switch to the sdk component
```
git clone git@github.com:hirosystems/clarinet.git
cd clarinet/components/clarinet-sdk
```

Open the SDK workspace in VSCode:
```
code ./clarinet-sdk.code-workspace
```

Compile the project (both WASM and JS):
```
npm run build
```
17 changes: 17 additions & 0 deletions components/clarinet-sdk/clarinet-sdk.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"folders": [{ "path": "../../" }],
"settings": {
// "rust-analyzer.checkOnSave.command": "clippy -p clarinet-sdk -- --no-deps",
// "rust-analyzer.check.command": "check",
"rust-analyzer.check.overrideCommand": [
"cargo",
"clippy",
"--no-default-features",
"--package=clarinet-sdk",
"--features=wasm",
"--message-format=json",
"--",
"--no-deps"
]
}
}
Loading
Loading