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

Add method: transfernft & show nft #304

Merged
merged 16 commits into from
Nov 9, 2023
Merged

Conversation

chenzhitong
Copy link
Member

@chenzhitong chenzhitong commented Nov 7, 2023

close #193

transfernft

Usage: neoxp transfernft [options] <Contract> <TokenId> <Sender> <Receiver>

Arguments:
  Contract                  NFT Contract (symbol or script hash)
  TokenId                   TokenId of NFT (Base64 string)
  Sender                    Account to send NFT from
  Receiver                  Account to send NFT to

Options:
  -d|--data <DATA>          Optional data parameter to pass to transfer operation
  -p|--password <PASSWORD>  password to use for NEP-2/NEP-6 sender
  -i|--input <INPUT>        Path to neo-express data file
  -t|--trace                Enable contract execution tracing
  -j|--json                 Output as JSON
  -?|-h|--help              Show help information.
image

show nft

Usage: neoxp show nft [options] <Contract> <Account>

Arguments:
  Contract            Contract to show NFT of (symbol or script hash)
  Account             Account to show asset balance for

Options:
  -i|--input <INPUT>  Path to neo-express data file
  -?|-h|--help        Show help information.
image

var (chainManager, _) = chainManagerFactory.LoadChain(Input);
var password = chainManager.Chain.ResolvePassword(Sender, Password);
using var txExec = txExecutorFactory.Create(chainManager, Trace, Json);
await txExec.TransferNFTAsync(Contract, Encoding.UTF8.GetString(Convert.FromBase64String(TokenId)), Sender, password, Receiver, Data).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

TokenId Should be in hex. This is the way it is done in production. Will be easier to understand.

internal string Data { get; init; } = string.Empty;

[Option(Description = "password to use for NEP-2/NEP-6 sender")]
internal string Password { get; init; } = string.Empty;
Copy link
Member

Choose a reason for hiding this comment

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

NEP-17 transfers dont require password. Seeing how there is default.neo-express file that holds it.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is copied from TransferCommand.cs and is the same as NEP-17.

Copy link
Member

Choose a reason for hiding this comment

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

yes but for password to use for NEP-2/NEP-6 sender for legacy i believe.

Copy link
Member

Choose a reason for hiding this comment

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

Also keep in mind for batch it doesn't require password for transfers. That's what i was thinking of.

<ItemGroup>
<PackageReference Update="Neo.BlockchainToolkit.Library" Version="3.6.19" />
</ItemGroup>

Copy link
Member

@cschuchardt88 cschuchardt88 Nov 7, 2023

Choose a reason for hiding this comment

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

3.6.19 doesn't exists anymore its 3.6.0 now. But we have updated repo with lots of changes please merge before adding this. If still needed then keep it.

"commandLineArgs": "run"
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please dont merge your launchSettings.json.

Copy link
Member

@cschuchardt88 cschuchardt88 left a comment

Choose a reason for hiding this comment

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

Dont forget to run dotnet format and your analyzers to fix github actions.

Edit:
https://github.com/cschuchardt88/neo-construct/blob/master/src/NeoEvents.Construct/Node/Tokens/Nep11Token.cs is good resource for adding the methods for NEP-11, But i dont remember the proper way to invoke the VM in neo-express.

}
else
{
return Encoding.UTF8.GetString(hex[2..].HexToBytes().Reverse().ToArray());
Copy link
Member

Choose a reason for hiding this comment

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

Convert.FromHexString or Convert.ToHexString is good too.

@cschuchardt88
Copy link
Member

since you are working on #193 can you also checkout and think adding NEP-11 for #194

@chenzhitong chenzhitong changed the title Add method transfernft Add method: transfernft & show nft Nov 8, 2023
@chenzhitong chenzhitong marked this pull request as ready for review November 8, 2023 08:02
@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 9, 2023

}
catch (Exception)
{
throw new Exception("invalid script results");
Copy link
Member

Choose a reason for hiding this comment

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

Can we get a better error output? Something indicating that the contract isn't an NFT or missing a method

@chenzhitong
Copy link
Member Author

You have forgotten about Divisible vs Non-Divisible NFTs

Please see https://github.com/neo-project/proposals/blob/master/nep-11.mediawiki#user-content-transfer-2

.vs https://github.com/neo-project/proposals/blob/master/nep-11.mediawiki#user-content-transfer

Template for neo-devpack-dotnet only has base class for Non-divisible NFT, so, I think just supporting Non-divisible NFT is enough.

BTW, does any wallet support Divisible NFT now?

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 9, 2023

BTW, does any wallet support Divisible NFT now?

image
I believe NeoLine. That what the Number 1 is for? But I don't think we should limit it.

Template for neo-devpack-dotnet only has base class for Non-divisible NFT, so, I think just supporting Non-divisible NFT is enough.

Once we add the validator for NEP-11 this won't be a problem. That is because in neo-devpack-dotnet if you want divisible you just have to add these functions transfer ownerOf and balanceOf. Also seeing how the class is abstract the non-divisible ones won't be on the interface.

@chenzhitong
Copy link
Member Author

image
This count is to the number of NFTs held in the same contract
When you click on it, you will see the details

image

@chenzhitong
Copy link
Member Author

Who can review it

@Jim8y
Copy link
Contributor

Jim8y commented Nov 9, 2023

Lacks unit test, all i can do is merge when you think its good to go. If you think it is good to go, i can merge it for you

@chenzhitong
Copy link
Member Author

I've tested it. Merge it please. @Liaojinghui

@Jim8y Jim8y merged commit e65d7c4 into neo-project:master Nov 9, 2023
@Jim8y
Copy link
Contributor

Jim8y commented Nov 9, 2023

@chenzhitong @cschuchardt88 @Ashuaidehao Can you add unit test to this repo? I remember that @cschuchardt88 you wanted to add something that contains the unit test to this repo, right? I think we can just make things easy.

@cschuchardt88
Copy link
Member

@chenzhitong @cschuchardt88 @Ashuaidehao Can you add unit test to this repo? I remember that @cschuchardt88 you wanted to add something that contains the unit test to this repo, right? I think we can just make things easy.

I wanted to add neo-blockchaintoolkit-library to this repo that's where all the unit tests are for core functionally.

@chenzhitong
can you make sure you put file header in *.cs files please.

In Visual Studio set it up like this
image

Than you can run like so if needed:
image

@cschuchardt88 cschuchardt88 mentioned this pull request Nov 15, 2023
22 tasks
@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 15, 2023

@chenzhitong can you reopen and fix?

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 15, 2023

  • Add TokenIds as base64 as well
  • Fix error output to show inter error
  • Make wording say [Argument(1, Description = "TokenId of NFT (Format: HEX, BASE64)")]
  • Make wording say [Argument(0, Description = "NFT Contract (Symbol or Script Hash)")]
  • Add transfernft command to batch commands
  • Allow contract names

Try not to use Regex makes it hard to quickly understand; unless it a very lengthy task to validate. Why you use Reverse when you have 0x?

Fix show nft

C:\Users\edged\Code\sott>neoxp batch run.batch
Transfer Transaction 0xa9096bc8e3d24a8bf264bc8801bf3601c6e8040a3bf1a63e21b4e9d498945926 submitted
Deployment of sword (0x8b49d75870e876b610b430e3db108d487d545dd1) Transaction 0x4a67944d49fb6ae9bf7667c5419495188de2bad98f032ead24fca3adb5013c8c submitted
Invocation Transaction 0x6750b0223adc16659fb6436e5755604ad71b27fe8c30664e372e6316fda0a36b submitted
Invocation Transaction 0x7493007e207525bd5e93154c758284ea334eee377436be2485e3933e495aa19a submitted

C:\Users\edged\Code\sott>neoxp show nft -h
Show NFT Tokens for account

Usage: neoxp show nft [options] <Contract> <Account>

Arguments:
  Contract            Contract to show NFT of (symbol or script hash)
  Account             Account to show asset balance for

Options:
  -i|--input <INPUT>  Path to neo-express data file
  -?|-h|--help        Show help information.


C:\Users\edged\Code\sott>
C:\Users\edged\Code\sott>neoxp show nft SOTT bob
System.ArgumentException: Unknown Asset "SOTT" (Parameter 'asset')

C:\Users\edged\Code\sott>neoxp show nft sword bob
System.ArgumentException: Unknown Asset "sword" (Parameter 'asset')

C:\Users\edged\Code\sott>neoxp show nft 0x8b49d75870e876b610b430e3db108d487d545dd1 bob
System.Exception: invalid script results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add commands for managing NEP11 tokens
3 participants