Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Implement getNFT function of NFT module #9034

Merged
merged 5 commits into from
Sep 28, 2023
Merged

Conversation

Incede
Copy link
Contributor

@Incede Incede commented Sep 25, 2023

What was the problem?

This PR resolves #8958 #8959 #8960 and partially resolves #8961

How was it solved?

Implement and update usage as specified

How was it tested?

Added and updated unit tests

@Incede Incede requested a review from bobanm September 25, 2023 08:42
@Incede Incede self-assigned this Sep 25, 2023
@Incede Incede requested review from mjerkov and has5aan and removed request for has5aan September 25, 2023 09:15
@Incede Incede marked this pull request as ready for review September 25, 2023 15:35
@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Merging #9034 (adbfbde) into release/6.1.0 (a251bb3) will decrease coverage by 0.03%.
The diff coverage is 98.78%.

Impacted file tree graph

@@                Coverage Diff                @@
##           release/6.1.0    #9034      +/-   ##
=================================================
- Coverage          84.36%   84.34%   -0.03%     
=================================================
  Files                651      651              
  Lines              24016    23985      -31     
  Branches            3493     3490       -3     
=================================================
- Hits               20261    20230      -31     
  Misses              3755     3755              
Files Coverage Δ
...amework/src/modules/nft/cc_commands/cc_transfer.ts 97.59% <100.00%> (+0.15%) ⬆️
framework/src/modules/nft/commands/transfer.ts 100.00% <100.00%> (ø)
...k/src/modules/nft/commands/transfer_cross_chain.ts 100.00% <100.00%> (+2.56%) ⬆️
framework/src/modules/nft/method.ts 99.10% <100.00%> (-0.08%) ⬇️
framework/src/modules/nft/endpoint.ts 98.16% <80.00%> (-0.90%) ⬇️

Copy link
Contributor

@mjerkov mjerkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I only have one small comment.

framework/src/modules/nft/cc_commands/cc_transfer.ts Outdated Show resolved Hide resolved
@shuse2 shuse2 self-requested a review September 27, 2023 08:35
Comment on lines 61 to 66
owner: Buffer;
attributesArray: NFTAttributes[];
lockingModule?: string;
}

export interface NFTOutputEndpoint {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a duplicated interface with same properties but different types, I think it would be better to follow the pattern which we've been using throughout the codebase:

export type JSONObject<T> = Replaced<T, bigint | Buffer, string>;

export type NFTJSON = JSONObject<NFT>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid point 👍 I updated it

Comment on lines +46 to +50
let nft;
try {
nft = await this._method.getNFT(methodContext, params.nftID);
} catch (error) {
throw new Error('NFT does not exist');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason the code is catching and re-throwing the error from getNFT() method?

getNFT() already throws 2 types of errors, depending on if the entry is missing from NFT store or from User store.

It seems that this try/catch not only complicates the command verification, but also provide less accurate error message than if there was no try/catch here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case (and verify hook of other commands), I think it makes sense to emit more granular error(s). And yes it'll get rid of the try-catch. Since this code will already be replaced by verifyTransfer, I'll apply the suggestion directly in the internal functions in PR #9005 instead of redundant update here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applies to other places, but the error can be false because it's possible to have error with different reason. (ex: DB is dead)
It would be better not to ignore the error received. At least, we should wrap it if we want to have additional message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update in the internal functions in PR #9005 to catch and throw if error is other than expected 👍

@@ -347,12 +310,10 @@ export class NFTMethod extends BaseMethod {
NftEventResult.RESULT_NFT_DOES_NOT_EXIST,
);

throw new Error('NFT substore entry does not exist');
throw new Error('NFT does not exist');
Copy link
Contributor

@bobanm bobanm Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the goal of this try/catch was simply to log the event, then how about simply re-throwing the same error object, instead of creating a new one?

Same for the other instances of this pattern in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errors are following the LIP and make sense for me - the errors inside getNFT are more granular depedning upon which substore entry is missing. Inside higher level functions such as lock it makes sense to encapsualte both into a single generic error instead of 2 different errors.

@Incede Incede requested a review from bobanm September 27, 2023 17:58
Comment on lines +46 to +50
let nft;
try {
nft = await this._method.getNFT(methodContext, params.nftID);
} catch (error) {
throw new Error('NFT does not exist');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applies to other places, but the error can be false because it's possible to have error with different reason. (ex: DB is dead)
It would be better not to ignore the error received. At least, we should wrap it if we want to have additional message

framework/src/modules/nft/cc_commands/cc_transfer.ts Outdated Show resolved Hide resolved
framework/src/modules/nft/method.ts Show resolved Hide resolved
@Incede Incede requested a review from shuse2 September 28, 2023 11:09
@shuse2 shuse2 merged commit 5c689a9 into release/6.1.0 Sep 28, 2023
11 checks passed
@shuse2 shuse2 deleted the 8959-method-getnft branch September 28, 2023 13:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants