Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Withdraw ERC1155 and EVM based chains support added for NFT PoC #1704

Merged
merged 91 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
c142d97
wip
laruh Jan 20, 2023
b233d01
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Jan 20, 2023
df5212a
wip
laruh Jan 22, 2023
4a50218
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Jan 23, 2023
6ed1ee8
wip some structures were added
laruh Jan 24, 2023
853d289
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Jan 24, 2023
a7dc383
wip
laruh Jan 26, 2023
55e11b7
wip
laruh Jan 27, 2023
5653da3
wip
laruh Jan 27, 2023
28dac60
fn get_my_address was moved into lp_coins.rs
laruh Jan 27, 2023
bd3ac54
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Jan 27, 2023
2af943a
wip get_my_address
laruh Feb 1, 2023
2cbbc23
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 1, 2023
551f895
get_my_address works
laruh Feb 1, 2023
cd1e11c
send_moralis_request, errors, get_nft_list wip
laruh Feb 2, 2023
f617e5d
add targets for send_moralis_request
laruh Feb 3, 2023
28f3e63
wip
laruh Feb 3, 2023
db638e9
wip
laruh Feb 3, 2023
5fc4e8e
wip use fn slurp_req_body in fn send_moralis_request
laruh Feb 3, 2023
fd2aaef
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 6, 2023
778dd60
wip fix wasm
laruh Feb 7, 2023
f83a9ff
wip cursor in get_nft_list
laruh Feb 7, 2023
8636599
wip impl Deserialize for Wrap
laruh Feb 8, 2023
a33be79
get_nft_list
laruh Feb 8, 2023
f9ad871
remove unnecessary notes
laruh Feb 8, 2023
5bef9bf
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 8, 2023
36798e9
wip get_nft_transfers
laruh Feb 9, 2023
91cf067
get_nft_transfers works
laruh Feb 9, 2023
f5f19c7
polish code
laruh Feb 9, 2023
7860331
polish code
laruh Feb 9, 2023
9c45de9
remove Option from some fields in Nft struct
laruh Feb 10, 2023
c932d36
wip get_nft_metadata
laruh Feb 10, 2023
3411af2
use NftWrapper in fn get_nft_metadata, add some doc comments
laruh Feb 12, 2023
8185875
remove allow(dead_code)
laruh Feb 12, 2023
831dd5b
change order in Chain enum
laruh Feb 12, 2023
9f4e6c0
fix doc comment
laruh Feb 13, 2023
4311194
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 14, 2023
da2d745
beautify json
laruh Feb 14, 2023
cfb8f37
add from in withdraw requests
laruh Feb 14, 2023
9e51761
String::new(), serde UPPERCASE, pub(crate) SerdeStringWrap,line break
laruh Feb 15, 2023
487d10f
use ok_or_else, remove if cursor is null, remove !nfts_list.is_empty()
laruh Feb 15, 2023
92bed1d
derive order, simplify match protocol
laruh Feb 15, 2023
981ac94
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 15, 2023
c649bf8
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 15, 2023
fbc8af0
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 15, 2023
1b3a6fa
replace Chain::Bnb with Chain::Bsc
laruh Feb 17, 2023
b92ec80
change status code matching, add derive Copy
laruh Feb 17, 2023
a8403e4
fn withdraw_erc721
laruh Feb 20, 2023
5cbf0fd
move nft from eth to coin crate
laruh Feb 20, 2023
bc5d59d
remove memo
laruh Feb 20, 2023
0253dcf
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 21, 2023
4edc948
wip
laruh Feb 21, 2023
e5d2109
add fn coins_conf_check
laruh Feb 21, 2023
399b85e
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 22, 2023
d576053
add from_stringify
laruh Feb 22, 2023
16cfdcc
add feature enable-nft-integration, fix coins_conf_check
laruh Feb 22, 2023
09223fa
add doc comment for withdraw_nft
laruh Feb 22, 2023
1cedc3b
fix coins_conf_check
laruh Feb 22, 2023
1cd530a
fix deref which would be done by auto-deref
laruh Feb 22, 2023
4b1f93a
Merge remote-tracking branch 'origin/dev' into NFT-integration-poc
laruh Feb 25, 2023
10ce258
fix conflicts, add feature log file
laruh Feb 25, 2023
114ad32
fix wasm
laruh Feb 25, 2023
a260ff0
find_wallet_amount, withdraw_erc1155
laruh Mar 3, 2023
5d60912
add Avalanche, Fantom, Polygon chains
laruh Mar 5, 2023
2bc8cf6
simplify code
laruh Mar 5, 2023
e57eda9
amount_dec in tx details
laruh Mar 5, 2023
f6b3df8
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 7, 2023
eb41afb
add get_eth_nft_gas_details
laruh Mar 7, 2023
b188d87
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 8, 2023
afe09e8
add derive Clone, PartialEq
laruh Mar 8, 2023
2344ebb
doc comments
laruh Mar 8, 2023
4e7a5cc
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 9, 2023
e48ef94
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 9, 2023
79549f1
fix merge conflict
laruh Mar 9, 2023
aac0c4b
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 13, 2023
f48cdaa
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 15, 2023
b6b26d6
TokenNotFoundInWallet
laruh Mar 15, 2023
e70c8c0
use eth_coin.my_address()?
laruh Mar 15, 2023
ef3fc73
add entry in the changelog file
laruh Mar 15, 2023
2187f95
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 16, 2023
fa8987e
use get_eth_gas_details for nft and fungible tokens
laruh Mar 16, 2023
e9245ce
remove redundant attributes, count field, add type GasDetails, add it…
laruh Mar 17, 2023
5cce557
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 17, 2023
3f5ae06
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 21, 2023
11eca9e
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 22, 2023
9963fe1
fix merge conflicts
laruh Mar 22, 2023
72a7846
get_valid_nft_add_to_withdraw, use just bool for max
laruh Mar 22, 2023
9a8f33d
polish eth_value_for_estimate
laruh Mar 23, 2023
06657f0
remove nft: bool
laruh Mar 23, 2023
8245784
add line spaces, add bold text
laruh Mar 23, 2023
c120952
Merge remote-tracking branch 'origin/dev' into NFT-integration-withdr…
laruh Mar 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**Features:**
- NFT integration `WIP` [#900](https://github.com/KomodoPlatform/atomicDEX-API/issues/900)
- NFT integration PoC added. Includes ERC721 support for ETH and BSC [#1652](https://github.com/KomodoPlatform/atomicDEX-API/pull/1652)
- Withdraw ERC1155 and EVM based chains support added for NFT PoC [#1704](https://github.com/KomodoPlatform/atomicDEX-API/pull/1704)
- Swap watcher nodes [#1431](https://github.com/KomodoPlatform/atomicDEX-API/issues/1431)
- Watcher rewards for ETH swaps were added [#1658](https://github.com/KomodoPlatform/atomicDEX-API/pull/1658)
- Cosmos integration `WIP` [#1432](https://github.com/KomodoPlatform/atomicDEX-API/issues/1432)
Expand Down
324 changes: 232 additions & 92 deletions mm2src/coins/eth.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mm2src/coins/eth/v2_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use mm2_err_handle::common_errors::WithInternal;
#[cfg(target_arch = "wasm32")]
use mm2_metamask::{from_metamask_error, MetamaskError, MetamaskRpcError, WithMetamaskRpcError};

#[derive(Debug, Deserialize, Display, EnumFromTrait, Serialize, SerializeErrorType)]
#[derive(Clone, Debug, Deserialize, Display, EnumFromTrait, PartialEq, Serialize, SerializeErrorType)]
#[serde(tag = "error_type", content = "error_data")]
pub enum EthActivationV2Error {
InvalidPayload(String),
Expand Down
71 changes: 64 additions & 7 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ use coin_errors::{MyAddressError, ValidatePaymentError, ValidatePaymentFut};
pub mod coins_tests;

pub mod eth;
use eth::{eth_coin_from_conf_and_request, get_eth_address, EthCoin, EthTxFeeDetails, GetEthAddressError, SignedEthTx};
#[cfg(feature = "enable-nft-integration")]
use eth::GetValidEthWithdrawAddError;
use eth::{eth_coin_from_conf_and_request, get_eth_address, EthCoin, EthGasDetailsErr, EthTxFeeDetails,
GetEthAddressError, SignedEthTx};

pub mod hd_confirm_address;
pub mod hd_pubkey;
Expand Down Expand Up @@ -257,6 +260,8 @@ use utxo::UtxoActivationParams;
use utxo::{BlockchainNetwork, GenerateTxError, UtxoFeeDetails, UtxoTx};

#[cfg(feature = "enable-nft-integration")] pub mod nft;
#[cfg(feature = "enable-nft-integration")]
use nft::nft_errors::GetNftInfoError;

#[cfg(not(target_arch = "wasm32"))] pub mod z_coin;
#[cfg(not(target_arch = "wasm32"))] use z_coin::ZCoin;
Expand Down Expand Up @@ -405,7 +410,7 @@ pub enum TxHistoryError {
InternalError(String),
}

#[derive(Clone, Debug, Display, Deserialize)]
#[derive(Clone, Debug, Deserialize, Display, PartialEq)]
pub enum PrivKeyPolicyNotAllowed {
#[display(fmt = "Hardware Wallet is not supported")]
HardwareWalletNotSupported,
Expand Down Expand Up @@ -1728,7 +1733,7 @@ impl DelegationError {
}
}

#[derive(Clone, Debug, Display, EnumFromStringify, EnumFromTrait, Serialize, SerializeErrorType, PartialEq)]
#[derive(Clone, Debug, Display, EnumFromStringify, EnumFromTrait, PartialEq, Serialize, SerializeErrorType)]
#[serde(tag = "error_type", content = "error_data")]
pub enum WithdrawError {
#[display(
Expand Down Expand Up @@ -1791,14 +1796,38 @@ pub enum WithdrawError {
#[from_stringify("NumConversError", "UnexpectedDerivationMethod", "PrivKeyPolicyNotAllowed")]
#[display(fmt = "Internal error: {}", _0)]
InternalError(String),
#[cfg(feature = "enable-nft-integration")]
#[display(fmt = "{} coin doesn't support NFT withdrawing", coin)]
CoinDoesntSupportNftWithdraw { coin: String },
#[cfg(feature = "enable-nft-integration")]
#[display(fmt = "My address {} and from address {} mismatch", my_address, from)]
AddressMismatchError { my_address: String, from: String },
#[cfg(feature = "enable-nft-integration")]
#[display(fmt = "Contract type {} doesnt support 'withdraw_nft' yet", _0)]
ContractTypeDoesntSupportNftWithdrawing(String),
#[display(fmt = "Action not allowed for coin: {}", _0)]
ActionNotAllowed(String),
#[cfg(feature = "enable-nft-integration")]
GetNftInfoError(GetNftInfoError),
#[cfg(feature = "enable-nft-integration")]
#[display(
fmt = "Not enough NFTs amount with token_address: {} and token_id {}. Available {}, required {}",
token_address,
token_id,
available,
required
)]
NotEnoughNftsAmount {
token_address: String,
token_id: String,
available: BigDecimal,
required: BigDecimal,
},
}

#[cfg(feature = "enable-nft-integration")]
impl From<GetNftInfoError> for WithdrawError {
fn from(e: GetNftInfoError) -> Self { WithdrawError::GetNftInfoError(e) }
}

impl HttpStatusCode for WithdrawError {
Expand All @@ -1818,14 +1847,17 @@ impl HttpStatusCode for WithdrawError {
| WithdrawError::UnexpectedFromAddress(_)
| WithdrawError::UnknownAccount { .. }
| WithdrawError::UnexpectedUserAction { .. }
| WithdrawError::CoinDoesntSupportNftWithdraw { .. }
| WithdrawError::AddressMismatchError { .. }
| WithdrawError::ActionNotAllowed(_)
| WithdrawError::ContractTypeDoesntSupportNftWithdrawing(_) => StatusCode::BAD_REQUEST,
| WithdrawError::ActionNotAllowed(_) => StatusCode::BAD_REQUEST,
WithdrawError::HwError(_) => StatusCode::GONE,
#[cfg(target_arch = "wasm32")]
WithdrawError::BroadcastExpected(_) => StatusCode::BAD_REQUEST,
WithdrawError::Transport(_) | WithdrawError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
#[cfg(feature = "enable-nft-integration")]
WithdrawError::GetNftInfoError(_)
| WithdrawError::AddressMismatchError { .. }
| WithdrawError::ContractTypeDoesntSupportNftWithdrawing(_)
| WithdrawError::CoinDoesntSupportNftWithdraw { .. }
| WithdrawError::NotEnoughNftsAmount { .. } => StatusCode::BAD_REQUEST,
}
}
}
Expand Down Expand Up @@ -1860,6 +1892,31 @@ impl From<TimeoutError> for WithdrawError {
fn from(e: TimeoutError) -> Self { WithdrawError::Timeout(e.duration) }
}

#[cfg(feature = "enable-nft-integration")]
impl From<GetValidEthWithdrawAddError> for WithdrawError {
fn from(e: GetValidEthWithdrawAddError) -> Self {
match e {
GetValidEthWithdrawAddError::AddressMismatchError { my_address, from } => {
WithdrawError::AddressMismatchError { my_address, from }
},
GetValidEthWithdrawAddError::CoinDoesntSupportNftWithdraw { coin } => {
WithdrawError::CoinDoesntSupportNftWithdraw { coin }
},
GetValidEthWithdrawAddError::InvalidAddress(e) => WithdrawError::InvalidAddress(e),
}
}
}

impl From<EthGasDetailsErr> for WithdrawError {
fn from(e: EthGasDetailsErr) -> Self {
match e {
EthGasDetailsErr::InvalidFeePolicy(e) => WithdrawError::InvalidFeePolicy(e),
EthGasDetailsErr::Internal(e) => WithdrawError::InternalError(e),
EthGasDetailsErr::Transport(e) => WithdrawError::Transport(e),
}
}
}

impl WithdrawError {
/// Construct [`WithdrawError`] from [`GenerateTxError`] using additional `coin` and `decimals`.
pub fn from_generate_tx_error(gen_tx_err: GenerateTxError, coin: String, decimals: u8) -> WithdrawError {
Expand Down
58 changes: 39 additions & 19 deletions mm2src/coins/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ pub(crate) mod nft_structs;

use crate::WithdrawError;
use nft_errors::GetNftInfoError;
use nft_structs::{Chain, Nft, NftList, NftListReq, NftMetadataReq, NftTransferHistory, NftTransferHistoryWrapper,
NftTransfersReq, NftWrapper, NftsTransferHistoryList, TransactionNftDetails, WithdrawNftReq};
use nft_structs::{Chain, ConvertChain, Nft, NftList, NftListReq, NftMetadataReq, NftTransferHistory,
NftTransferHistoryWrapper, NftTransfersReq, NftWrapper, NftsTransferHistoryList,
TransactionNftDetails, WithdrawNftReq};

use crate::eth::{get_eth_address, withdraw_erc721};
use crate::eth::{get_eth_address, withdraw_erc1155, withdraw_erc721};
use common::{APPLICATION_JSON, X_API_KEY};
use http::header::ACCEPT;
use mm2_number::BigDecimal;
use serde_json::Value as Json;

/// url for moralis requests
Expand All @@ -23,7 +25,7 @@ const DIRECTION_BOTH_MORALIS: &str = "direction=both";

pub type WithdrawNftResult = Result<TransactionNftDetails, MmError<WithdrawError>>;

/// `get_nft_list` function returns list of NFTs on ETH or/and BNB chains owned by user.
/// `get_nft_list` function returns list of NFTs on requested chains owned by user.
pub async fn get_nft_list(ctx: MmArc, req: NftListReq) -> MmResult<NftList, GetNftInfoError> {
let api_key = ctx.conf["api_key"]
.as_str()
Expand All @@ -32,11 +34,8 @@ pub async fn get_nft_list(ctx: MmArc, req: NftListReq) -> MmResult<NftList, GetN
let mut res_list = Vec::new();

for chain in req.chains {
let (coin_str, chain_str) = match chain {
Chain::Bsc => ("BNB", "bsc"),
Chain::Eth => ("ETH", "eth"),
};
let my_address = get_eth_address(&ctx, coin_str).await?;
let (coin_str, chain_str) = chain.to_ticker_chain();
let my_address = get_eth_address(&ctx, &coin_str).await?;
let uri_without_cursor = format!(
"{}{}/nft?chain={}&{}",
URL_MORALIS, my_address.wallet_address, chain_str, FORMAT_DECIMAL_MORALIS
Expand Down Expand Up @@ -83,24 +82,28 @@ pub async fn get_nft_list(ctx: MmArc, req: NftListReq) -> MmResult<NftList, GetN
}
}
drop_mutability!(res_list);
let nft_list = NftList {
count: res_list.len() as u64,
nfts: res_list,
};
let nft_list = NftList { nfts: res_list };
Ok(nft_list)
}

/// `get_nft_metadata` function returns info of one specific NFT.
/// Current implementation sends request to Moralis.
/// Later, after adding caching, metadata lookup can be performed using previously obtained NFTs info without
/// sending new moralis request. The moralis request can be sent as a fallback, if the data was not found in the cache.
///
/// `Caution`. ERC-1155 token can have a total supply more than 1, which means there could be several owners
shamardy marked this conversation as resolved.
Show resolved Hide resolved
/// of the same token. `get_nft_metadata` returns NFTs info with the most recent owner.
/// **Dont** use this function to get specific info about owner address, amount etc, you will get info not related to my_address.
pub async fn get_nft_metadata(ctx: MmArc, req: NftMetadataReq) -> MmResult<Nft, GetNftInfoError> {
let api_key = ctx.conf["api_key"]
.as_str()
.ok_or_else(|| MmError::new(GetNftInfoError::ApiKeyError))?;
let chain_str = match req.chain {
Chain::Avalanche => "avalanche",
Chain::Bsc => "bsc",
Chain::Eth => "eth",
Chain::Fantom => "fantom",
Chain::Polygon => "polygon",
};
let uri = format!(
"{}nft/{}/{}?chain={}&{}",
Expand Down Expand Up @@ -129,7 +132,7 @@ pub async fn get_nft_metadata(ctx: MmArc, req: NftMetadataReq) -> MmResult<Nft,
Ok(nft_metadata)
}

/// `get_nft_transfers` function returns a transfer history of NFTs on ETH or/and BNb chains owned by user.
/// `get_nft_transfers` function returns a transfer history of NFTs on requested chains owned by user.
/// Currently doesnt support filters.
pub async fn get_nft_transfers(ctx: MmArc, req: NftTransfersReq) -> MmResult<NftsTransferHistoryList, GetNftInfoError> {
let api_key = ctx.conf["api_key"]
Expand All @@ -140,8 +143,11 @@ pub async fn get_nft_transfers(ctx: MmArc, req: NftTransfersReq) -> MmResult<Nft

for chain in req.chains {
let (coin_str, chain_str) = match chain {
Chain::Avalanche => ("AVAX", "avalanche"),
Chain::Bsc => ("BNB", "bsc"),
Chain::Eth => ("ETH", "eth"),
Chain::Fantom => ("FTM", "fantom"),
Chain::Polygon => ("MATIC", "polygon"),
};
let my_address = get_eth_address(&ctx, coin_str).await?;
let uri_without_cursor = format!(
Expand Down Expand Up @@ -192,7 +198,6 @@ pub async fn get_nft_transfers(ctx: MmArc, req: NftTransfersReq) -> MmResult<Nft
}
drop_mutability!(res_list);
let transfer_history_list = NftsTransferHistoryList {
count: res_list.len() as u64,
transfer_history: res_list,
};
Ok(transfer_history_list)
Expand All @@ -201,12 +206,9 @@ pub async fn get_nft_transfers(ctx: MmArc, req: NftTransfersReq) -> MmResult<Nft
/// `withdraw_nft` function generates, signs and returns a transaction that transfers NFT
/// from my address to recipient's address.
/// This method generates a raw transaction which should then be broadcast using `send_raw_transaction`.
/// Currently support ERC721 withdrawing, ERC1155 support will be added later.
pub async fn withdraw_nft(ctx: MmArc, req_type: WithdrawNftReq) -> WithdrawNftResult {
match req_type {
WithdrawNftReq::WithdrawErc1155(_) => MmError::err(WithdrawError::ContractTypeDoesntSupportNftWithdrawing(
"ERC1155".to_owned(),
)),
WithdrawNftReq::WithdrawErc1155(erc1155_req) => withdraw_erc1155(ctx, erc1155_req).await,
WithdrawNftReq::WithdrawErc721(erc721_req) => withdraw_erc721(ctx, erc721_req).await,
}
}
Expand Down Expand Up @@ -265,3 +267,21 @@ async fn send_moralis_request(uri: &str, api_key: &str) -> MmResult<Json, GetNft
let response: Json = try_or!(serde_json::from_str(&response_str), InvalidResponse);
Ok(response)
}

/// This function uses `get_nft_list` method to get the correct info about amount of specific NFT owned by my_address.
pub(crate) async fn find_wallet_amount(
ctx: MmArc,
nft_list: NftListReq,
token_address_req: String,
token_id_req: BigDecimal,
) -> MmResult<BigDecimal, GetNftInfoError> {
let nft_list = get_nft_list(ctx, nft_list).await?.nfts;
let nft = nft_list
.into_iter()
.find(|nft| nft.token_address == token_address_req && nft.token_id == token_id_req)
.ok_or_else(|| GetNftInfoError::TokenNotFoundInWallet {
token_address: token_address_req,
token_id: token_id_req.to_string(),
})?;
Ok(nft.amount)
}
18 changes: 14 additions & 4 deletions mm2src/coins/nft/nft_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mm2_net::transport::SlurpError;
use serde::{Deserialize, Serialize};
use web3::Error;

#[derive(Debug, Deserialize, Display, EnumFromStringify, Serialize, SerializeErrorType)]
#[derive(Clone, Debug, Deserialize, Display, EnumFromStringify, PartialEq, Serialize, SerializeErrorType)]
#[serde(tag = "error_type", content = "error_data")]
pub enum GetNftInfoError {
/// `http::Error` can appear on an HTTP request [`http::Builder::build`] building.
Expand All @@ -24,6 +24,15 @@ pub enum GetNftInfoError {
GetEthAddressError(GetEthAddressError),
#[display(fmt = "X-API-Key is missing")]
ApiKeyError,
#[display(
fmt = "Token: token_address {}, token_id {} was not find in wallet",
token_address,
token_id
)]
TokenNotFoundInWallet {
token_address: String,
token_id: String,
},
}

impl From<SlurpError> for GetNftInfoError {
Expand Down Expand Up @@ -60,9 +69,10 @@ impl HttpStatusCode for GetNftInfoError {
GetNftInfoError::InvalidRequest(_) => StatusCode::BAD_REQUEST,
GetNftInfoError::InvalidResponse(_) => StatusCode::FAILED_DEPENDENCY,
GetNftInfoError::ApiKeyError => StatusCode::FORBIDDEN,
GetNftInfoError::Transport(_) | GetNftInfoError::Internal(_) | GetNftInfoError::GetEthAddressError(_) => {
StatusCode::INTERNAL_SERVER_ERROR
},
GetNftInfoError::Transport(_)
| GetNftInfoError::Internal(_)
| GetNftInfoError::GetEthAddressError(_)
| GetNftInfoError::TokenNotFoundInWallet { .. } => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
Loading