-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to download a contract (#209)
* Add command to download a contract from a remote network into our local chain of choice * Process feedback * Add ExpressFindStatesAsync without key decoding and with paging support Add {} around exceptions Rename ExpressOracle * batch command * Resolve null warnings * handle duplicate contracts * process feedback * Update ExpressFindStatesAsync * pass storage pairs as IReadOnlyList instead of as an array * remove EncodedFoundStates * fix LastUsedContractId and relevant logic * - Limit contract download to single node consensus setup - rename DownloadParamsAsync -> DownloadContractStateAsync * check consensus node count before getting express node * get contract state via state service * fix storage persisting if local contract does not yet exist * Improve error message when state service plugin is not installed * Improve error message when contract already exists * Generic collections > object model collections * variable rename + format * simplify GetStateHeightAsync logic * minor fixed + format * reworked PersistContract * fix compile break * don't create empty array via new * reworked PersistContract * throw better exeption on missing contract + disallow native contract download * Remove unused code + touch up * very minor whitespace + cleanup * update changelog Co-authored-by: Harry Pierson <[email protected]> Co-authored-by: Harry <[email protected]>
- Loading branch information
1 parent
53f2d02
commit cdd3a18
Showing
11 changed files
with
441 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using NeoExpress.Node; | ||
|
||
namespace NeoExpress.Commands | ||
{ | ||
partial class ContractCommand | ||
{ | ||
internal enum OverwriteForce | ||
{ | ||
None, | ||
All, | ||
ContractOnly, | ||
StorageOnly | ||
} | ||
|
||
[Command(Name = "download", Description = "Download contract with storage from remote chain into local chain")] | ||
internal class Download | ||
{ | ||
readonly ExpressChainManagerFactory chainManagerFactory; | ||
|
||
public Download(ExpressChainManagerFactory chainManagerFactory) | ||
{ | ||
this.chainManagerFactory = chainManagerFactory; | ||
} | ||
|
||
[Argument(0, Description = "Contract invocation hash")] | ||
[Required] | ||
internal string Contract { get; init; } = string.Empty; | ||
|
||
[Argument(1, Description = "URL of Neo JSON-RPC Node\nSpecify MainNet (default), TestNet or JSON-RPC URL")] | ||
internal string RpcUri { get; } = string.Empty; | ||
|
||
[Option(Description = "Path to neo-express data file")] | ||
internal string Input { get; init; } = string.Empty; | ||
|
||
[Option(Description = "Block height to get contract state for")] | ||
internal uint Height { get; } = 0; | ||
|
||
[Option(CommandOptionType.SingleOrNoValue, | ||
Description = "Replace contract and storage if it already exists (Default: All)")] | ||
[AllowedValues(StringComparison.OrdinalIgnoreCase, "All", "ContractOnly", "StorageOnly")] | ||
internal OverwriteForce Force { get; init; } = OverwriteForce.None; | ||
|
||
internal async Task ExecuteAsync(TextWriter writer) | ||
{ | ||
var (chainManager, _) = chainManagerFactory.LoadChain(Input); | ||
|
||
if (chainManager.Chain.ConsensusNodes.Count != 1) | ||
{ | ||
throw new ArgumentException("Contract download is only supported for single-node consensus"); | ||
} | ||
|
||
var result = await NodeUtility.DownloadContractStateAsync(Contract, RpcUri, Height); | ||
using var expressNode = chainManager.GetExpressNode(); | ||
await expressNode.PersistContractAsync(result.contractState, result.storagePairs, Force); | ||
} | ||
|
||
internal async Task<int> OnExecuteAsync(CommandLineApplication app, IConsole console) | ||
{ | ||
try | ||
{ | ||
await ExecuteAsync(console.Out).ConfigureAwait(false); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
app.WriteException(ex); | ||
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
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
Oops, something went wrong.