-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC #2039
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First review iteration:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work! few changes from me
mm2src/derives/enum_from/src/lib.rs
Outdated
/// `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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, you can rename for sure if it worth it.. what about enum_derives
cc. @shamardy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (there are other spots too but I don't want to ping them all)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last review iteration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 (KomodoPlatform#2028) security bump for `h2` (KomodoPlatform#2062) fix(makerbot): allow more than one prices url in makerbot (KomodoPlatform#2027) fix(wasm worker env): refactor direct usage of `window` (KomodoPlatform#1953) feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (KomodoPlatform#2039) refactor(utxo): refactor utxo output script creation (KomodoPlatform#1960) feat(ETH): balance event streaming for ETH (KomodoPlatform#2041) chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044) feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984) chore(config): remove vscode launchjson (KomodoPlatform#2040) feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015) feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013) feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930) fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038) chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037) chore(network): write network information to stdout (KomodoPlatform#2034) fix(price_endpoints): add cached url (KomodoPlatform#2032) deps(network): sync with upstream yamux (KomodoPlatform#2030) ...
* dev: feat(zcoin): ARRR WASM implementation (KomodoPlatform#1957) feat(trading-proto-upgrade): locked amounts, kmd burn and other impl (KomodoPlatform#2046) fix(indexeddb): set stop on success cursor condition (KomodoPlatform#2067) feat(config): add `max_concurrent_connections` to mm2 config (KomodoPlatform#2063) feat(stats_swaps): add gui/mm_version in stats db (KomodoPlatform#2061) fix(indexeddb): fix IDB cursor.continue_() call after drop (KomodoPlatform#2028) security bump for `h2` (KomodoPlatform#2062) fix(makerbot): allow more than one prices url in makerbot (KomodoPlatform#2027) fix(wasm worker env): refactor direct usage of `window` (KomodoPlatform#1953) feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (KomodoPlatform#2039) refactor(utxo): refactor utxo output script creation (KomodoPlatform#1960) feat(ETH): balance event streaming for ETH (KomodoPlatform#2041) chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044) feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984)
This PR introduces two new functions,
erc1155_balance
anderc721_owner
, to theEthCoin
structure.These enhancements streamline the NFT withdrawal process in the
withdraw_nft
RPC 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_balance
function 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_erc1155
for an ERC721 token, and vice versa).Technical Notes:
ownerOf
function, unlike ERC1155.balanceOf
function, they require different parameters (ERC721's balanceOf, ERC1155's balanceOf).New
clear_nft_db
RPC 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_all
flag set totrue
, the RPC clears NFT data from all chains. In this casechains
parameter will be ignored.clear_all
isfalse
and no specificchains
are provided, then the mm error occurs"Nothing to clear was specified"
.