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

Update wallet sdk #355

Merged
merged 4 commits into from
Mar 8, 2025
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
546 changes: 300 additions & 246 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ specta-typescript = "0.0.7"
tauri-specta = "2.0.0-rc.20"

# Chia
chia = "0.17.0"
clvmr = "0.10.0"
chia-wallet-sdk = { features = ["rustls", "offers"], version = "0.20.0" }
chia = "0.20.0"
chia-puzzles = "0.20.1"
clvmr = "0.12.0"
chia-wallet-sdk = { version = "0.22.1", features = ["rustls", "offers", "peer-simulator"] }
bip39 = "2.0.0"
bech32 = "0.9.1"

Expand Down
1 change: 0 additions & 1 deletion crates/sage-assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ workspace = true

[dependencies]
chia = { workspace = true }
clvmr = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
num-bigint = { workspace = true, features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-assets/src/nfts/fetch_nft_uri.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chia::protocol::Bytes32;
use clvmr::sha2::Sha256;
use chia::sha2::Sha256;
use futures_lite::StreamExt;
use futures_util::stream::FuturesUnordered;
use mime_sniffer::MimeTypeSniffer;
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-config/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chia_wallet_sdk::{MAINNET_CONSTANTS, TESTNET11_CONSTANTS};
use chia_wallet_sdk::types::{MAINNET_CONSTANTS, TESTNET11_CONSTANTS};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use specta::Type;
Expand Down
4 changes: 2 additions & 2 deletions crates/sage-database/src/coin_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ async fn get_block_heights_by_item_id(
let id_bytes = if let Some(value) = &id {
// First try to decode as a bech32m address (NFT ID, DID ID, etc.)
if value.starts_with("nft") || value.starts_with("did:chia:") {
match chia_wallet_sdk::decode_address(value) {
Ok((launcher_id, _prefix)) => Some(launcher_id.to_vec()),
match chia_wallet_sdk::utils::Address::decode(value) {
Ok(address) => Some(address.puzzle_hash.to_vec()),
Err(_) => return Ok((Vec::new(), 0)), // Invalid bech32m address
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-database/src/primitives/cats.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chia::{protocol::Bytes32, puzzles::LineageProof};
use chia_wallet_sdk::Cat;
use chia_wallet_sdk::driver::Cat;
use sqlx::SqliteExecutor;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-database/src/primitives/dids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chia::{
protocol::{Bytes32, Program},
puzzles::LineageProof,
};
use chia_wallet_sdk::{Did, DidInfo};
use chia_wallet_sdk::driver::{Did, DidInfo};
use sqlx::SqliteExecutor;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-database/src/primitives/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use chia::{
puzzles::LineageProof,
sha2::Sha256,
};
use chia_wallet_sdk::{Nft, NftInfo};
use chia_wallet_sdk::driver::{Nft, NftInfo};
use sqlx::SqliteExecutor;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-database/src/rows/cat_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chia::{
protocol::{Bytes32, Coin},
puzzles::LineageProof,
};
use chia_wallet_sdk::Cat;
use chia_wallet_sdk::driver::Cat;

use crate::{to_bytes32, to_u64, DatabaseError};

Expand Down
2 changes: 1 addition & 1 deletion crates/sage-database/src/rows/did_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chia::{
protocol::{Bytes32, Coin, Program},
puzzles::{LineageProof, Proof},
};
use chia_wallet_sdk::{Did, DidInfo};
use chia_wallet_sdk::driver::{Did, DidInfo};

use crate::{to_bytes32, to_u64, DatabaseError};

Expand Down
2 changes: 1 addition & 1 deletion crates/sage-database/src/rows/nft_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chia::{
protocol::{Coin, Program},
puzzles::{LineageProof, Proof},
};
use chia_wallet_sdk::{Nft, NftInfo};
use chia_wallet_sdk::driver::{Nft, NftInfo};

use crate::{to_bytes32, to_u64, DatabaseError};

Expand Down
1 change: 1 addition & 0 deletions crates/sage-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ workspace = true
[dependencies]
chia = { workspace = true }
clvmr = { workspace = true }
chia-puzzles = { workspace = true }
chia-wallet-sdk = { workspace = true }
sage-database = { workspace = true }
sage-assets = { workspace = true }
Expand Down
9 changes: 6 additions & 3 deletions crates/sage-wallet/src/child_kind.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use chia::{
clvm_traits::{FromClvm, ToClvm},
protocol::{Bytes32, Coin, Program},
puzzles::{nft::NftMetadata, singleton::SINGLETON_LAUNCHER_PUZZLE_HASH, LineageProof, Proof},
puzzles::{nft::NftMetadata, LineageProof, Proof},
};
use chia_puzzles::SINGLETON_LAUNCHER_HASH;
use chia_wallet_sdk::{
run_puzzle, Cat, Condition, Did, DidInfo, HashedPtr, Memos, Nft, NftInfo, Puzzle,
driver::{Cat, Did, DidInfo, HashedPtr, Nft, NftInfo, Puzzle},
prelude::Memos,
types::{run_puzzle, Condition},
};
use clvmr::{Allocator, NodePtr};
use tracing::{debug_span, warn};
Expand Down Expand Up @@ -75,7 +78,7 @@ impl ChildKind {
);
let _span = parse_span.enter();

if coin.puzzle_hash == SINGLETON_LAUNCHER_PUZZLE_HASH.into() {
if coin.puzzle_hash == SINGLETON_LAUNCHER_HASH.into() {
return Ok(Self::Launcher);
}

Expand Down
7 changes: 4 additions & 3 deletions crates/sage-wallet/src/coin_kind.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use chia::{
clvm_traits::{FromClvm, ToClvm},
protocol::{Bytes32, Program},
puzzles::{nft::NftMetadata, singleton::SINGLETON_LAUNCHER_PUZZLE_HASH},
puzzles::nft::NftMetadata,
};
use chia_wallet_sdk::{CatLayer, DidInfo, HashedPtr, Layer, NftInfo, Puzzle};
use chia_puzzles::SINGLETON_LAUNCHER_HASH;
use chia_wallet_sdk::driver::{CatLayer, DidInfo, HashedPtr, Layer, NftInfo, Puzzle};
use clvmr::Allocator;
use tracing::{debug_span, warn};

Expand Down Expand Up @@ -41,7 +42,7 @@ impl CoinKind {
let parse_span = debug_span!("parse puzzle");
let _span = parse_span.enter();

if puzzle.curried_puzzle_hash() == SINGLETON_LAUNCHER_PUZZLE_HASH {
if puzzle.curried_puzzle_hash() == SINGLETON_LAUNCHER_HASH.into() {
return Ok(Self::Launcher);
}

Expand Down
7 changes: 6 additions & 1 deletion crates/sage-wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use chia::{
clvm_traits::{FromClvmError, ToClvmError},
protocol::Bytes32,
};
use chia_wallet_sdk::{ClientError, CoinSelectionError, DriverError, OfferError, SignerError};
use chia_wallet_sdk::{
client::ClientError,
driver::{DriverError, OfferError},
signer::SignerError,
utils::CoinSelectionError,
};
use clvmr::reduction::EvalErr;
use sage_database::DatabaseError;
use thiserror::Error;
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-wallet/src/queues/offer_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use chia::protocol::Bytes32;
use chia_wallet_sdk::Offer;
use chia_wallet_sdk::driver::Offer;
use clvmr::Allocator;
use sage_database::{Database, OfferStatus};
use tokio::{
Expand Down
5 changes: 4 additions & 1 deletion crates/sage-wallet/src/sync_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use chia::{
protocol::{Bytes32, CoinStateUpdate, Message, NewPeakWallet, ProtocolMessageTypes},
traits::Streamable,
};
use chia_wallet_sdk::{ClientError, Connector, Network, MAINNET_CONSTANTS, TESTNET11_CONSTANTS};
use chia_wallet_sdk::{
client::{ClientError, Connector, Network},
types::{MAINNET_CONSTANTS, TESTNET11_CONSTANTS},
};
use futures_lite::future::poll_once;
use itertools::Itertools;
use tokio::{
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-wallet/src/sync_manager/peer_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chia::{
protocol::{Message, NewPeakWallet, ProtocolMessageTypes},
traits::Streamable,
};
use chia_wallet_sdk::{connect_peer, Peer, PeerOptions};
use chia_wallet_sdk::client::{connect_peer, Peer, PeerOptions};
use futures_lite::StreamExt;
use futures_util::stream::FuturesUnordered;
use tokio::{sync::mpsc, time::timeout};
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-wallet/src/sync_manager/sync_command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{net::IpAddr, sync::Arc};

use chia::protocol::{Bytes32, Message};
use chia_wallet_sdk::Network;
use chia_wallet_sdk::client::Network;

use crate::Wallet;

Expand Down
7 changes: 5 additions & 2 deletions crates/sage-wallet/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use chia::{
puzzles::{standard::StandardArgs, DeriveSynthetic},
};
use chia_wallet_sdk::{
test_secret_key, AggSigConstants, Connector, Network, Peer, PeerSimulator, TESTNET11_CONSTANTS,
client::{Connector, Network, Peer},
signer::AggSigConstants,
test::{BlsPair, PeerSimulator},
types::TESTNET11_CONSTANTS,
};
use sage_database::Database;
use sqlx::{migrate, SqlitePool};
Expand Down Expand Up @@ -71,7 +74,7 @@ impl TestWallet {
let db = Database::new(pool);
db.run_rust_migrations().await?;

let sk = test_secret_key()?.derive_unhardened(key_index);
let sk = BlsPair::default().sk.derive_unhardened(key_index);
let pk = sk.public_key();
let fingerprint = pk.get_fingerprint();
let intermediate_pk = master_to_wallet_unhardened_intermediate(&pk);
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-wallet/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chia::{
clvm_traits::{FromClvm, ToClvm},
protocol::{Coin, CoinSpend, Program},
};
use chia_wallet_sdk::{run_puzzle, Condition, Conditions};
use chia_wallet_sdk::types::{run_puzzle, Condition, Conditions};
use clvmr::{Allocator, NodePtr};

use crate::{ChildKind, CoinKind, WalletError};
Expand Down
5 changes: 4 additions & 1 deletion crates/sage-wallet/src/utils/fetch_nft_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use chia::{
singleton::SingletonSolution,
},
};
use chia_wallet_sdk::{run_puzzle, Condition, Conditions, DidInfo, HashedPtr, NftInfo, Puzzle};
use chia_wallet_sdk::{
driver::{DidInfo, HashedPtr, NftInfo, Puzzle},
types::{run_puzzle, Condition, Conditions},
};
use clvmr::{Allocator, NodePtr};
use tokio::time::{sleep, timeout};

Expand Down
2 changes: 1 addition & 1 deletion crates/sage-wallet/src/utils/fetch_nft_offer_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chia::{
clvm_traits::{FromClvm, ToClvm},
protocol::{Bytes32, Program},
};
use chia_wallet_sdk::{HashedPtr, Nft, Puzzle};
use chia_wallet_sdk::driver::{HashedPtr, Nft, Puzzle};
use clvmr::Allocator;
use tokio::time::{sleep, timeout};

Expand Down
5 changes: 4 additions & 1 deletion crates/sage-wallet/src/wallet/cat_coin_management.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use chia::protocol::CoinSpend;
use chia_wallet_sdk::{Cat, Conditions, SpendContext};
use chia_wallet_sdk::{
driver::{Cat, SpendContext},
types::Conditions,
};

use crate::WalletError;

Expand Down
3 changes: 2 additions & 1 deletion crates/sage-wallet/src/wallet/cat_spends.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chia_wallet_sdk::{
Cat, CatSpend, Conditions, SpendContext, SpendWithConditions, StandardLayer,
driver::{Cat, CatSpend, SpendContext, SpendWithConditions, StandardLayer},
types::Conditions,
};

use crate::WalletError;
Expand Down
5 changes: 4 additions & 1 deletion crates/sage-wallet/src/wallet/cats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use chia::{
bls::PublicKey,
protocol::{Bytes, Bytes32, CoinSpend},
};
use chia_wallet_sdk::{Cat, Conditions, SpendContext};
use chia_wallet_sdk::{
driver::{Cat, SpendContext},
types::Conditions,
};

use crate::WalletError;

Expand Down
2 changes: 1 addition & 1 deletion crates/sage-wallet/src/wallet/coin_selection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use chia::protocol::{Bytes32, Coin};
use chia_wallet_sdk::{select_coins, Cat};
use chia_wallet_sdk::{driver::Cat, utils::select_coins};

use crate::WalletError;

Expand Down
9 changes: 6 additions & 3 deletions crates/sage-wallet/src/wallet/did_assign.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use chia::protocol::{Bytes32, CoinSpend};
use chia_wallet_sdk::{Conditions, DidOwner, HashedPtr, SpendContext, StandardLayer};
use chia_wallet_sdk::{
driver::{DidOwner, HashedPtr, SpendContext, StandardLayer},
types::Conditions,
};

use crate::WalletError;

Expand Down Expand Up @@ -57,7 +60,7 @@ impl Wallet {

let did = if let Some(did) = did {
let did_metadata_ptr = ctx.alloc(&did.info.metadata)?;
Some(did.with_metadata(HashedPtr::from_ptr(&ctx.allocator, did_metadata_ptr)))
Some(did.with_metadata(HashedPtr::from_ptr(&ctx, did_metadata_ptr)))
} else {
None
};
Expand All @@ -71,7 +74,7 @@ impl Wallet {

for (i, nft) in nfts.into_iter().enumerate() {
let nft_metadata_ptr = ctx.alloc(&nft.info.metadata)?;
let nft = nft.with_metadata(HashedPtr::from_ptr(&ctx.allocator, nft_metadata_ptr));
let nft = nft.with_metadata(HashedPtr::from_ptr(&ctx, nft_metadata_ptr));

let synthetic_key = self.db.synthetic_key(nft.info.p2_puzzle_hash).await?;
let p2 = StandardLayer::new(synthetic_key);
Expand Down
9 changes: 6 additions & 3 deletions crates/sage-wallet/src/wallet/dids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use chia::{
protocol::{Bytes32, Coin, CoinSpend},
puzzles::{singleton::SingletonArgs, Proof},
};
use chia_wallet_sdk::{Conditions, Did, HashedPtr, Launcher, SpendContext, StandardLayer};
use chia_wallet_sdk::{
driver::{Did, HashedPtr, Launcher, SpendContext, StandardLayer},
types::Conditions,
};

use crate::WalletError;

Expand Down Expand Up @@ -90,7 +93,7 @@ impl Wallet {

for (i, did) in dids.into_iter().enumerate() {
let did_metadata_ptr = ctx.alloc(&did.info.metadata)?;
let did = did.with_metadata(HashedPtr::from_ptr(&ctx.allocator, did_metadata_ptr));
let did = did.with_metadata(HashedPtr::from_ptr(&ctx, did_metadata_ptr));

let synthetic_key = self.db.synthetic_key(did.info.p2_puzzle_hash).await?;
let p2 = StandardLayer::new(synthetic_key);
Expand Down Expand Up @@ -168,7 +171,7 @@ impl Wallet {

for (i, did) in dids.into_iter().enumerate() {
let did_metadata_ptr = ctx.alloc(&did.info.metadata)?;
let did = did.with_metadata(HashedPtr::from_ptr(&ctx.allocator, did_metadata_ptr));
let did = did.with_metadata(HashedPtr::from_ptr(&ctx, did_metadata_ptr));

let synthetic_key = self.db.synthetic_key(did.info.p2_puzzle_hash).await?;
let p2 = StandardLayer::new(synthetic_key);
Expand Down
Loading