Пример #1
0
        public async Task ContractDeployAsync(string contract, string accountName, string password, WitnessScope witnessScope, bool force)
        {
            if (!TryGetSigningAccount(accountName, password, out var wallet, out var accountHash))
            {
                throw new Exception($"{accountName} account not found.");
            }

            var(nefFile, manifest) = await fileSystem.LoadContractAsync(contract).ConfigureAwait(false);

            if (!force)
            {
                var contracts = await expressNode.ListContractsAsync(manifest.Name).ConfigureAwait(false);

                if (contracts.Count > 0)
                {
                    throw new Exception($"Contract named {manifest.Name} already deployed. Use --force to deploy contract with conflicting name.");
                }
            }

            var txHash = await expressNode.DeployAsync(nefFile, manifest, wallet, accountHash, witnessScope).ConfigureAwait(false);

            await writer.WriteTxHashAsync(txHash, "Deployment", json).ConfigureAwait(false);
        }
Пример #2
0
        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 !;
Пример #3
0
        public async Task ContractDeployAsync(string contract, string accountName, string password, WitnessScope witnessScope, string data, bool force)
        {
            if (!chainManager.TryGetSigningAccount(accountName, password, out var wallet, out var accountHash))
            {
                throw new Exception($"{accountName} account not found.");
            }

            var(nefFile, manifest) = await fileSystem.LoadContractAsync(contract).ConfigureAwait(false);

            if (!force)
            {
                var contracts = await expressNode.ListContractsAsync(manifest.Name).ConfigureAwait(false);

                if (contracts.Count > 0)
                {
                    throw new Exception($"Contract named {manifest.Name} already deployed. Use --force to deploy contract with conflicting name.");
                }

                var nep11 = false; var nep17 = false;
                var standards = manifest.SupportedStandards;
                for (var i = 0; i < standards.Length; i++)
                {
                    if (standards[i] == "NEP-11")
                    {
                        nep11 = true;
                    }
                    if (standards[i] == "NEP-17")
                    {
                        nep17 = true;
                    }
                }
                if (nep11 && nep17)
                {
                    throw new Exception($"{manifest.Name} Contract declares support for both NEP-11 and NEP-17 standards. Use --force to deploy contract with invalid supported standards declarations.");
                }
            }

            ContractParameter dataParam;

            if (string.IsNullOrEmpty(data))
            {
                dataParam = new ContractParameter(ContractParameterType.Any);
            }
            else
            {
                var parser = await expressNode.GetContractParameterParserAsync(chainManager.Chain).ConfigureAwait(false);

                dataParam = parser.ParseParameter(data);
            }

            var txHash = await expressNode
                         .DeployAsync(nefFile, manifest, wallet, accountHash, witnessScope, dataParam)
                         .ConfigureAwait(false);


            var contractHash = Neo.SmartContract.Helper.GetContractHash(accountHash, nefFile.CheckSum, manifest.Name);

            if (json)
            {
                using var jsonWriter = new JsonTextWriter(writer)
                      {
                          Formatting = Formatting.Indented
                      };
                await jsonWriter.WriteStartObjectAsync().ConfigureAwait(false);

                await jsonWriter.WritePropertyNameAsync("contract-name").ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(manifest.Name).ConfigureAwait(false);

                await jsonWriter.WritePropertyNameAsync("contract-hash").ConfigureAwait(false);

                await jsonWriter.WriteValueAsync($"{contractHash}").ConfigureAwait(false);

                await jsonWriter.WritePropertyNameAsync("tx-hash").ConfigureAwait(false);

                await jsonWriter.WriteValueAsync($"{txHash}").ConfigureAwait(false);

                await jsonWriter.WriteEndObjectAsync().ConfigureAwait(false);
            }
            else
            {
                await writer.WriteLineAsync($"Deployment of {manifest.Name} ({contractHash}) Transaction {txHash} submitted").ConfigureAwait(false);
            }
        }