Skip to content

Commit

Permalink
CLI: charms wallet cast, charms wallet list
Browse files Browse the repository at this point in the history
Also,
- Unify calculation of app inputs
- Use funding UTXO to fund both the commit and spell transactions
- Use "string of charms" as a term for sets of charms (tokens, NFTs, apps) bundled together
- Use secret input in the example app contract
  • Loading branch information
imikushin committed Jan 16, 2025
1 parent 576c971 commit c78e776
Show file tree
Hide file tree
Showing 23 changed files with 644 additions and 415 deletions.
75 changes: 1 addition & 74 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ charms-spell-checker = { path = "charms-spell-checker", version = "0.2.0-dev" }
ciborium = { workspace = true }
clap = { version = "4.5.26", features = ["derive"] }
hex = { workspace = true }
postcard = { workspace = true, features = ["use-std"] }
rand = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
sp1-sdk = { workspace = true }
tokio = { version = "1.43", features = ["full"] }
tracing = { version = "0.1" }
tracing-forest = { version = "0.1.0" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[dev-dependencies]
Expand All @@ -54,7 +54,6 @@ bitcoin = { version = "0.32.5" }
ciborium = { version = "0.2.2" }
ciborium-io = { version = "0.2.2" }
hex = { version = "0.4.3" }
postcard = { version = "1.1.1" }
proptest = { version = "1.6.0" }
proptest-derive = { version = "0.5.1" }
rand = { version = "0.8.5" }
Expand Down
1 change: 0 additions & 1 deletion charms-data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ hex = { workspace = true }
serde = { workspace = true, features = ["derive"] }

[dev-dependencies]
postcard = { workspace = true, features = ["use-std"] }
proptest = { workspace = true }
proptest-derive = { workspace = true }
test-strategy = { workspace = true }
26 changes: 13 additions & 13 deletions charms-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ pub fn nft_state_preserved(app: &App, tx: &Transaction) -> bool {

pub fn app_state_multiset<'a>(
app: &App,
strands: impl Iterator<Item = &'a Charms>,
strings_of_charms: impl Iterator<Item = &'a Charms>,
) -> BTreeMap<&'a Data, usize> {
strands
.filter_map(|strand| strand.get(app))
strings_of_charms
.filter_map(|charms| charms.get(app))
.fold(BTreeMap::new(), |mut r, s| {
match r.get_mut(&s) {
Some(count) => *count += 1,
Expand All @@ -466,9 +466,9 @@ pub fn app_state_multiset<'a>(

pub fn sum_token_amount<'a>(
self_app: &App,
strands: impl Iterator<Item = &'a Charms>,
strings_of_charms: impl Iterator<Item = &'a Charms>,
) -> Result<u64> {
strands.fold(Ok(0u64), |amount, strand| match strand.get(self_app) {
strings_of_charms.fold(Ok(0u64), |amount, charms| match charms.get(self_app) {
Some(state) => Ok(amount? + state.value::<u64>()?),
None => amount,
})
Expand All @@ -495,32 +495,32 @@ mod tests {

#[proptest]
fn vk_serde_roundtrip(vk: B32) {
let bytes = postcard::to_stdvec(&vk).unwrap();
let deserialize_result = postcard::from_bytes::<B32>(&bytes);
let bytes = util::write(&vk).unwrap();
let deserialize_result = util::read::<B32>(&bytes);
let vk2 = deserialize_result.unwrap();
prop_assert_eq!(vk, vk2);
}

#[proptest]
fn app_serde_roundtrip(app: App) {
let bytes = postcard::to_stdvec(&app).unwrap();
let deserialize_result = postcard::from_bytes::<App>(&bytes);
let bytes = util::write(&app).unwrap();
let deserialize_result = util::read::<App>(&bytes);
let app2 = deserialize_result.unwrap();
prop_assert_eq!(app, app2);
}

#[proptest]
fn utxo_id_serde_roundtrip(utxo_id: UtxoId) {
let bytes = postcard::to_stdvec(&utxo_id).unwrap();
let deserialize_result = postcard::from_bytes::<UtxoId>(&bytes);
let bytes = util::write(&utxo_id).unwrap();
let deserialize_result = util::read::<UtxoId>(&bytes);
let utxo_id2 = deserialize_result.unwrap();
prop_assert_eq!(utxo_id, utxo_id2);
}

#[proptest]
fn tx_id_serde_roundtrip(tx_id: TxId) {
let bytes = postcard::to_stdvec(&tx_id).unwrap();
let deserialize_result = postcard::from_bytes::<TxId>(&bytes);
let bytes = util::write(&tx_id).unwrap();
let deserialize_result = util::read::<TxId>(&bytes);
let tx_id2 = deserialize_result.unwrap();
prop_assert_eq!(tx_id, tx_id2);
}
Expand Down
16 changes: 16 additions & 0 deletions examples/toad-token/spells/mint-nft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 0

apps:
$00: n/${app_id}/${app_vk}

private_inputs:
$00: "${in_utxo_0}"

ins:
- utxo_id: ${in_utxo_0}
charms: {}

outs:
- address: ${addr_0}
charms:
$00: 100000
12 changes: 0 additions & 12 deletions examples/toad-token/spells/mint-nft.yml

This file was deleted.

21 changes: 21 additions & 0 deletions examples/toad-token/spells/mint-token.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0

apps:
$00: n/${app_id}/${app_vk}
$01: t/${app_id}/${app_vk}

private_inputs:
$00: ""

ins:
- utxo_id: ${in_utxo_0}
charms:
$00: 100000

outs:
- address: ${addr_0}
charms:
$01: 69420
- address: ${addr_1}
charms:
$00: 30580
15 changes: 0 additions & 15 deletions examples/toad-token/spells/mint-token.yml

This file was deleted.

27 changes: 27 additions & 0 deletions examples/toad-token/spells/send.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 0

apps:
$00: n/${app_id}/${app_vk}
$01: t/${app_id}/${app_vk}

ins:
- utxo_id: ${in_utxo_0}
charms:
$01: 69420

- utxo_id: ${in_utxo_1}
charms:
$00: 30580

outs:
- address: ${addr_0}
charms:
$00: 30580
$01: 420

- address: ${addr_1}
charms: {}

- address: ${addr_2}
charms:
$01: 69000
23 changes: 0 additions & 23 deletions examples/toad-token/spells/send.yml

This file was deleted.

14 changes: 14 additions & 0 deletions examples/toad-token/spells/send420.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 0

apps:
$00: t/${app_id}/${app_vk}

ins:
- utxo_id: ${in_utxo_0}
charms:
$00: 420

outs:
- address: ${addr_0}
charms:
$00: 420
13 changes: 0 additions & 13 deletions examples/toad-token/spells/send420.yml

This file was deleted.

Loading

0 comments on commit c78e776

Please sign in to comment.