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

Select optimize #3

Merged
merged 5 commits into from
Jul 4, 2022
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cardano-utxo-wasm"
version = "0.1.2"
version = "0.1.3"
authors = ["Siegfried <zhiqiang.lei@gmail.com>"]
edition = "2021"
homepage = "https://github.com/siegfried/cardano-utxo-wasm"
Expand All @@ -18,4 +18,4 @@ crate-type = ["cdylib"]
wasm-bindgen = "~0.2.81"
wasm-bindgen-test = "~0.3.31"
js-sys = "~0.3.58"
utxo = "~0.2.2"
utxo = "~0.3.0"
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ build: clean

publish: pkg
npm publish pkg/

test:
wasm-pack test --headless --chrome --firefox

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

This package wraps UTxO helpers from Rust crates such as [utxo](https://github.com/siegfried/utxo) into WASM so that they can be used by Nodejs and the browsers.

## Example
## UTxO Selection Example

In real use case, `policyId` and `assetName` are usually hex string fetched from query API such as GraphQL. `select` is expected to be used before you feed inputs to transaction builder.

```typescript
import type { Output } from 'cardano-utxo-wasm'
import init, { select } from 'cardano-utxo-wasm'

// The output required to spend.
const output: Output = {
lovelace: BigInt('10000'),
assets: [
Expand All @@ -18,6 +21,7 @@ const output: Output = {
]
}

// A UTxO should not be selected because there are 2 assets not needed.
const input0: Output = {
id: { hash: "tx0", index: 0 },
lovelace: BigInt('100000'),
Expand All @@ -28,6 +32,7 @@ const input0: Output = {
]
}

// A UTxO should be selected because there are 2 assets needed.
const input1: Output = {
id: { hash: "tx1", index: 1 },
lovelace: BigInt('1000'),
Expand All @@ -37,6 +42,7 @@ const input1: Output = {
]
}

// A UTxO should be selected because the lovelace was not enough in `input1`.
const input2: Output = {
id: { hash: "tx2", index: 2 },
lovelace: BigInt('10000'),
Expand Down
Loading