Skip to content

Commit

Permalink
chore: rename structs to friendly names
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Sep 15, 2023
1 parent 6b76145 commit 1a17be7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
37 changes: 18 additions & 19 deletions src/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ use crate::{
ImportRequest, InterfaceDetail, InterfacesResponse, InvoiceRequest, InvoiceResponse,
IssueMetaRequest, IssueMetadata, IssueRequest, IssueResponse, NewCollectible,
NextAddressResponse, NextUtxoResponse, NextUtxosResponse, PsbtFeeRequest, PsbtRequest,
PsbtResponse, ReIssueRequest, ReIssueResponse, RgbInvoiceResponse,
RgbRemoveTransferRequest, RgbSaveTransferRequest, RgbSwapBuyerRequest,
RgbSwapBuyerResponse, RgbSwapSellerRequest, RgbSwapSellerResponse, RgbSwapTransferRequest,
RgbSwapTransferResponse, RgbTransferDetail, RgbTransferRequest, RgbTransferResponse,
RgbTransferStatusResponse, RgbTransfersResponse, SchemaDetail, SchemasResponse,
TransferType, TxStatus, UDADetail, UtxoResponse, WatcherDetailResponse, WatcherRequest,
WatcherResponse, WatcherUtxoResponse,
PsbtResponse, ReIssueRequest, ReIssueResponse, RgbBidRequest, RgbBidResponse,
RgbInvoiceResponse, RgbOfferRequest, RgbOfferResponse, RgbRemoveTransferRequest,
RgbSaveTransferRequest, RgbSwapRequest, RgbSwapResponse, RgbTransferDetail,
RgbTransferRequest, RgbTransferResponse, RgbTransferStatusResponse, RgbTransfersResponse,
SchemaDetail, SchemasResponse, TransferType, TxStatus, UDADetail, UtxoResponse,
WatcherDetailResponse, WatcherRequest, WatcherResponse, WatcherUtxoResponse,
},
validators::RGBContext,
};
Expand Down Expand Up @@ -858,8 +857,8 @@ pub enum RgbSwapError {

pub async fn create_offer_seller(
sk: &str,
request: RgbSwapSellerRequest,
) -> Result<RgbSwapSellerResponse, RgbSwapError> {
request: RgbOfferRequest,
) -> Result<RgbOfferResponse, RgbSwapError> {
if let Err(err) = request.validate(&RGBContext::default()) {
let errors = err
.flatten()
Expand Down Expand Up @@ -894,7 +893,7 @@ pub async fn create_offer_seller(
.wallets
.insert(RGB_DEFAULT_NAME.to_owned(), rgb_wallet.clone());

let RgbSwapSellerRequest {
let RgbOfferRequest {
contract_id,
contract_amount,
bitcoin_price,
Expand Down Expand Up @@ -943,7 +942,7 @@ pub async fn create_offer_seller(
seller_psbt.psbt.clone(),
);

let resp = RgbSwapSellerResponse {
let resp = RgbOfferResponse {
offer_id: new_offer.clone().offer_id,
contract_id: contract_id.clone(),
contract_amount,
Expand Down Expand Up @@ -976,8 +975,8 @@ pub async fn create_offer_seller(

pub async fn create_offer_buyer(
sk: &str,
request: RgbSwapBuyerRequest,
) -> Result<RgbSwapBuyerResponse, RgbSwapError> {
request: RgbBidRequest,
) -> Result<RgbBidResponse, RgbSwapError> {
if let Err(err) = request.validate(&RGBContext::default()) {
let errors = err
.flatten()
Expand All @@ -1001,7 +1000,7 @@ pub async fn create_offer_buyer(
_ => return Err(RgbSwapError::NoWatcher),
};

let RgbSwapBuyerRequest {
let RgbBidRequest {
offer_id,
change_terminal,
..
Expand Down Expand Up @@ -1097,7 +1096,7 @@ pub async fn create_offer_buyer(
let invoice = invoice.to_string();
new_bid.buyer_invoice = invoice.clone();

let resp = RgbSwapBuyerResponse {
let resp = RgbBidResponse {
bid_id,
offer_id,
invoice,
Expand All @@ -1120,8 +1119,8 @@ pub async fn create_offer_buyer(

pub async fn create_swap_transfer(
sk: &str,
request: RgbSwapTransferRequest,
) -> Result<RgbSwapTransferResponse, RgbSwapError> {
request: RgbSwapRequest,
) -> Result<RgbSwapResponse, RgbSwapError> {
if let Err(err) = request.validate(&RGBContext::default()) {
let errors = err
.flatten()
Expand All @@ -1140,7 +1139,7 @@ pub async fn create_swap_transfer(
.await
.map_err(RgbSwapError::IO)?;

let RgbSwapTransferRequest {
let RgbSwapRequest {
offer_id,
bid_id,
swap_psbt,
Expand Down Expand Up @@ -1185,7 +1184,7 @@ pub async fn create_swap_transfer(
.await
.map_err(RgbSwapError::IO)?;

Ok(RgbSwapTransferResponse {
Ok(RgbSwapResponse {
consig_id,
final_consig,
final_psbt,
Expand Down
10 changes: 5 additions & 5 deletions src/rgb/prebuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
constants::NETWORK,
structs::{
AllocationDetail, AllocationValue, AssetType, FullRgbTransferRequest, PsbtFeeRequest,
PsbtInputRequest, RgbSwapBuyerRequest, RgbSwapSellerRequest, SecretString,
PsbtInputRequest, RgbBidRequest, RgbOfferRequest, SecretString,
},
validators::RGBContext,
};
Expand Down Expand Up @@ -381,7 +381,7 @@ pub async fn prebuild_transfer_asset(
}

pub async fn prebuild_seller_swap(
request: RgbSwapSellerRequest,
request: RgbOfferRequest,
stock: &mut Stock,
rgb_wallet: &mut RgbWallet,
resolver: &mut ExplorerResolver,
Expand Down Expand Up @@ -409,7 +409,7 @@ pub async fn prebuild_seller_swap(
RgbSwapError::Validation(errors)
})?;

let RgbSwapSellerRequest {
let RgbOfferRequest {
descriptor,
iface: iface_name,
contract_amount: target_amount,
Expand Down Expand Up @@ -646,7 +646,7 @@ pub async fn prebuild_seller_swap(
}

pub async fn prebuild_buyer_swap(
request: RgbSwapBuyerRequest,
request: RgbBidRequest,
rgb_wallet: &mut RgbWallet,
resolver: &mut ExplorerResolver,
) -> Result<(RgbBid, Vec<PsbtInputRequest>, Vec<String>, u64), RgbSwapError> {
Expand All @@ -659,7 +659,7 @@ pub async fn prebuild_buyer_swap(
return Err(RgbSwapError::Validation(errors));
}

let RgbSwapBuyerRequest {
let RgbBidRequest {
descriptor,
offer_id,
fee,
Expand Down
12 changes: 6 additions & 6 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ pub struct UtxoSpentStatus {
#[garde(context(RGBContext))]
#[serde(rename_all = "camelCase")]
#[display("")]
pub struct RgbSwapSellerRequest {
pub struct RgbOfferRequest {
/// The Contract ID
#[garde(ascii)]
#[garde(length(min = 0, max = 100))]
Expand Down Expand Up @@ -1076,7 +1076,7 @@ pub struct RgbSwapSellerRequest {
#[derive(Clone, Serialize, Deserialize, Debug, Display, Default)]
#[serde(rename_all = "camelCase")]
#[display("")]
pub struct RgbSwapSellerResponse {
pub struct RgbOfferResponse {
/// The Contract ID
pub offer_id: String,
/// The Contract ID
Expand All @@ -1095,7 +1095,7 @@ pub struct RgbSwapSellerResponse {
#[garde(context(RGBContext))]
#[serde(rename_all = "camelCase")]
#[display("")]
pub struct RgbSwapBuyerRequest {
pub struct RgbBidRequest {
/// The Offer ID
#[garde(ascii)]
#[garde(length(min = 0, max = 100))]
Expand All @@ -1120,7 +1120,7 @@ pub struct RgbSwapBuyerRequest {
#[derive(Clone, Serialize, Deserialize, Debug, Display, Default)]
#[serde(rename_all = "camelCase")]
#[display("")]
pub struct RgbSwapBuyerResponse {
pub struct RgbBidResponse {
/// The Bid ID
pub bid_id: String,
/// The Offer ID
Expand All @@ -1137,7 +1137,7 @@ pub struct RgbSwapBuyerResponse {
#[garde(context(RGBContext))]
#[serde(rename_all = "camelCase")]
#[display("")]
pub struct RgbSwapTransferRequest {
pub struct RgbSwapRequest {
/// Offer ID
#[garde(ascii)]
#[garde(length(min = 0, max = 100))]
Expand All @@ -1153,7 +1153,7 @@ pub struct RgbSwapTransferRequest {

#[derive(Clone, Serialize, Deserialize, Debug, Display, Default)]
#[display("")]
pub struct RgbSwapTransferResponse {
pub struct RgbSwapResponse {
/// Transfer ID
pub consig_id: String,
/// Final Consig
Expand Down
20 changes: 10 additions & 10 deletions tests/rgb/integration/swaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use bitmask_core::{
create_watcher, get_contract,
},
structs::{
AcceptRequest, IssueResponse, PsbtFeeRequest, RgbSwapBuyerRequest, RgbSwapBuyerResponse,
RgbSwapSellerRequest, RgbSwapSellerResponse, RgbSwapTransferRequest,
RgbSwapTransferResponse, SecretString, SignPsbtRequest, SignedPsbtResponse, WatcherRequest,
AcceptRequest, IssueResponse, PsbtFeeRequest, RgbBidRequest, RgbBidResponse,
RgbOfferRequest, RgbOfferResponse, RgbSwapRequest, RgbSwapResponse, SecretString,
SignPsbtRequest, SignedPsbtResponse, WatcherRequest,
},
};

Expand Down Expand Up @@ -134,7 +134,7 @@ async fn create_scriptless_swap() -> anyhow::Result<()> {
let seller_sk = seller_keys.private.nostr_prv.clone();
let bitcoin_price: u64 = 100000;
let seller_asset_desc = seller_keys.public.rgb_assets_descriptor_xpub.clone();
let seller_swap_req = RgbSwapSellerRequest {
let seller_swap_req = RgbOfferRequest {
contract_id: contract_id.clone(),
iface,
contract_amount,
Expand All @@ -148,7 +148,7 @@ async fn create_scriptless_swap() -> anyhow::Result<()> {
assert!(seller_swap_resp.is_ok());

// 7. Create Buyer Swap Side
let RgbSwapSellerResponse {
let RgbOfferResponse {
offer_id,
contract_amount,
seller_psbt,
Expand All @@ -157,7 +157,7 @@ async fn create_scriptless_swap() -> anyhow::Result<()> {

let buyer_sk = buyer_keys.private.nostr_prv.clone();
let buyer_btc_desc = buyer_keys.public.btc_descriptor_xpub.clone();
let buyer_swap_req = RgbSwapBuyerRequest {
let buyer_swap_req = RgbBidRequest {
offer_id: offer_id.clone(),
asset_amount: contract_amount,
descriptor: SecretString(buyer_btc_desc),
Expand All @@ -170,7 +170,7 @@ async fn create_scriptless_swap() -> anyhow::Result<()> {
assert!(buyer_swap_resp.is_ok());

// 8. Sign the Buyer Side
let RgbSwapBuyerResponse {
let RgbBidResponse {
bid_id, swap_psbt, ..
} = buyer_swap_resp?;
let request = SignPsbtRequest {
Expand All @@ -183,11 +183,11 @@ async fn create_scriptless_swap() -> anyhow::Result<()> {
let buyer_psbt_resp = sign_psbt_file(request).await;
assert!(buyer_psbt_resp.is_ok());

// 9.Create Swap PSBT
// 9. Create Swap PSBT
let SignedPsbtResponse {
psbt: swap_psbt, ..
} = buyer_psbt_resp?;
let final_swap_req = RgbSwapTransferRequest {
let final_swap_req = RgbSwapRequest {
offer_id,
bid_id,
swap_psbt,
Expand All @@ -197,7 +197,7 @@ async fn create_scriptless_swap() -> anyhow::Result<()> {
assert!(final_swap_resp.is_ok());

// 8. Sign the Final PSBT
let RgbSwapTransferResponse {
let RgbSwapResponse {
final_consig,
final_psbt,
..
Expand Down

0 comments on commit 1a17be7

Please sign in to comment.