Skip to content

Commit beec6f8

Browse files
committed
Merge remote-tracking branch 'upstream/new-database' into migrate-schema
2 parents 4f3dd78 + fc7338e commit beec6f8

19 files changed

Lines changed: 337 additions & 375 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
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 = { git = "https://github.com/xch-dev/chia-wallet-sdk", rev = "1202fe93b62a60fba4009071ae60b960b27e72e6", features = ["rustls", "offer-compression", "peer-simulator"] }
93+
chia-wallet-sdk = { git = "https://github.com/xch-dev/chia-wallet-sdk", rev = "c9a35dacaf5387483c99208591d8831692bcc1ab", features = ["rustls", "offer-compression", "peer-simulator"] }
9494
bip39 = "2.0.0"
9595
bech32 = "0.9.1"
9696
rand = "0.8.5"

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ pub struct TakeOffer {
4747
pub fee: Amount,
4848
#[serde(default)]
4949
pub auto_submit: bool,
50-
#[serde(default = "yes")]
51-
pub auto_import: bool,
5250
}
5351

5452
#[derive(Debug, Clone, Serialize, Deserialize)]

crates/sage-database/src/tables/assets.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ pub struct NftMetadataInfo {
118118
pub collection_id: Option<Bytes32>,
119119
}
120120

121+
#[derive(Debug, Clone)]
122+
pub struct RequestedNft {
123+
pub metadata: Program,
124+
pub metadata_updater_puzzle_hash: Bytes32,
125+
pub royalty_puzzle_hash: Bytes32,
126+
pub royalty_basis_points: u16,
127+
}
128+
121129
impl Database {
122130
pub async fn asset_kind(&self, asset_id: Bytes32) -> Result<Option<AssetKind>> {
123131
asset_kind(&self.pool, asset_id).await
@@ -180,6 +188,10 @@ impl Database {
180188
pub async fn did_assets(&self) -> Result<Vec<DidAsset>> {
181189
did_assets(&self.pool).await
182190
}
191+
192+
pub async fn requested_nft(&self, launcher_id: Bytes32) -> Result<Option<RequestedNft>> {
193+
requested_nft(&self.pool, launcher_id).await
194+
}
183195
}
184196

185197
impl DatabaseTx<'_> {
@@ -928,3 +940,32 @@ async fn did_assets(conn: impl SqliteExecutor<'_>) -> Result<Vec<DidAsset>> {
928940
})
929941
.collect()
930942
}
943+
944+
async fn requested_nft(
945+
conn: impl SqliteExecutor<'_>,
946+
launcher_id: Bytes32,
947+
) -> Result<Option<RequestedNft>> {
948+
let launcher_id = launcher_id.as_ref();
949+
950+
query!(
951+
"
952+
SELECT
953+
metadata, metadata_updater_puzzle_hash, royalty_puzzle_hash, royalty_basis_points
954+
FROM nfts
955+
INNER JOIN assets ON assets.id = nfts.asset_id
956+
WHERE hash = ?
957+
",
958+
launcher_id
959+
)
960+
.fetch_optional(conn)
961+
.await?
962+
.map(|row| {
963+
Ok(RequestedNft {
964+
metadata: Program::from(row.metadata),
965+
metadata_updater_puzzle_hash: row.metadata_updater_puzzle_hash.convert()?,
966+
royalty_puzzle_hash: row.royalty_puzzle_hash.convert()?,
967+
royalty_basis_points: row.royalty_basis_points.convert()?,
968+
})
969+
})
970+
.transpose()
971+
}

crates/sage-database/src/tables/coins.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ impl DatabaseTx<'_> {
206206
is_known_coin(&mut *self.tx, coin_id).await
207207
}
208208

209-
pub async fn is_latest_singleton_coin(&mut self, hash: Bytes32) -> Result<bool> {
210-
is_latest_singleton_coin(&mut *self.tx, hash).await
211-
}
212-
213209
pub async fn sync_coin(
214210
&mut self,
215211
coin_id: Bytes32,
@@ -347,22 +343,6 @@ async fn delete_coin(conn: impl SqliteExecutor<'_>, coin_id: Bytes32) -> Result<
347343
Ok(())
348344
}
349345

350-
async fn is_latest_singleton_coin(conn: impl SqliteExecutor<'_>, hash: Bytes32) -> Result<bool> {
351-
let hash_ref = hash.as_ref();
352-
353-
let rows = query!(
354-
"SELECT amount FROM internal_coins WHERE parent_coin_hash = ?",
355-
hash_ref
356-
)
357-
.fetch_all(conn)
358-
.await?
359-
.into_iter()
360-
.map(|row| row.amount.convert())
361-
.collect::<Result<Vec<u64>>>()?;
362-
363-
Ok(rows.into_iter().all(|amount| amount % 2 == 0))
364-
}
365-
366346
async fn sync_coin(
367347
conn: impl SqliteExecutor<'_>,
368348
coin_id: Bytes32,

0 commit comments

Comments
 (0)