-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added worknet command dynamically * can pass input parameter * removed unused console print * created shell extension abstractions and execute method for the shell extension * can map subcommand to the real extenion command for example map worknet to neo-worknet * -added initial nft transfer command to test out shell extension that can handle transactions Still WIP * fix warnings, still experimenting the code is not up to prod standard * nft transfer seems to be work with 0X hash format, also added owner of * can invoke for result or submit * transfer and onwer of working with passing script directly * refactored the code * code clean up * added NEO extension readme * typo * Addressed review comments * fixed logo reference that broke 'dotnet pack' * remove logo from neonft since it's a sample project --------- Co-authored-by: Weijie Lin <[email protected]>
- Loading branch information
1 parent
6a961c1
commit 92fed18
Showing
14 changed files
with
683 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.IO.Abstractions; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using Neo; | ||
using Neo.VM; | ||
using Neo.VM.Types; | ||
using Newtonsoft.Json; | ||
|
||
namespace NeoNft.Commands | ||
{ | ||
[Command("ownerof", Description = "Transfer a NFT to another address")] | ||
partial class OwnerOfCommand | ||
{ | ||
[Argument(0, Description = "Contract hash of the NFT contract")] | ||
[Required] | ||
internal string Contract { get; init; } = string.Empty; | ||
|
||
[Argument(1, Description = "NFT ID")] | ||
[Required] | ||
internal string Id { get; init; } = string.Empty; | ||
|
||
[Option(Description = "Path to neo data file")] | ||
internal string Input { get; init; } = string.Empty; | ||
|
||
[Option(Description = "Enable contract execution tracing")] | ||
internal bool Trace { get; init; } = false; | ||
|
||
[Option(Description = "Output as JSON")] | ||
internal bool Json { get; init; } = false; | ||
|
||
internal int OnExecute(CommandLineApplication app, IConsole console) | ||
{ | ||
try | ||
{ | ||
UInt160.TryParse(this.Contract, out var contractHash); | ||
var hexString = this.Id; | ||
if (this.Id.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
hexString = hexString.Substring(2); | ||
} | ||
|
||
var idBytes = hexString.HexToBytes(); | ||
var script = contractHash.MakeScript("ownerOf", idBytes); | ||
var payload = new { Script = Convert.ToBase64String(script), Trace = this.Trace, Json = this.Json }; | ||
Console.WriteLine(JsonConvert.SerializeObject(payload)); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
app.Error.Write(ex.Message); | ||
return 1; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.IO.Abstractions; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using Neo; | ||
using Neo.BlockchainToolkit.Models; | ||
using Neo.VM; | ||
using Newtonsoft.Json; | ||
|
||
namespace NeoNft.Commands | ||
{ | ||
[Command("transfer", Description = "Transfer a NFT to another address")] | ||
partial class TransferCommand | ||
{ | ||
[Option(Description = "Path to neo data file")] | ||
internal string Input { get; init; } = string.Empty; | ||
|
||
[Argument(0, Description = "Contract hash of the NFT contract")] | ||
[Required] | ||
internal string Contract { get; init; } = string.Empty; | ||
|
||
[Argument(1, Description = "Address to transfer to")] | ||
[Required] | ||
internal string To { get; init; } = string.Empty; | ||
|
||
[Argument(2, Description = "NFT ID to transfer")] | ||
[Required] | ||
internal string Id { get; init; } = string.Empty; | ||
|
||
[Argument(3, Description = "NFT contract owner account")] | ||
[Required] | ||
internal string Account { get; init; } = string.Empty; | ||
|
||
[Option(Description = "Enable contract execution tracing")] | ||
internal bool Trace { get; init; } = false; | ||
|
||
[Option(Description = "Output as JSON")] | ||
internal bool Json { get; init; } = false; | ||
|
||
|
||
|
||
internal int OnExecute(CommandLineApplication app, IConsole console) | ||
{ | ||
try | ||
{ | ||
UInt160.TryParse(this.Contract, out var contractHash); | ||
UInt160.TryParse(this.To, out var toHash); | ||
var hexString = this.Id; | ||
if (this.Id.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
hexString = hexString.Substring(2); | ||
} | ||
|
||
var idBytes = hexString.HexToBytes(); | ||
var script = contractHash.MakeScript("transfer", toHash, idBytes, string.Empty); | ||
var payload = new { Script = Convert.ToBase64String(script), Account = this.Account, Trace = this.Trace, Json = this.Json }; | ||
Console.WriteLine(JsonConvert.SerializeObject(payload)); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
app.Error.Write(ex.Message); | ||
return 1; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.IO.Abstractions; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NeoNft.Commands; | ||
|
||
namespace NeoNft | ||
{ | ||
[Command("nft")] | ||
[Subcommand(typeof(TransferCommand), typeof(OwnerOfCommand))] | ||
class Program | ||
{ | ||
public static Task<int> Main(string[] args) | ||
{ | ||
var services = new ServiceCollection() | ||
.AddSingleton<IConsole>(PhysicalConsole.Singleton) | ||
.BuildServiceProvider(); | ||
|
||
var app = new CommandLineApplication<Program>(); | ||
app.Conventions | ||
.UseDefaultConventions() | ||
.UseConstructorInjection(services); | ||
return app.ExecuteAsync(args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>neonft</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<PackageId>Neo.Nft</PackageId> | ||
<PackAsTool>true</PackAsTool> | ||
<RootNamespace>NeoNft</RootNamespace> | ||
<PackageIcon /> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="../../neo-logo-72.png" Pack="true" Visible="false" PackagePath=""/> | ||
</ItemGroup> | ||
|
||
<Choose> | ||
<When Condition=" '$(BlockchainToolkitLibraryVersion)' == 'local'"> | ||
<ItemGroup> | ||
<ProjectReference Include="$(BlockchainToolkitLibraryLocalPath)\src\bctklib\bctklib.csproj" /> | ||
</ItemGroup> | ||
</When> | ||
<Otherwise> | ||
<ItemGroup> | ||
<PackageReference Include="Neo.BlockchainToolkit.Library" Version="$(BlockchainToolkitLibraryVersion)" /> | ||
</ItemGroup> | ||
</Otherwise> | ||
</Choose> | ||
|
||
</Project> |
Oops, something went wrong.