Skip to content

Commit

Permalink
Merge pull request #290 from xch-dev/prep-update
Browse files Browse the repository at this point in the history
Add NFT refresh and prep update
  • Loading branch information
Rigidity authored Jan 21, 2025
2 parents e7d762f + ef2744c commit d41a0c4
Show file tree
Hide file tree
Showing 28 changed files with 1,520 additions and 518 deletions.

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

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

18 changes: 9 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/sage-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-api"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "API definitions for the Sage wallet."
Expand Down
8 changes: 8 additions & 0 deletions crates/sage-api/src/requests/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ pub struct UpdateNft {
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type)]
pub struct UpdateNftResponse {}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct RedownloadNft {
pub nft_id: String,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type)]
pub struct RedownloadNftResponse {}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, Type)]
pub struct IncreaseDerivationIndex {
pub hardened: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-assets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-assets"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "Fetches non-critical data from various APIs for use in Sage wallet."
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-cli"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "A CLI and RPC for Sage wallet."
Expand Down
1 change: 1 addition & 0 deletions crates/sage-cli/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ routes!(
update_cat await: UpdateCat = "/update_cat",
update_did await: UpdateDid = "/update_did",
update_nft await: UpdateNft = "/update_nft",
redownload_nft await: RedownloadNft = "/redownload_nft",
increase_derivation_index await: IncreaseDerivationIndex = "/increase_derivation_index",
);

Expand Down
2 changes: 1 addition & 1 deletion crates/sage-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-config"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "Configuration for the Sage wallet."
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-database/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-database"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "The SQLite database for Sage."
Expand Down
26 changes: 26 additions & 0 deletions crates/sage-database/src/primitives/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ impl<'a> DatabaseTx<'a> {
set_nft_uri_checked(&mut *self.tx, uri, hash, hash_matches).await
}

pub async fn set_nft_uri_unchecked(&mut self, uri: String) -> Result<()> {
set_nft_uri_unchecked(&mut *self.tx, uri).await
}

pub async fn delete_nft_data(&mut self, hash: Bytes32) -> Result<()> {
delete_nft_data(&mut *self.tx, hash).await
}

pub async fn insert_nft_data(&mut self, hash: Bytes32, nft_data: NftData) -> Result<()> {
insert_nft_data(&mut *self.tx, hash, nft_data).await
}
Expand Down Expand Up @@ -420,6 +428,14 @@ async fn set_nft_uri_checked(
Ok(())
}

async fn set_nft_uri_unchecked(conn: impl SqliteExecutor<'_>, uri: String) -> Result<()> {
sqlx::query!("UPDATE `nft_uris` SET `checked` = 0 WHERE `uri` = ?", uri)
.execute(conn)
.await?;

Ok(())
}

async fn insert_nft_data(
conn: impl SqliteExecutor<'_>,
hash: Bytes32,
Expand All @@ -442,6 +458,16 @@ async fn insert_nft_data(
Ok(())
}

async fn delete_nft_data(conn: impl SqliteExecutor<'_>, hash: Bytes32) -> Result<()> {
let hash = hash.as_ref();

sqlx::query!("DELETE FROM `nft_data` WHERE `hash` = ?", hash)
.execute(conn)
.await?;

Ok(())
}

async fn distinct_minter_dids(conn: impl SqliteExecutor<'_>) -> Result<Vec<Option<Bytes32>>> {
let rows = sqlx::query!("SELECT DISTINCT minter_did FROM nfts WHERE minter_did IS NOT NULL")
.fetch_all(conn)
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-keychain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-keychain"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "A simple password based keychain implementation for Sage."
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-wallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-wallet"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "The driver code and sync logic for Sage wallet."
Expand Down
2 changes: 1 addition & 1 deletion crates/sage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage"
version = "0.9.1"
version = "0.9.2"
edition = "2021"
license = "Apache-2.0"
description = "A high level abstraction for running Sage wallet."
Expand Down
57 changes: 54 additions & 3 deletions crates/sage/src/endpoints/actions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use chia::{
bls::master_to_wallet_hardened_intermediate,
puzzles::{standard::StandardArgs, DeriveSynthetic},
clvm_traits::{FromClvm, ToClvm},
puzzles::{nft::NftMetadata, standard::StandardArgs, DeriveSynthetic},
};
use clvmr::Allocator;
use sage_api::{
IncreaseDerivationIndex, IncreaseDerivationIndexResponse, RemoveCat, RemoveCatResponse,
UpdateCat, UpdateCatResponse, UpdateDid, UpdateDidResponse, UpdateNft, UpdateNftResponse,
IncreaseDerivationIndex, IncreaseDerivationIndexResponse, RedownloadNft, RedownloadNftResponse,
RemoveCat, RemoveCatResponse, UpdateCat, UpdateCatResponse, UpdateDid, UpdateDidResponse,
UpdateNft, UpdateNftResponse,
};
use sage_database::{CatRow, DidRow};
use sage_wallet::SyncCommand;
Expand Down Expand Up @@ -75,6 +78,54 @@ impl Sage {
Ok(UpdateNftResponse {})
}

pub async fn redownload_nft(&self, req: RedownloadNft) -> Result<RedownloadNftResponse> {
let wallet = self.wallet()?;

let nft_id = parse_nft_id(req.nft_id)?;

let Some(nft) = wallet.db.nft(nft_id).await? else {
return Err(Error::MissingNft(nft_id));
};

let mut allocator = Allocator::new();
let metadata = nft
.info
.metadata
.to_clvm(&mut allocator)
.ok()
.and_then(|ptr| NftMetadata::from_clvm(&allocator, ptr).ok());

if let Some(metadata) = metadata {
let mut tx = wallet.db.tx().await?;

for uri in [
metadata.data_uris,
metadata.metadata_uris,
metadata.license_uris,
]
.concat()
{
tx.set_nft_uri_unchecked(uri).await?;
}

if let Some(hash) = metadata.data_hash {
tx.delete_nft_data(hash).await?;
}

if let Some(hash) = metadata.metadata_hash {
tx.delete_nft_data(hash).await?;
}

if let Some(hash) = metadata.license_hash {
tx.delete_nft_data(hash).await?;
}

tx.commit().await?;
}

Ok(RedownloadNftResponse {})
}

pub async fn increase_derivation_index(
&self,
req: IncreaseDerivationIndex,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-tauri"
version = "0.9.1"
version = "0.9.2"
description = "A next generation Chia wallet."
authors = ["Rigidity <[email protected]>"]
license = "Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/gen/apple/sage-tauri_iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.9.1</string>
<string>0.9.2</string>
<key>CFBundleVersion</key>
<string>0.9.1</string>
<string>0.9.2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand All @@ -45,4 +45,4 @@
<key>NSCameraUsageDescription</key>
<string>Read QR codes</string>
</dict>
</plist>
</plist>
9 changes: 9 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ pub async fn update_nft(state: State<'_, AppState>, req: UpdateNft) -> Result<Up
Ok(state.lock().await.update_nft(req).await?)
}

#[command]
#[specta]
pub async fn redownload_nft(
state: State<'_, AppState>,
req: RedownloadNft,
) -> Result<RedownloadNftResponse> {
Ok(state.lock().await.redownload_nft(req).await?)
}

#[command]
#[specta]
pub async fn increase_derivation_index(
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub fn run() {
commands::remove_cat,
commands::update_did,
commands::update_nft,
commands::redownload_nft,
commands::increase_derivation_index,
commands::get_peers,
commands::add_peer,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"productName": "Sage",
"version": "0.9.1",
"version": "0.9.2",
"identifier": "com.rigidnetwork.sage",
"build": {
"frontendDist": "../dist",
Expand Down
5 changes: 5 additions & 0 deletions src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ async updateDid(req: UpdateDid) : Promise<UpdateDidResponse> {
async updateNft(req: UpdateNft) : Promise<UpdateNftResponse> {
return await TAURI_INVOKE("update_nft", { req });
},
async redownloadNft(req: RedownloadNft) : Promise<RedownloadNftResponse> {
return await TAURI_INVOKE("redownload_nft", { req });
},
async increaseDerivationIndex(req: IncreaseDerivationIndex) : Promise<IncreaseDerivationIndexResponse> {
return await TAURI_INVOKE("increase_derivation_index", { req });
},
Expand Down Expand Up @@ -362,6 +365,8 @@ export type OfferSummary = { fee: Amount; maker: OfferAssets; taker: OfferAssets
export type OfferXch = { amount: Amount; royalty: Amount }
export type PeerRecord = { ip_addr: string; port: number; peak_height: number }
export type PendingTransactionRecord = { transaction_id: string; fee: Amount; submitted_at: string | null }
export type RedownloadNft = { nft_id: string }
export type RedownloadNftResponse = Record<string, never>
export type RemoveCat = { asset_id: string }
export type RemoveCatResponse = Record<string, never>
export type RemovePeer = { ip: string; ban: boolean }
Expand Down
Loading

0 comments on commit d41a0c4

Please sign in to comment.