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 get sync status and add UI card #321

Closed
wants to merge 6 commits into from
Closed
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
47 changes: 47 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sage-database = { path = "./crates/sage-database" }
sage-keychain = { path = "./crates/sage-keychain" }
sage-wallet = { path = "./crates/sage-wallet" }
sage-assets = { path = "./crates/sage-assets" }
utoipa = { version = "4.2.0", features = ["yaml"] }

# Serialization
serde = "1.0.204"
Expand Down
2 changes: 2 additions & 0 deletions crates/sage-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ tauri = ["dep:tauri-specta", "dep:specta"]
[dependencies]
sage-config = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tauri-specta = { workspace = true, features = ["derive"], optional = true }
specta = { workspace = true, features = ["derive", "bigdecimal"], optional = true }
once_cell = { workspace = true }
indexmap = { workspace = true, features = ["serde"] }
utoipa = { version = "4.2.0", features = ["yaml"] }
2 changes: 2 additions & 0 deletions crates/sage-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod events;
mod openapi;
mod records;
mod requests;
mod types;

pub use events::*;
pub use openapi::*;
pub use records::*;
pub use requests::*;
pub use types::*;
40 changes: 40 additions & 0 deletions crates/sage-api/src/openapi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::*;
use utoipa::OpenApi;

#[derive(OpenApi)]
#[openapi(
paths(),
components(
schemas(
// Keys
Login, LoginResponse,
Logout, LogoutResponse,
Resync, ResyncResponse,
GenerateMnemonic, GenerateMnemonicResponse,
ImportKey, ImportKeyResponse,
DeleteKey, DeleteKeyResponse,
RenameKey, RenameKeyResponse,
GetKey, GetKeyResponse,
GetSecretKey, GetSecretKeyResponse,
GetKeys, GetKeysResponse,
// Offers
MakeOffer, MakeOfferResponse,
TakeOffer, TakeOfferResponse,
CombineOffers, CombineOffersResponse,
ViewOffer, ViewOfferResponse,
ImportOffer, ImportOfferResponse,
GetOffers, GetOffersResponse,
GetOffer, GetOfferResponse,
DeleteOffer, DeleteOfferResponse,
CancelOffer, CancelOfferResponse,
// Add other types as needed...
)
),
tags(
(name = "keys", description = "Key management endpoints"),
(name = "offers", description = "Offer management endpoints"),
// Add other tags as needed...
)
)]
#[derive(Copy, Clone, Debug)]
pub struct ApiDoc;
11 changes: 6 additions & 5 deletions crates/sage-api/src/records/offer_summary.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::Amount;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct OfferSummary {
pub fee: Amount,
pub maker: OfferAssets,
pub taker: OfferAssets,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct OfferAssets {
pub xch: OfferXch,
pub cats: IndexMap<String, OfferCat>,
pub nfts: IndexMap<String, OfferNft>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct OfferXch {
pub amount: Amount,
pub royalty: Amount,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct OfferCat {
pub amount: Amount,
Expand All @@ -36,7 +37,7 @@ pub struct OfferCat {
pub icon_url: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct OfferNft {
pub image_data: Option<String>,
Expand Down
2 changes: 2 additions & 0 deletions crates/sage-api/src/requests/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct GetSyncStatusResponse {
pub total_coins: u32,
pub receive_address: String,
pub burn_address: String,
pub peer_count: u32,
pub peer_max_height: u32,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down
41 changes: 21 additions & 20 deletions crates/sage-api/src/requests/keys.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::{KeyInfo, SecretKeyInfo};

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct Login {
pub fingerprint: u32,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct LoginResponse {}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct Logout {}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct LogoutResponse {}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct Resync {
pub fingerprint: u32,
Expand All @@ -32,23 +33,23 @@ pub struct Resync {
pub delete_hardened_derivations: bool,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct ResyncResponse {}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GenerateMnemonic {
pub use_24_words: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GenerateMnemonicResponse {
pub mnemonic: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct ImportKey {
pub name: String,
Expand All @@ -65,63 +66,63 @@ fn yes() -> bool {
true
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct ImportKeyResponse {
pub fingerprint: u32,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct DeleteKey {
pub fingerprint: u32,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct DeleteKeyResponse {}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct RenameKey {
pub fingerprint: u32,
pub name: String,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct RenameKeyResponse {}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GetKeys {}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GetKeysResponse {
pub keys: Vec<KeyInfo>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GetKey {
#[serde(default)]
pub fingerprint: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GetKeyResponse {
pub key: Option<KeyInfo>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GetSecretKey {
pub fingerprint: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[cfg_attr(feature = "tauri", derive(specta::Type))]
pub struct GetSecretKeyResponse {
pub secrets: Option<SecretKeyInfo>,
Expand Down
Loading
Loading