Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Dec 18, 2024
1 parent 2e27288 commit 06edd24
Show file tree
Hide file tree
Showing 19 changed files with 439 additions and 149 deletions.
23 changes: 7 additions & 16 deletions crates/sage-api/src/records/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ pub struct NftRecord {
pub sensitive_content: bool,
pub name: Option<String>,
pub created_height: Option<u32>,
pub data_mime_type: Option<String>,
pub data: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct NftInfo {
pub launcher_id: String,
pub collection_id: Option<String>,
pub collection_name: Option<String>,
pub minter_did: Option<String>,
pub owner_did: Option<String>,
pub visible: bool,
pub coin_id: String,
pub address: String,
pub royalty_address: String,
Expand All @@ -36,8 +24,11 @@ pub struct NftInfo {
pub license_hash: Option<String>,
pub edition_number: Option<u32>,
pub edition_total: Option<u32>,
pub created_height: Option<u32>,
pub data: Option<String>,
pub data_mime_type: Option<String>,
pub metadata: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct NftData {
pub blob: Option<String>,
pub mime_type: Option<String>,
pub metadata_json: Option<String>,
}
14 changes: 12 additions & 2 deletions crates/sage-api/src/requests/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use specta::Type;

use crate::{
Amount, CatRecord, CoinRecord, DerivationRecord, DidRecord, NftCollectionRecord, NftInfo,
Amount, CatRecord, CoinRecord, DerivationRecord, DidRecord, NftCollectionRecord, NftData,
NftRecord, PendingTransactionRecord, Unit,
};

Expand Down Expand Up @@ -143,5 +143,15 @@ pub struct GetNft {

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct GetNftResponse {
pub nft: Option<NftInfo>,
pub nft: Option<NftRecord>,
}

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

#[derive(Debug, Clone, Serialize, Deserialize, Type)]
pub struct GetNftDataResponse {
pub data: Option<NftData>,
}
2 changes: 2 additions & 0 deletions crates/sage-api/src/requests/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub struct SendCat {
pub amount: Amount,
pub fee: Amount,
#[serde(default)]
pub memos: Vec<String>,
#[serde(default)]
pub auto_submit: bool,
}

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 @@ -84,6 +84,7 @@ routes!(
get_nft_collection await: GetNftCollection = "/get_nft_collection",
get_nfts await: GetNfts = "/get_nfts",
get_nft await: GetNft = "/get_nft",
get_nft_data await: GetNftData = "/get_nft_data",

send_xch await: SendXch = "/send_xch",
combine_xch await: CombineXch = "/combine_xch",
Expand Down
26 changes: 18 additions & 8 deletions crates/sage-wallet/src/wallet/cats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem;

use chia::{
bls::PublicKey,
protocol::{Bytes32, CoinSpend},
protocol::{Bytes, Bytes32, CoinSpend},
};
use chia_wallet_sdk::{Cat, Conditions, SpendContext};

Expand Down Expand Up @@ -58,12 +58,14 @@ impl Wallet {
}

/// Sends the given amount of XCH to the given puzzle hash, minus the fee.
#[allow(clippy::too_many_arguments)]
pub async fn send_cat(
&self,
asset_id: Bytes32,
puzzle_hash: Bytes32,
amount: u64,
fee: u64,
mut memos: Vec<Bytes>,
hardened: bool,
reuse: bool,
) -> Result<Vec<CoinSpend>, WalletError> {
Expand Down Expand Up @@ -113,11 +115,11 @@ impl Wallet {
return (cat, Conditions::new());
}

let mut conditions = mem::take(&mut conditions).create_coin(
puzzle_hash,
amount,
vec![puzzle_hash.into()],
);
let mut output_memos = vec![puzzle_hash.into()];
output_memos.extend(mem::take(&mut memos));

let mut conditions =
mem::take(&mut conditions).create_coin(puzzle_hash, amount, output_memos);

if cat_change > 0 {
conditions = conditions.create_coin(
Expand Down Expand Up @@ -159,7 +161,7 @@ mod tests {

let coin_spends = test
.wallet
.send_cat(asset_id, test.puzzle_hash, 750, 0, false, true)
.send_cat(asset_id, test.puzzle_hash, 750, 0, Vec::new(), false, true)
.await?;
assert_eq!(coin_spends.len(), 1);

Expand All @@ -171,7 +173,15 @@ mod tests {

let coin_spends = test
.wallet
.send_cat(asset_id, test.puzzle_hash, 1000, 500, false, true)
.send_cat(
asset_id,
test.puzzle_hash,
1000,
500,
Vec::new(),
false,
true,
)
.await?;
assert_eq!(coin_spends.len(), 3);

Expand Down
Loading

0 comments on commit 06edd24

Please sign in to comment.