use crate::client::LightconeClient;
use crate::error::SdkError;
use crate::http::RetryPolicy;
use super::{
CancelTarget, ExportWalletRequest, ExportWalletResponse, PrivyOrderEnvelope,
SignAndCancelAllRequest, SignAndCancelOrderRequest, SignAndSendOrderRequest,
SignAndSendTxRequest, SignAndSendTxResponse,
};
pub struct Privy<'a> {
pub(crate) client: &'a LightconeClient,
}
impl<'a> Privy<'a> {
pub async fn sign_and_send_tx(
&self,
wallet_id: &str,
base64_tx: &str,
) -> Result<SignAndSendTxResponse, SdkError> {
let url = format!("{}/api/privy/sign_and_send_tx", self.client.http.base_url());
let req = SignAndSendTxRequest {
wallet_id: wallet_id.to_string(),
base64_tx: base64_tx.to_string(),
};
self.client.http.post(&url, &req, RetryPolicy::None).await
}
pub async fn sign_and_send_order(
&self,
wallet_id: &str,
order: PrivyOrderEnvelope,
) -> Result<serde_json::Value, SdkError> {
let url = format!(
"{}/api/privy/sign_and_send_order",
self.client.http.base_url()
);
let req = SignAndSendOrderRequest {
wallet_id: wallet_id.to_string(),
order,
};
self.client.http.post(&url, &req, RetryPolicy::None).await
}
pub async fn sign_and_cancel_order(
&self,
wallet_id: &str,
order_hash: &str,
maker: &str,
) -> Result<serde_json::Value, SdkError> {
let url = format!(
"{}/api/privy/sign_and_cancel_order",
self.client.http.base_url()
);
let req = SignAndCancelOrderRequest {
wallet_id: wallet_id.to_string(),
maker: maker.to_string(),
cancel: CancelTarget::Limit {
order_hash: order_hash.to_string(),
},
};
self.client.http.post(&url, &req, RetryPolicy::None).await
}
pub async fn sign_and_cancel_trigger_order(
&self,
wallet_id: &str,
trigger_order_id: &str,
maker: &str,
) -> Result<serde_json::Value, SdkError> {
let url = format!(
"{}/api/privy/sign_and_cancel_order",
self.client.http.base_url()
);
let req = SignAndCancelOrderRequest {
wallet_id: wallet_id.to_string(),
maker: maker.to_string(),
cancel: CancelTarget::Trigger {
trigger_order_id: trigger_order_id.to_string(),
},
};
self.client.http.post(&url, &req, RetryPolicy::None).await
}
pub async fn sign_and_cancel_all_orders(
&self,
wallet_id: &str,
user_pubkey: &str,
orderbook_id: &str,
timestamp: i64,
salt: &str,
) -> Result<serde_json::Value, SdkError> {
let url = format!(
"{}/api/privy/sign_and_cancel_all_orders",
self.client.http.base_url()
);
let req = SignAndCancelAllRequest {
wallet_id: wallet_id.to_string(),
user_pubkey: user_pubkey.to_string(),
orderbook_id: orderbook_id.to_string(),
timestamp,
salt: salt.to_string(),
};
self.client.http.post(&url, &req, RetryPolicy::None).await
}
pub async fn export_wallet(
&self,
wallet_id: &str,
decode_pubkey_base64: &str,
) -> Result<ExportWalletResponse, SdkError> {
let url = format!("{}/api/privy/wallet/export", self.client.http.base_url());
let req = ExportWalletRequest {
wallet_id: wallet_id.to_string(),
decode_pubkey_base64: decode_pubkey_base64.to_string(),
};
self.client.http.post(&url, &req, RetryPolicy::None).await
}
}