Skip to content

Commit e6491bb

Browse files
authored
Merge pull request xch-dev#562 from xch-dev/use-sdk-fix
Use Wallet SDK fix
2 parents cd52c58 + f59be1f commit e6491bb

File tree

27 files changed

+956
-652
lines changed

27 files changed

+956
-652
lines changed

Cargo.lock

Lines changed: 152 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ chia-traits = "0.26.0"
9090
chia-sha2 = "0.26.0"
9191
chia-puzzles = "0.20.1"
9292
clvmr = "0.14.0"
93-
chia-wallet-sdk = { version = "0.27.2", features = ["rustls", "offer-compression", "peer-simulator"] }
93+
chia-wallet-sdk = { git = "https://github.com/xch-dev/chia-wallet-sdk", rev = "c022b3d262ca13038958ccf3211925f87c3c1a83", features = ["rustls", "offer-compression", "peer-simulator"] }
9494
bip39 = "2.0.0"
9595
bech32 = "0.9.1"
9696
rand = "0.8.5"
@@ -103,7 +103,7 @@ tokio = "1.39.2"
103103
futures-util = "0.3.30"
104104
futures-lite = "2.3.0"
105105
sqlx = "0.8.0"
106-
reqwest = { version = "0.12.7", default-features = false }
106+
reqwest = { version = "0.12.22", default-features = false }
107107

108108
# Utilities
109109
indexmap = "2.3.0"

crates/sage-api/src/requests/actions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ pub struct RedownloadNftResponse {}
7171
pub struct IncreaseDerivationIndex {
7272
#[serde(default)]
7373
pub hardened: Option<bool>,
74+
#[serde(default)]
75+
pub unhardened: Option<bool>,
7476
pub index: u32,
7577
}
7678

crates/sage-database/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
mod maintenance;
2+
mod serialized_primitives;
23
mod tables;
34
mod utils;
45

56
pub use maintenance::*;
7+
pub use serialized_primitives::*;
68
pub use tables::*;
79

810
pub(crate) use utils::*;
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
use chia::{
2+
clvm_traits::{FromClvm, ToClvm},
3+
protocol::{Bytes32, Program},
4+
};
5+
use chia_wallet_sdk::{
6+
driver::{Did, DidInfo, DriverError, HashedPtr, Nft, NftInfo, Singleton},
7+
prelude::Allocator,
8+
};
9+
10+
pub type SerializedNft = Singleton<SerializedNftInfo>;
11+
pub type SerializedDid = Singleton<SerializedDidInfo>;
12+
13+
#[derive(Debug, Clone, PartialEq, Eq)]
14+
pub struct SerializedNftInfo {
15+
pub launcher_id: Bytes32,
16+
pub metadata: Program,
17+
pub metadata_updater_puzzle_hash: Bytes32,
18+
pub current_owner: Option<Bytes32>,
19+
pub royalty_puzzle_hash: Bytes32,
20+
pub royalty_basis_points: u16,
21+
pub p2_puzzle_hash: Bytes32,
22+
}
23+
24+
#[derive(Debug, Clone, PartialEq, Eq)]
25+
pub struct SerializedDidInfo {
26+
pub launcher_id: Bytes32,
27+
pub recovery_list_hash: Option<Bytes32>,
28+
pub num_verifications_required: u64,
29+
pub metadata: Program,
30+
pub p2_puzzle_hash: Bytes32,
31+
}
32+
33+
pub trait DeserializePrimitive {
34+
type Primitive;
35+
36+
fn deserialize(self, allocator: &mut Allocator) -> Result<Self::Primitive, DriverError>;
37+
}
38+
39+
impl DeserializePrimitive for SerializedNft {
40+
type Primitive = Nft;
41+
42+
fn deserialize(self, allocator: &mut Allocator) -> Result<Self::Primitive, DriverError> {
43+
Ok(Nft::new(
44+
self.coin,
45+
self.proof,
46+
self.info.deserialize(allocator)?,
47+
))
48+
}
49+
}
50+
51+
impl DeserializePrimitive for SerializedNftInfo {
52+
type Primitive = NftInfo;
53+
54+
fn deserialize(self, allocator: &mut Allocator) -> Result<Self::Primitive, DriverError> {
55+
let ptr = self.metadata.to_clvm(allocator)?;
56+
57+
Ok(NftInfo::new(
58+
self.launcher_id,
59+
HashedPtr::from_ptr(allocator, ptr),
60+
self.metadata_updater_puzzle_hash,
61+
self.current_owner,
62+
self.royalty_puzzle_hash,
63+
self.royalty_basis_points,
64+
self.p2_puzzle_hash,
65+
))
66+
}
67+
}
68+
69+
impl DeserializePrimitive for SerializedDid {
70+
type Primitive = Did;
71+
72+
fn deserialize(self, allocator: &mut Allocator) -> Result<Self::Primitive, DriverError> {
73+
Ok(Did::new(
74+
self.coin,
75+
self.proof,
76+
self.info.deserialize(allocator)?,
77+
))
78+
}
79+
}
80+
81+
impl DeserializePrimitive for SerializedDidInfo {
82+
type Primitive = DidInfo;
83+
84+
fn deserialize(self, allocator: &mut Allocator) -> Result<Self::Primitive, DriverError> {
85+
let ptr = self.metadata.to_clvm(allocator)?;
86+
87+
Ok(DidInfo::new(
88+
self.launcher_id,
89+
self.recovery_list_hash,
90+
self.num_verifications_required,
91+
HashedPtr::from_ptr(allocator, ptr),
92+
self.p2_puzzle_hash,
93+
))
94+
}
95+
}
96+
97+
pub trait SerializePrimitive: Sized {
98+
type Primitive;
99+
100+
fn serialize(&self, allocator: &Allocator) -> Result<Self::Primitive, DriverError>;
101+
}
102+
103+
impl SerializePrimitive for Nft {
104+
type Primitive = SerializedNft;
105+
106+
fn serialize(&self, allocator: &Allocator) -> Result<Self::Primitive, DriverError> {
107+
Ok(SerializedNft {
108+
coin: self.coin,
109+
proof: self.proof,
110+
info: self.info.serialize(allocator)?,
111+
})
112+
}
113+
}
114+
115+
impl SerializePrimitive for NftInfo {
116+
type Primitive = SerializedNftInfo;
117+
118+
fn serialize(&self, allocator: &Allocator) -> Result<Self::Primitive, DriverError> {
119+
Ok(SerializedNftInfo {
120+
launcher_id: self.launcher_id,
121+
metadata: Program::from_clvm(allocator, self.metadata.ptr())?,
122+
metadata_updater_puzzle_hash: self.metadata_updater_puzzle_hash,
123+
current_owner: self.current_owner,
124+
royalty_puzzle_hash: self.royalty_puzzle_hash,
125+
royalty_basis_points: self.royalty_basis_points,
126+
p2_puzzle_hash: self.p2_puzzle_hash,
127+
})
128+
}
129+
}
130+
131+
impl SerializePrimitive for Did {
132+
type Primitive = SerializedDid;
133+
134+
fn serialize(&self, allocator: &Allocator) -> Result<Self::Primitive, DriverError> {
135+
Ok(SerializedDid {
136+
coin: self.coin,
137+
proof: self.proof,
138+
info: self.info.serialize(allocator)?,
139+
})
140+
}
141+
}
142+
143+
impl SerializePrimitive for DidInfo {
144+
type Primitive = SerializedDidInfo;
145+
146+
fn serialize(&self, allocator: &Allocator) -> Result<Self::Primitive, DriverError> {
147+
Ok(SerializedDidInfo {
148+
launcher_id: self.launcher_id,
149+
recovery_list_hash: self.recovery_list_hash,
150+
num_verifications_required: self.num_verifications_required,
151+
metadata: Program::from_clvm(allocator, self.metadata.ptr())?,
152+
p2_puzzle_hash: self.p2_puzzle_hash,
153+
})
154+
}
155+
}

0 commit comments

Comments
 (0)