Skip to content

Commit

Permalink
Optimize the select logic underlying (#3)
Browse files Browse the repository at this point in the history
* Update utxo dep

* Add test task to Makefile

* Use typed setters for Javascript objects

* Version 0.1.3

* Update README.md
  • Loading branch information
siegfried committed Jul 4, 2022
1 parent 1c0d047 commit 33e3b8c
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 70 deletions.
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

0 comments on commit 33e3b8c

Please sign in to comment.