-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,014 additions
and
462 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use specta::Type; | ||
|
||
use crate::Amount; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, Type)] | ||
pub struct MakeOffer { | ||
pub requested_assets: Assets, | ||
pub offered_assets: Assets, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, Type)] | ||
pub struct Assets { | ||
pub xch: Amount, | ||
pub cats: Vec<CatAmount>, | ||
pub nfts: Vec<String>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, Type)] | ||
pub struct CatAmount { | ||
pub asset_id: String, | ||
pub amount: Amount, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod fetch_nft_did; | ||
mod fetch_nft_offer_details; | ||
mod fetch_uri; | ||
mod offchain_metadata; | ||
|
||
pub use fetch_nft_did::*; | ||
pub use fetch_nft_offer_details::*; | ||
pub use fetch_uri::*; | ||
pub use offchain_metadata::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::time::Duration; | ||
|
||
use chia::{ | ||
clvm_traits::{FromClvm, ToClvm}, | ||
protocol::{Bytes32, Program}, | ||
}; | ||
use chia_wallet_sdk::{HashedPtr, Nft, Puzzle}; | ||
use clvmr::Allocator; | ||
use tokio::time::{sleep, timeout}; | ||
|
||
use crate::{NftOfferDetails, WalletError, WalletPeer}; | ||
|
||
pub async fn fetch_nft_offer_details( | ||
peer: &WalletPeer, | ||
launcher_id: Bytes32, | ||
) -> Result<Option<NftOfferDetails>, WalletError> { | ||
let mut offer_details = None::<NftOfferDetails>; | ||
let mut current_id = launcher_id; | ||
|
||
loop { | ||
let Some(child) = | ||
timeout(Duration::from_secs(5), peer.try_fetch_child(current_id)).await?? | ||
else { | ||
break; | ||
}; | ||
|
||
let spent_height = child.spent_height.ok_or(WalletError::PeerMisbehaved)?; | ||
current_id = child.coin.coin_id(); | ||
|
||
let (puzzle_reveal, solution) = timeout( | ||
Duration::from_secs(15), | ||
peer.fetch_puzzle_solution(current_id, spent_height), | ||
) | ||
.await??; | ||
|
||
let mut allocator = Allocator::new(); | ||
|
||
let puzzle_reveal = puzzle_reveal.to_clvm(&mut allocator)?; | ||
let puzzle = Puzzle::parse(&allocator, puzzle_reveal); | ||
let solution = solution.to_clvm(&mut allocator)?; | ||
|
||
if let Some(nft) = | ||
Nft::<HashedPtr>::parse_child(&mut allocator, child.coin, puzzle, solution) | ||
.ok() | ||
.flatten() | ||
{ | ||
offer_details = Some(NftOfferDetails { | ||
metadata: Program::from_clvm(&allocator, nft.info.metadata.ptr())?, | ||
metadata_updater_puzzle_hash: nft.info.metadata_updater_puzzle_hash, | ||
royalty_puzzle_hash: nft.info.royalty_puzzle_hash, | ||
royalty_ten_thousandths: nft.info.royalty_ten_thousandths, | ||
}); | ||
break; | ||
} | ||
|
||
sleep(Duration::from_secs(1)).await; | ||
} | ||
|
||
Ok(offer_details) | ||
} |
Oops, something went wrong.