Skip to content

Commit

Permalink
Update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
gRoussac committed Mar 8, 2024
1 parent 14dd7a1 commit 610d315
Show file tree
Hide file tree
Showing 28 changed files with 6,270 additions and 3,257 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci-rust-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ jobs:
- name: Lint
run: make check-lint

- name: Doc
run: make doc

- name: Github pages 🚀
uses: JamesIves/github-pages-deploy-action@ba1486788b0490a235422264426c45848eac35c6 #v4.4.1
with:
folder: docs # The folder the action should deploy.

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@5b949b50c3461bbcd5a540b150c368278160234a #v3.4.0
with:
Expand All @@ -83,14 +75,22 @@ jobs:
- name: E2E Tests
run: make e2e-test

- name: Build lib for Wasm with no features
- name: Build lib for all targets
uses: actions-rs/cargo@v1
with:
command: build
args: --lib --target wasm32-unknown-unknown --no-default-features
args: --lib --all-targets

- name: Install Wasm Pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Pack
run: make pack
- name: Build packages and apps
run: make build

- name: Doc
run: make doc

- name: Github pages 🚀
uses: JamesIves/github-pages-deploy-action@ba1486788b0490a235422264426c45848eac35c6 #v4.4.1
with:
folder: docs # The folder the action should deploy.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ doc:
cp -r target/doc/* docs/api-rust/
npx typedoc --name api-wasm --out docs/api-wasm pkg/casper_rust_wasm_sdk.d.ts

build: pack doc
build: pack
cd examples/frontend/angular/ && npm ci && npm run build && cd .
cd examples/frontend/react/ && npm ci && npm run build && cd .
cd examples/desktop/node/ && npm ci && npx tsc index.ts && cd .
Expand Down
156 changes: 154 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,147 @@ const signed_deploy = unsigned_deploy.sign(private_key);

</details>

<details>
<summary>Wait Deploy</summary>

#### Rust

Developers using Rust can utilize the wait_deploy function to wait for a specific deploy event. This is achieved by providing the desired event URL, deploy hash, and an optional timeout duration. Once the deploy is processed, the resulting data, such as the deploy's cost, can be easily accessed and utilized in subsequent logic.

```rust
pub const DEFAULT_EVENT_ADDRESS: &str = "http://127.0.0.1:18101/events/main";

let deploy_hash = "c94ff7a9f86592681e69c1d8c2d7d2fed89fd1a922faa0ae74481f8458af2ee4";

let timeout_duration = None; // Some(30000) for 30s instead of default timeout duration of 60s

// Wait for deploy
let event_parse_result = sdk
.wait_deploy(DEFAULT_EVENT_ADDRESS, &deploy_hash, timeout_duration)
.await
.unwrap();
let deploy_processed = event_parse_result.body.unwrap().deploy_processed.unwrap();
println!("{:?}", deploy_processed);
```

#### Typescript

In TypeScript, the waitDeploy function provides a similar capability to wait for a specific deploy event. Developers can leverage this function by specifying the event address, deploy hash, and an optional timeout duration. The received EventParseResult object can then be processed to extract valuable information, such as the cost of the deploy.

```ts
const events_address = 'http://127.0.0.1:18101/events/main';

const deploy_hash =
'c94ff7a9f86592681e69c1d8c2d7d2fed89fd1a922faa0ae74481f8458af2ee4';

const timeout_duration = undefined; // 30000 for 30s instead of default timeout duration of 60s

// Wait for deploy
const eventParseResult: EventParseResult = await sdk.waitDeploy(
events_address,
install_result_as_json.deploy_hash,
timeout_duration
);
console.log(eventParseResult.body.DeployProcessed);
const cost =
eventParseResult.body?.DeployProcessed?.execution_result.Success?.cost;
console.log(`deploy cost ${cost}`);
```

</details>

<details>
<summary>Watch Deploy</summary>

#### Rust

The watch_deploy functionality facilitates actively monitoring deploy events. By creating a deploy watcher, developers can subscribe to specific deploy hashes and define custom callback functions to handle these events. The watcher is then started, and as deploy events occur, the specified callback functions are executed. This mechanism enables real-time responsiveness to deploy events within Rust applications.

```rust
use casper_rust_wasm_sdk::deploy_watcher::watcher::{
DeploySubscription, EventHandlerFn,
};

pub const DEFAULT_EVENT_ADDRESS: &str = "http://127.0.0.1:18101/events/main";

let deploy_hash = "c94ff7a9f86592681e69c1d8c2d7d2fed89fd1a922faa0ae74481f8458af2ee4";

let timeout_duration = None; // Some(30000) for 30s instead of default timeout duration of 60s

// Creates a watcher instance
let mut watcher = sdk.watch_deploy(DEFAULT_EVENT_ADDRESS, timeout_duration);

// Create a callback function handler of your design
let event_handler_fn = get_event_handler_fn(deploy_hash.to_string());

let mut deploy_subscriptions: Vec<DeploySubscription> = vec![];
deploy_subscriptions.push(DeploySubscription::new(
deploy_hash.to_string(),
EventHandlerFn::new(event_handler_fn),
));

// Subscribe and start watching
let _ = watcher.subscribe(deploy_subscriptions);
let results = watcher.start().await;
watcher.stop();
println!("{:?}", results);
```

#### Typescript

Similarly, TypeScript developers can utilize the watchDeploy function to actively watch for deploy events on the Casper blockchain. By creating a deploy watcher and defining callback functions, developers can subscribe to specific deploy hashes and respond dynamically as events unfold.

```ts
import { EventParseResult, DeploySubscription } from 'casper-sdk';

const events_address = 'http://127.0.0.1:18101/events/main';

const deploy_hash =
'c94ff7a9f86592681e69c1d8c2d7d2fed89fd1a922faa0ae74481f8458af2ee4';

// Creates a watcher instance
const watcher = sdk.watchDeploy(events_address);

// Create a callback function handler of your design
const getEventHandlerFn = (deployHash: string) => {
const eventHandlerFn = (eventParseResult: EventParseResult) => {
console.log(`callback for ${deployHash}`);
if (eventParseResult.err) {
return false;
} else if (
eventParseResult.body?.DeployProcessed?.execution_result.Success
) {
console.log(
eventParseResult.body?.DeployProcessed?.execution_result.Success
);
return true;
} else {
console.error(
eventParseResult.body?.DeployProcessed?.execution_result.Failure
);
return false;
}
};
return eventHandlerFn;
};

const eventHandlerFn = getEventHandlerFn(deploy_hash);

const deploySubscription: DeploySubscription = new DeploySubscription(
deploy_hash,
eventHandlerFn
);
const deploySubscriptions: DeploySubscription[] = [deploySubscription];

// Subscribe and start watching
watcher.subscribe(deploySubscriptions);
const results = await watcher.start();
watcher.stop();
console.log(results);
```

</details>

</details>

<details>
Expand Down Expand Up @@ -1242,6 +1383,12 @@ You can download an alpha version of the app illustrating the SDK here:

- [Deploy Type and static builder](https://casper-ecosystem.github.io/rustSDK/api-rust/casper_rust_wasm_sdk/types/deploy/struct.Deploy.html)

### Deploy Watcher

- [Deploy Watcher](https://casper-ecosystem.github.io/rustSDK/api-rust/casper_rust_wasm_sdk/deploy_watcher/index.html)
- [DeploySubscription](https://casper-ecosystem.github.io/rustSDK/api-rust/casper_rust_wasm_sdk/deploy_watcher/struct.DeploySubscription.html)
- [EventParseResult](https://casper-ecosystem.github.io/rustSDK/api-rust/casper_rust_wasm_sdk/deploy_watcher/struct.EventParseResult.html)

### Types

- [Current exposed types](https://casper-ecosystem.github.io/rustSDK/api-rust/casper_rust_wasm_sdk/types/index.html)
Expand Down Expand Up @@ -1269,6 +1416,12 @@ You can download an alpha version of the app illustrating the SDK here:

- [Deploy Type and static builder](https://casper-ecosystem.github.io/rustSDK/api-wasm/classes/Deploy.html)

### Deploy Watcher

- [Deploy Watcher](https://casper-ecosystem.github.io/rustSDK/api-wasm/classes/DeployWatcher.html)
- [DeploySubscription](https://casper-ecosystem.github.io/rustSDK/api-wasm/classes/DeploySubscription.html)
- [EventParseResult](https://casper-ecosystem.github.io/rustSDK/api-wasm/classes/EventParseResult.html)

### Types

- [Current exposed types](https://casper-ecosystem.github.io/rustSDK/api-wasm/modules.html)
Expand All @@ -1279,7 +1432,7 @@ You can download an alpha version of the app illustrating the SDK here:

## Testing

Tests are run against NCTL by default or the network configured in corresponding configurations. Tests assume a `secret_key.pem` is either at the root of tests or in `../NCTL/casper-node/utils/nctl/assets/net-1/users/user-1/` from the root (one level higher than the root). This path can be changed in configuration.
Tests are run against NCTL by default. Alternately, you may configure another network in corresponding configurations. Testes assume a `secret_key.pem` will be located in the root `tests` directory, or one level higher at `../NCTL/casper-node/utils/nctl/assets/net-1/users/user-1/`. This path can be changed in the configuration.
(Rust tests must be run with `--test-threads=1`)

- [Rust Integration tests](tests/integration/rust/) can be run with
Expand Down Expand Up @@ -1317,5 +1470,4 @@ make test

- Expose more CL Types and Casper Client result Types
- EventStream
- Keygen
- Wallet connect
Loading

0 comments on commit 610d315

Please sign in to comment.