feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC#2039
Conversation
| /// `EnumVariantList` is a procedural macro used to generate a method that returns a vector containing all variants of an enum. | ||
| /// This macro is intended for use with simple enums (enums without associated data or complex structures). | ||
| /// | ||
| /// ### USAGE: | ||
| /// | ||
| /// ```rust | ||
| /// use enum_from::EnumVariantList; | ||
| /// | ||
| /// #[derive(EnumVariantList)] | ||
| /// enum Chain { | ||
| /// Avalanche, | ||
| /// Bsc, | ||
| /// Eth, | ||
| /// Fantom, | ||
| /// Polygon, | ||
| /// } | ||
| /// | ||
| ///#[test] | ||
| ///fn test_enum_variant_list() { | ||
| /// let all_chains = Chain::variant_list(); | ||
| /// assert_eq!(all_chains, vec![ | ||
| /// Chain::Avalanche, | ||
| /// Chain::Bsc, | ||
| /// Chain::Eth, | ||
| /// Chain::Fantom, | ||
| /// Chain::Polygon | ||
| /// ]); | ||
| ///} | ||
| /// ``` | ||
| #[proc_macro_derive(EnumVariantList)] | ||
| pub fn enum_variant_list(input: TokenStream) -> TokenStream { | ||
| let input = parse_macro_input!(input as DeriveInput); | ||
| let name = input.ident; | ||
|
|
||
| let variants = match input.data { | ||
| Data::Enum(DataEnum { variants, .. }) => variants, | ||
| Data::Struct(_) => return CompileError::expected_enum(ENUM_VARIANT_LIST_IDENT, "struct").into(), | ||
| Data::Union(_) => return CompileError::expected_enum(ENUM_VARIANT_LIST_IDENT, "union").into(), | ||
| }; | ||
|
|
||
| let variant_list: Vec<_> = variants.iter().map(|v| &v.ident).collect(); | ||
|
|
||
| let expanded = quote! { | ||
| impl #name { | ||
| pub fn variant_list() -> Vec<#name> { | ||
| vec![ #( #name::#variant_list ),* ] | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| TokenStream::from(expanded) | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't think this macro should be In this mod by the way, the intention and name is quite different from what's expected from the mod just unlike the other macros there . maybe another mod or just create a derives mod in coins and move there
There was a problem hiding this comment.
@borngraced yeah, I felt that this macro probably wont fit the lib name.
What do you think about renaming enum_from to enum_utilities so we can just leave enum_variant_list function in lib.rs and reuse all necessary already implemented types (like error) for EnumVariantList and any other future derive macro for enum.
There was a problem hiding this comment.
I did this
derives
│
└── enum_utilities
├── lib.rs
├── from_inner.rs
├── from_stringify.rs
└── from_trait.rs
If we leave enum_from lib name, then we need to add additional lib enum_to which actually could re-utilize implementations or types from enum_from bcz we desire to work with enums. I suggest to keep enum_utilities for different enum macros.
But if you would like to have different names, I will create new lib crate.
There was a problem hiding this comment.
yeah, you can rename for sure if it worth it.. what about enum_derives
cc. @shamardy
There was a problem hiding this comment.
personally, I would lean towards enum_derives as it explicitly suggests that the crate is focused on deriving traits or functionalities for enums. also gives a clear indication of the crate's purpose.
There was a problem hiding this comment.
yep, enum_derives is definitely a better name, changed it, thanks!
| @@ -148,8 +203,8 @@ impl fmt::Display for MacroAttr { | |||
| struct CompileError(String); | |||
|
|
|||
| impl CompileError { | |||
There was a problem hiding this comment.
you can make CompileError public if you like to use externally.
… statement, use if/else
| pub fn new(table_name: &str) -> SqlResult<Self> { | ||
| validate_table_name(table_name)?; | ||
| Ok(SafeTableName(table_name.to_owned())) | ||
| } |
There was a problem hiding this comment.
Currently we can create SafeTableName without this function and read it with 'instance.0' . Maybe remove "pub" from the inner value to enforce using this function, then create another function for reading it?
There was a problem hiding this comment.
Good point! made inner value private and impl get_name function SafeTableName
mm2src/coins/nft/nft_errors.rs
Outdated
| /// Variants: | ||
| /// - `DbError`: Represents errors related to database operations. | ||
| /// - `Internal`: Indicates internal errors not directly associated with database operations. | ||
| /// - `InvalidRequest`: Used for various types of invalid requests, such as missing or contradictory parameters. |
There was a problem hiding this comment.
This isn't a good approach for documenting rust code. You should add the field-related docs on the fields directly.
There was a problem hiding this comment.
I see, thanks for the note! I changed as many doc comments as I've noticed. If I see more, I will fix them.
mm2src/coins/nft/nft_structs.rs
Outdated
| /// 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. |
There was a problem hiding this comment.
Same here (there are other spots too but I don't want to ping them all)
shamardy
left a comment
There was a problem hiding this comment.
LGTM! Some minor non-blockers!
|
@KomodoPlatform/qa Since there are a lot of open PRs, this can be tested in dev. @laruh In addition to this #2039 (comment) you can add example request/responses for the QA team here or in the related issues #900, #1902 |
* evm-hd-wallet: (27 commits) Fix todo comments Fix HDAddressOps::Address trait bounds fix(indexeddb): fix IDB cursor.continue_() call after drop (GLEECBTC#2028) security bump for `h2` (GLEECBTC#2062) fix(makerbot): allow more than one prices url in makerbot (GLEECBTC#2027) fix(wasm worker env): refactor direct usage of `window` (GLEECBTC#1953) feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (GLEECBTC#2039) refactor(utxo): refactor utxo output script creation (GLEECBTC#1960) feat(ETH): balance event streaming for ETH (GLEECBTC#2041) chore(release): bump mm2 version to 2.1.0-beta (GLEECBTC#2044) feat(trezor): add segwit support for withdraw with trezor (GLEECBTC#1984) chore(config): remove vscode launchjson (GLEECBTC#2040) feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (GLEECBTC#2015) feat(UTXO): balance event streaming for Electrum clients (GLEECBTC#2013) feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (GLEECBTC#1930) fix(p2p): handle encode_and_sign errors (GLEECBTC#2038) chore(release): add changelog entries for v2.0.0-beta (GLEECBTC#2037) chore(network): write network information to stdout (GLEECBTC#2034) fix(price_endpoints): add cached url (GLEECBTC#2032) deps(network): sync with upstream yamux (GLEECBTC#2030) ...
* dev: feat(zcoin): ARRR WASM implementation (GLEECBTC#1957) feat(trading-proto-upgrade): locked amounts, kmd burn and other impl (GLEECBTC#2046) fix(indexeddb): set stop on success cursor condition (GLEECBTC#2067) feat(config): add `max_concurrent_connections` to mm2 config (GLEECBTC#2063) feat(stats_swaps): add gui/mm_version in stats db (GLEECBTC#2061) fix(indexeddb): fix IDB cursor.continue_() call after drop (GLEECBTC#2028) security bump for `h2` (GLEECBTC#2062) fix(makerbot): allow more than one prices url in makerbot (GLEECBTC#2027) fix(wasm worker env): refactor direct usage of `window` (GLEECBTC#1953) feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (GLEECBTC#2039) refactor(utxo): refactor utxo output script creation (GLEECBTC#1960) feat(ETH): balance event streaming for ETH (GLEECBTC#2041) chore(release): bump mm2 version to 2.1.0-beta (GLEECBTC#2044) feat(trezor): add segwit support for withdraw with trezor (GLEECBTC#1984)
This PR introduces two new functions,
erc1155_balanceanderc721_owner, to theEthCoinstructure.These enhancements streamline the NFT withdrawal process in the
withdraw_nftRPC by directly interacting with smart contracts for validation, eliminating the need to access database information.Key Features and Benefits:
Direct Balance Check for ERC1155: The
erc1155_balancefunction allows us to verify the current balance of ERC1155 tokens owned by a user by querying the smart contract directly.Ownership Validation for ERC721: With
erc721_owner, we can now confirm whether a user is the rightful owner of an ERC721 token at the time of the withdrawal request.Prevent Invalid Withdrawal Requests: This update crucially enables the system to reject withdrawal requests if the user attempts to transfer an NFT using an RPC method that is incompatible with the NFT's contract type (such as using
withdraw_erc1155for an ERC721 token, and vice versa).Technical Notes:
ownerOffunction, unlike ERC1155.balanceOffunction, they require different parameters (ERC721's balanceOf, ERC1155's balanceOf).New
clear_nft_dbRPC for NFT data management was added.This new method allows users to selectively clear NFT data for specified blockchain networks, or to completely wipe it across all supported chains.
Key Features:
clear_allflag set totrue, the RPC clears NFT data from all chains. In this casechainsparameter will be ignored.clear_allisfalseand no specificchainsare provided, then the mm error occurs"Nothing to clear was specified".