-
Notifications
You must be signed in to change notification settings - Fork 106
feat: add core Neo smart contract deployment framework #1351
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
Open
Jim8y
wants to merge
24
commits into
dev
Choose a base branch
from
pr1-core-deployment-framework
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6375fe6
SafeAttribute supports in properties (#1330)
erikzhang bd9f1e1
feat: add core Neo smart contract deployment framework
Jim8y e40f22b
fix: resolve code formatting issues and remove duplicate package refe…
Jim8y ef94799
chore: update neo submodule to latest commit
Jim8y bcae4a1
fix: address PR review comments
Jim8y 9e3ef8d
fix: resolve code formatting issues
Jim8y f9bdb8e
test: add comprehensive unit tests for network magic retrieval
Jim8y b250af7
chore: update testnet RPC URL to Neo NGD endpoint
Jim8y 7ae2d02
fix: correct NGD testnet RPC URL
Jim8y 877d6ef
chore: update testnet RPC URL to Neo seed node
Jim8y eca436b
docs: add PR #1 test summary
Jim8y 992f18e
fix: resolve code formatting issues in test files
Jim8y 2f2f1ab
Update src/Neo.SmartContract.Deploy/Shared/ScriptBuilderHelper.cs
Jim8y de026c3
Update src/Neo.SmartContract.Deploy/Shared/ScriptBuilderHelper.cs
Jim8y 12def91
Update src/Neo.SmartContract.Deploy/Shared/ScriptBuilderHelper.cs
Jim8y 630a3a3
Update src/Neo.SmartContract.Deploy/Shared/ScriptBuilderHelper.cs
Jim8y ce8ccdd
Update src/Neo.SmartContract.Deploy/Shared/ScriptBuilderHelper.cs
Jim8y cb776b7
Update src/Neo.SmartContract.Deploy/Shared/ScriptBuilderHelper.cs
Jim8y da96daf
Update tests/Neo.SmartContract.Deploy.UnitTests/RpcIntegrationTests.cs
Jim8y 92cbba3
feat(deploy): implement minimal artifact deployment + calls; trim sca…
Jim8y 3e74910
Merge dev: update neo submodule to 8afce406; resolve conflicts in exa…
Jim8y 18daa75
feat(deploy): add configurable toolkit with compilation and manifest …
Jim8y 1dfe05d
chore: switch mainnet rpc default to coz endpoint
Jim8y 8d46f2e
Merge branch 'dev' into pr1-core-deployment-framework
ajara87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
21 changes: 21 additions & 0 deletions
21
examples/DeploymentArtifactsDemo/DeploymentArtifactsDemo.csproj
This file contains hidden or 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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<DisableExamplesPreBuild>true</DisableExamplesPreBuild> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- Remove references inherited from examples/Directory.Build.props that are only for contract projects --> | ||
<ProjectReference Remove="..\..\src\Neo.Compiler.CSharp\Neo.Compiler.CSharp.csproj" /> | ||
<ProjectReference Remove="..\..\src\Neo.SmartContract.Analyzer\Neo.SmartContract.Analyzer.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Neo.SmartContract.Deploy\Neo.SmartContract.Deploy.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or 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,104 @@ | ||
using Neo.SmartContract.Deploy; | ||
using System.Text.Json; | ||
|
||
static void PrintUsage() | ||
{ | ||
Console.WriteLine("Usage:"); | ||
Console.WriteLine(" dotnet run -- --network <mainnet|testnet|http(s)://rpc> --wif <WIF> --nef <path> --manifest <path> [--wait]"); | ||
Console.WriteLine(" dotnet run -- --network <...> --call --contract <hash|address> --method <name> [--args '[\"arg1\",123,true]']"); | ||
Console.WriteLine(); | ||
Console.WriteLine("Examples:"); | ||
Console.WriteLine(" dotnet run -- --network testnet --wif Kx... --nef My.nef --manifest My.manifest.json --wait"); | ||
Console.WriteLine(" dotnet run -- --network testnet --call --contract 0x... --method symbol"); | ||
} | ||
|
||
string? GetArg(string key) | ||
{ | ||
for (int i = 0; i < args.Length - 1; i++) | ||
if (string.Equals(args[i], key, StringComparison.OrdinalIgnoreCase)) | ||
return args[i + 1]; | ||
return null; | ||
} | ||
|
||
bool HasFlag(string key) => args.Any(a => string.Equals(a, key, StringComparison.OrdinalIgnoreCase)); | ||
|
||
if (args.Length == 0 || HasFlag("--help") || HasFlag("-h")) | ||
{ | ||
PrintUsage(); | ||
return; | ||
} | ||
|
||
var network = GetArg("--network") ?? Environment.GetEnvironmentVariable("NEO_RPC_URL") ?? "testnet"; | ||
var wif = GetArg("--wif") ?? Environment.GetEnvironmentVariable("NEO_WIF"); | ||
var nef = GetArg("--nef"); | ||
var manifest = GetArg("--manifest"); | ||
var wait = HasFlag("--wait"); | ||
|
||
var doCall = HasFlag("--call"); | ||
var contract = GetArg("--contract"); | ||
var method = GetArg("--method"); | ||
var argsJson = GetArg("--args"); | ||
|
||
var toolkit = new DeploymentToolkit().SetNetwork(network); | ||
|
||
try | ||
{ | ||
if (!doCall) | ||
{ | ||
if (string.IsNullOrWhiteSpace(wif) || string.IsNullOrWhiteSpace(nef) || string.IsNullOrWhiteSpace(manifest)) | ||
{ | ||
Console.Error.WriteLine("Missing required parameters for deployment.\n"); | ||
PrintUsage(); | ||
return; | ||
} | ||
|
||
toolkit.SetWifKey(wif); | ||
var initParams = Array.Empty<object>(); | ||
var result = await toolkit.DeployArtifactsAsync(nef, manifest, initParams, waitForConfirmation: wait); | ||
Console.WriteLine($"Transaction Hash: {result.TransactionHash}"); | ||
Console.WriteLine($"Expected Contract Hash: {result.ContractHash}"); | ||
} | ||
else | ||
{ | ||
if (string.IsNullOrWhiteSpace(contract) || string.IsNullOrWhiteSpace(method)) | ||
{ | ||
Console.Error.WriteLine("Missing required parameters for call.\n"); | ||
PrintUsage(); | ||
return; | ||
} | ||
|
||
object[] callArgs = Array.Empty<object>(); | ||
if (!string.IsNullOrWhiteSpace(argsJson)) | ||
{ | ||
try | ||
{ | ||
var doc = JsonDocument.Parse(argsJson); | ||
if (doc.RootElement.ValueKind == JsonValueKind.Array) | ||
{ | ||
callArgs = doc.RootElement.EnumerateArray().Select(el => el.ValueKind switch | ||
{ | ||
JsonValueKind.String => (object)el.GetString()!, | ||
JsonValueKind.Number => el.TryGetInt64(out var l) ? (object)l : el.GetDouble(), | ||
JsonValueKind.True => true, | ||
JsonValueKind.False => false, | ||
_ => el.ToString() | ||
}).ToArray(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.Error.WriteLine($"Failed to parse --args JSON: {ex.Message}"); | ||
return; | ||
} | ||
} | ||
|
||
var value = await toolkit.CallAsync<string>(contract, method, callArgs); | ||
Console.WriteLine($"Result: {value}"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.Error.WriteLine($"Error: {ex.Message}"); | ||
Environment.ExitCode = 1; | ||
} | ||
|
This file contains hidden or 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
40 changes: 40 additions & 0 deletions
40
src/Neo.SmartContract.Deploy/DeploymentArtifactsRequest.cs
This file contains hidden or 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,40 @@ | ||
using System; | ||
|
||
namespace Neo.SmartContract.Deploy; | ||
|
||
public sealed record DeploymentArtifactsRequest | ||
{ | ||
public DeploymentArtifactsRequest( | ||
string nefPath, | ||
string manifestPath, | ||
object?[]? initializationParameters = null) | ||
{ | ||
NefPath = nefPath ?? throw new ArgumentNullException(nameof(nefPath)); | ||
ManifestPath = manifestPath ?? throw new ArgumentNullException(nameof(manifestPath)); | ||
InitParams = initializationParameters ?? Array.Empty<object?>(); | ||
} | ||
|
||
public string NefPath { get; init; } | ||
|
||
public string ManifestPath { get; init; } | ||
|
||
public object?[] InitParams { get; init; } | ||
|
||
public bool? WaitForConfirmation { get; init; } | ||
|
||
public int? ConfirmationRetries { get; init; } | ||
|
||
public int? ConfirmationDelaySeconds { get; init; } | ||
|
||
public DeploymentArtifactsRequest WithInitParams(params object?[] parameters) | ||
=> this with { InitParams = parameters ?? Array.Empty<object?>() }; | ||
|
||
public DeploymentArtifactsRequest WithConfirmationPolicy(bool? waitForConfirmation, int? retries = null, int? delaySeconds = null) | ||
=> this with | ||
{ | ||
WaitForConfirmation = waitForConfirmation, | ||
ConfirmationRetries = retries, | ||
ConfirmationDelaySeconds = delaySeconds | ||
}; | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.