From 7e58a09acd148077e9b7122e7753e01afda82bed Mon Sep 17 00:00:00 2001 From: Jose D Robles Date: Wed, 20 Dec 2023 23:56:56 +0100 Subject: [PATCH] Modifs in typescript (#441) * Fix structs * Add methods to web.rs and update rgb.ts * Update web.rs Co-authored-by: Armando CD * Update rgb.ts Co-authored-by: Armando CD * Update rgb.ts Co-authored-by: Armando CD --------- Co-authored-by: Jose Diego Robles Pardo Co-authored-by: Armando CD --- lib/web/rgb.ts | 38 +++++++++++++++++++++++++++++++++++++- src/web.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/lib/web/rgb.ts b/lib/web/rgb.ts index 9981f26d..d8bb10d0 100644 --- a/lib/web/rgb.ts +++ b/lib/web/rgb.ts @@ -157,6 +157,12 @@ export const createOffer = async ( ): Promise => JSON.parse(await BMC.create_offer(nostrHexSk, request)); +export const createAuctionBid = async ( + nostrHexSk: string, + request: RgbAuctionBidRequest +): Promise => + JSON.parse(await BMC.create_auction_bid(nostrHexSk, request)); + export const createBid = async ( nostrHexSk: string, request: RgbBidRequest @@ -169,6 +175,15 @@ export const createSwap = async ( ): Promise => JSON.parse(await BMC.create_swap(nostrHexSk, request)); +export const finishAuction = async ( + nostrHexSk: string, + request: string +): Promise => + JSON.parse(await BMC.finish_auction(nostrHexSk, request)); + +export const listAuctions = async (): Promise => + JSON.parse(await BMC.list_auctions()); + export const directSwap = async ( nostrHexSk: string, request: RgbBidRequest @@ -935,9 +950,30 @@ export interface PublicRgbOfferResponse { /// Bitcoin Price bitcoinPrice: bigint; /// Initial Offer PSBT - offerPsbt: string; + offerPsbt?: string; +} + +export interface RgbAuctionFinishResponse { + /// Bundle ID + bundle_id: string, + /// New Change Outpoint + outpoint: string, + /// Sold Items + sold: Map, + /// Reamining Items + remaining: Map, } +export interface RgbSwapItem { + /// Contract ID + contractId: string, + /// Iface + iface: string, + /// Final Consig + contractAmount: string, +} + + export interface PublicRgbBidResponse { /// Bid ID bidId: string; diff --git a/src/web.rs b/src/web.rs index de2d03fd..1b545c90 100644 --- a/src/web.rs +++ b/src/web.rs @@ -9,8 +9,9 @@ use crate::rgb::structs::ContractAmount; use crate::structs::{ AcceptRequest, FullIssueRequest, FullRgbTransferRequest, ImportRequest, InvoiceRequest, IssueMediaRequest, IssueRequest, MediaRequest, PsbtRequest, PublishPsbtRequest, ReIssueRequest, - RgbBidRequest, RgbOfferRequest, RgbRemoveTransferRequest, RgbSaveTransferRequest, - RgbSwapRequest, RgbTransferRequest, SecretString, SignPsbtRequest, WatcherRequest, + RgbAuctionBidRequest, RgbBidRequest, RgbOfferRequest, RgbRemoveTransferRequest, + RgbSaveTransferRequest, RgbSwapRequest, RgbTransferRequest, SecretString, SignPsbtRequest, + WatcherRequest, }; pub fn set_panic_hook() { @@ -874,6 +875,21 @@ pub mod rgb { }) } + #[wasm_bindgen] + pub fn create_auction_bid(nostr_hex_sk: String, request: JsValue) -> Promise { + set_panic_hook(); + + future_to_promise(async move { + let bid_req: RgbAuctionBidRequest = serde_wasm_bindgen::from_value(request).unwrap(); + match crate::rgb::create_auction_bid(&nostr_hex_sk, bid_req).await { + Ok(result) => Ok(JsValue::from_string( + serde_json::to_string(&result).unwrap(), + )), + Err(err) => Err(JsValue::from_string(err.to_string())), + } + }) + } + #[wasm_bindgen] pub fn create_bid(nostr_hex_sk: String, request: JsValue) -> Promise { set_panic_hook(); @@ -904,6 +920,34 @@ pub mod rgb { }) } + #[wasm_bindgen] + pub fn finish_auction(nostr_hex_sk: String, request: JsValue) -> Promise { + set_panic_hook(); + + future_to_promise(async move { + let bundle_id: String = serde_wasm_bindgen::from_value(request).unwrap(); + match crate::rgb::finish_auction_offers(&nostr_hex_sk, bundle_id).await { + Ok(result) => Ok(JsValue::from_string( + serde_json::to_string(&result).unwrap(), + )), + Err(err) => Err(JsValue::from_string(err.to_string())), + } + }) + } + + #[wasm_bindgen] + pub fn list_auctions() -> Promise { + set_panic_hook(); + + future_to_promise(async move { + match crate::rgb::list_auctions().await { + Ok(result) => Ok(JsValue::from_string( + serde_json::to_string(&result).unwrap(), + )), + Err(err) => Err(JsValue::from_string(err.to_string())), + } + }) + } #[wasm_bindgen] pub fn direct_swap(nostr_hex_sk: String, request: JsValue) -> Promise { set_panic_hook();