Пример #1
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            var oracleName = context.ParseResult.CommandResult.GetArgumentValueOrDefault <string>("name")?.ToLowerInvariant().Trim();

            if (oracleName is null)
            {
                throw new CommandOptionRequiredException("name");
            }
            if (await TryGetOracle(oracleName) is Oracle)
            {
                throw new CommandException("name", "This oracle already exists");
            }
            var key = await Repository.CreatePrivateKey();

            var pubkey = key.PrivateKey.PubKey.ToECPubKey().ToXOnlyPubKey(out _);
            await NameRepository.SetMapping(Scopes.Oracles, oracleName, Encoders.Hex.EncodeData(pubkey.ToBytes()));

            await Repository.AddOracle(pubkey, key.KeyPath);

            context.Console.Out.Write(Helpers.ToString(pubkey));
        }
Пример #2
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            var oracleName = context.ParseResult.CommandResult.GetArgumentValueOrDefault <string>("name")?.Trim();

            if (oracleName is null)
            {
                throw new CommandOptionRequiredException("name");
            }
            var pubkey = context.ParseResult.CommandResult.GetArgumentValueOrDefault <string>("pubkey")?.ToLowerInvariant()?.Trim();

            if (pubkey is null)
            {
                throw new CommandOptionRequiredException("pubkey");
            }
            if (!OracleId.TryParse(pubkey, out var oracleId))
            {
                throw new CommandException("pubkey", "Invalid pubkey");
            }

            if (Set)
            {
                var oracle = await GetOracle("name", oracleName);

                await Repository.RemoveOracle(oracle.PubKey);

                await Repository.AddOracle(oracleId.PubKey);
            }
            else
            {
                var oracle = await TryGetOracle(oracleName);

                if (oracle is Oracle)
                {
                    throw new CommandException("name", "This oracle already exists");
                }
                await Repository.AddOracle(oracleId.PubKey);
            }
            await NameRepository.SetMapping(Scopes.Oracles, oracleName, oracleId.ToString());
        }