Skip to content

Commit

Permalink
doc comms
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Dec 14, 2023
1 parent 087f5da commit ab0ddc9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
15 changes: 12 additions & 3 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ async fn withdraw_impl(coin: EthCoin, req: WithdrawRequest) -> WithdrawResult {
pub async fn withdraw_erc1155(ctx: MmArc, withdraw_type: WithdrawErc1155) -> WithdrawNftResult {
let coin = lp_coinfind_or_err(&ctx, withdraw_type.chain.to_ticker()).await?;
let (to_addr, token_addr, eth_coin) =
get_valid_nft_add_to_withdraw(coin, &withdraw_type.to, &withdraw_type.token_address)?;
get_valid_nft_addr_to_withdraw(coin, &withdraw_type.to, &withdraw_type.token_address)?;
let my_address_str = eth_coin.my_address()?;

let token_id_str = &withdraw_type.token_id.to_string();
Expand Down Expand Up @@ -976,7 +976,7 @@ pub async fn withdraw_erc1155(ctx: MmArc, withdraw_type: WithdrawErc1155) -> Wit
pub async fn withdraw_erc721(ctx: MmArc, withdraw_type: WithdrawErc721) -> WithdrawNftResult {
let coin = lp_coinfind_or_err(&ctx, withdraw_type.chain.to_ticker()).await?;
let (to_addr, token_addr, eth_coin) =
get_valid_nft_add_to_withdraw(coin, &withdraw_type.to, &withdraw_type.token_address)?;
get_valid_nft_addr_to_withdraw(coin, &withdraw_type.to, &withdraw_type.token_address)?;
let my_address_str = eth_coin.my_address()?;

let token_id_str = &withdraw_type.token_id.to_string();
Expand Down Expand Up @@ -5720,6 +5720,7 @@ fn increase_gas_price_by_stage(gas_price: U256, level: &FeeApproxStage) -> U256
}
}

/// Represents errors that can occur while retrieving an Ethereum address.
#[derive(Clone, Debug, Deserialize, Display, PartialEq, Serialize)]
pub enum GetEthAddressError {
PrivKeyPolicyNotAllowed(PrivKeyPolicyNotAllowed),
Expand Down Expand Up @@ -5760,6 +5761,11 @@ pub async fn get_eth_address(
})
}

/// Errors encountered while validating Ethereum addresses for NFT withdrawal.
///
/// Variants:
/// - `CoinDoesntSupportNftWithdraw`: The specified coin does not support NFT withdrawal.
/// - `InvalidAddress`: The provided address is invalid.
#[derive(Display)]
pub enum GetValidEthWithdrawAddError {
#[display(fmt = "{} coin doesn't support NFT withdrawing", coin)]
Expand All @@ -5769,7 +5775,10 @@ pub enum GetValidEthWithdrawAddError {
InvalidAddress(String),
}

fn get_valid_nft_add_to_withdraw(
/// Validates Ethereum addresses for NFT withdrawal.
/// Returns a tuple of valid `to` address, `token` address, and `EthCoin` instance on success.
/// Errors if the coin doesn't support NFT withdrawal or if the addresses are invalid.
fn get_valid_nft_addr_to_withdraw(
coin_enum: MmCoinEnum,
to: &str,
token_add: &str,
Expand Down
11 changes: 11 additions & 0 deletions mm2src/coins/nft/nft_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ impl From<GetInfoFromUriError> for MetaFromUrlError {
fn from(e: GetInfoFromUriError) -> Self { MetaFromUrlError::GetInfoFromUriError(e) }
}

/// Represents errors that can occur while locking the NFT database.
///
/// Variants:
/// - `WasmNftCacheError`: Errors specific to the WebAssembly (WASM) environment's NFT cache.
/// - `SqlError`: Errors related to SQL operations in non-WASM environments.
#[derive(Debug, Display)]
pub enum LockDBError {
#[cfg(target_arch = "wasm32")]
Expand All @@ -363,6 +368,12 @@ impl From<WasmNftCacheError> for LockDBError {
fn from(e: WasmNftCacheError) -> Self { LockDBError::WasmNftCacheError(e) }
}

/// Errors related to calculating transfer confirmations for NFTs.
///
/// Variants:
/// - `NoSuchCoin`: Occurs when the specified coin does not exist.
/// - `CoinDoesntSupportNft`: Triggered when the specified coin does not support NFT operations.
/// - `GetCurrentBlockErr`: Represents errors encountered while retrieving the current block number.
#[derive(Clone, Debug, Deserialize, Display, PartialEq, Serialize)]
pub enum TransferConfirmationsError {
#[display(fmt = "No such coin {}", coin)]
Expand Down
26 changes: 26 additions & 0 deletions mm2src/coins/nft/nft_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ pub struct NftList {
pub(crate) total: usize,
}

/// Parameters for withdrawing an ERC-1155 token.
///
/// Fields:
/// - `chain`: The blockchain network to perform the withdrawal on.
/// - `to`: The address to send the NFT to.
/// - `token_address`: The address of the ERC-1155 token contract.
/// - `token_id`: The unique identifier of the NFT to withdraw.
/// - `amount`: Optional amount of the token to withdraw. Defaults to 1 if not specified.
/// - `max`: If set to `true`, withdraws the maximum amount available. Overrides the `amount` field.
/// - `fee`: Optional details for the withdrawal fee.
#[derive(Clone, Deserialize)]
pub struct WithdrawErc1155 {
pub(crate) chain: Chain,
Expand All @@ -399,6 +409,14 @@ pub struct WithdrawErc1155 {
pub(crate) fee: Option<WithdrawFee>,
}

/// Parameters for withdrawing an ERC-721 token.
///
/// Fields:
/// - `chain`: The blockchain network to perform the withdrawal on.
/// - `to`: The address to send the NFT to.
/// - `token_address`: The address of the ERC-721 token contract.
/// - `token_id`: The unique identifier of the NFT to withdraw.
/// - `fee`: Optional details for the withdrawal fee.
#[derive(Clone, Deserialize)]
pub struct WithdrawErc721 {
pub(crate) chain: Chain,
Expand All @@ -409,6 +427,11 @@ pub struct WithdrawErc721 {
pub(crate) fee: Option<WithdrawFee>,
}

/// Represents a request for withdrawing an NFT, supporting different ERC standards.
///
/// Variants:
/// - `WithdrawErc1155`: Parameters for withdrawing an ERC-1155 token.
/// - `WithdrawErc721`: Parameters for withdrawing an ERC-721 token.
#[derive(Clone, Deserialize)]
#[serde(tag = "type", content = "withdraw_data")]
#[serde(rename_all = "snake_case")]
Expand All @@ -417,6 +440,9 @@ pub enum WithdrawNftReq {
WithdrawErc721(WithdrawErc721),
}

/// Details of NFT transaction.
///
/// Includes the raw transaction hex for broadcasting, along with additional information about the transaction.
#[derive(Debug, Deserialize, Serialize)]
pub struct TransactionNftDetails {
/// Raw bytes of signed transaction, this should be sent as is to `send_raw_transaction` RPC to broadcast the transaction
Expand Down

0 comments on commit ab0ddc9

Please sign in to comment.