Exemple #1
0
        public async Task <(string path, bool online)> CreateCheckpointAsync(IExpressNode expressNode, string checkPointPath, bool force)
        {
            if (chain.ConsensusNodes.Count != 1)
            {
                throw new ArgumentException("Checkpoint create is only supported on single node express instances", nameof(chain));
            }

            checkPointPath = ResolveCheckpointFileName(checkPointPath);
            if (fileSystem.File.Exists(checkPointPath))
            {
                if (force)
                {
                    fileSystem.File.Delete(checkPointPath);
                }
                else
                {
                    throw new Exception("You must specify --force to overwrite an existing file");
                }
            }

            var parentPath = fileSystem.Path.GetDirectoryName(checkPointPath);

            if (!fileSystem.Directory.Exists(parentPath))
            {
                fileSystem.Directory.CreateDirectory(parentPath);
            }

            var online = await expressNode.CreateCheckpointAsync(checkPointPath).ConfigureAwait(false);

            return(checkPointPath, online);
        }
Exemple #2
0
 public TransactionExecutor(IFileSystem fileSystem, ExpressChainManager chainManager, bool trace, bool json, TextWriter writer)
 {
     this.chainManager = chainManager;
     expressNode       = chainManager.GetExpressNode(trace);
     this.fileSystem   = fileSystem;
     this.json         = json;
     this.writer       = writer;
 }
        public static async Task <ContractParameterParser> GetContractParameterParserAsync(this IExpressNode expressNode, ExpressChain?chain = null)
        {
            ContractParameterParser.TryGetUInt160 tryGetAccount = (string name, out UInt160 scriptHash) =>
            {
                var account = chain?.GetAccount(name);
                if (account != null)
                {
                    scriptHash = account.AsUInt160();
                    return(true);
                }

                scriptHash = null !;
                return(false);
            };

            var contracts = await expressNode.ListContractsAsync().ConfigureAwait(false);

            var lookup = contracts.ToDictionary(c => c.manifest.Name, c => c.hash);

            ContractParameterParser.TryGetUInt160 tryGetContract = (string name, out UInt160 scriptHash) =>
            {
                if (lookup.TryGetValue(name, out var value))
                {
                    scriptHash = value;
                    return(true);
                }

                foreach (var kvp in lookup)
                {
                    if (string.Equals(name, kvp.Key, StringComparison.OrdinalIgnoreCase))
                    {
                        scriptHash = kvp.Value;
                        return(true);
                    }
                }

                scriptHash = default !;
 public static Task <ContractParameterParser> GetContractParameterParserAsync(this IExpressNode expressNode, IExpressChainManager chainManager)
 => expressNode.GetContractParameterParserAsync(chainManager.Chain);
        public static async Task <ContractParameterParser> GetContractParameterParserAsync(this IExpressNode expressNode, IExpressChainManager chainManager, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
        {
            ContractParameterParser.TryGetUInt160 tryGetAccount = (string name, out UInt160 scriptHash) =>
            {
                if (chainManager.Chain.TryGetAccountHash(name, out var accountHash, expressNode.ProtocolSettings))
                {
                    scriptHash = accountHash;
                    return(true);
                }

                scriptHash = null !;
                return(false);
            };