Ejemplo n.º 1
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            EventFullName evt = context.GetEventName();

            if (await Repository.GetEvent(evt) is Event)
            {
                throw new CommandException("name", "This event already exists");
            }
            var outcomes = context.GetOutcomes();
            var oracle   = await Repository.GetOracle(evt.OracleName);

            if (oracle is null)
            {
                throw new CommandException("name", "This oracle does not exists");
            }
            if (oracle.RootedKeyPath is null)
            {
                throw new CommandException("name", "You do not own the keys of this oracle");
            }


            var k = await Repository.CreatePrivateKey();

            var nonce = k.PrivateKey.ToECPrivKey().CreateSchnorrNonce();

            if (!await Repository.AddEvent(evt, nonce, outcomes, k.KeyPath))
            {
                throw new CommandException("name", "This event already exists");
            }
            context.Console.Out.Write(nonce.ToString());
        }
Ejemplo n.º 2
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            EventFullName evt    = context.GetEventName();
            var           rNonce = context.ParseResult.CommandResult.GetArgumentValueOrDefault <string>("nonce")?.ToLowerInvariant().Trim();

            if (rNonce is null)
            {
                throw new CommandOptionRequiredException("nonce");
            }
            if (!SchnorrNonce.TryParse(rNonce, out var nonce) || nonce is null)
            {
                throw new CommandException("nonce", "Invalid nonce");
            }

            var oracle = await GetOracle("eventfullname", evt.OracleName);

            var outcomes = context.GetOutcomes();
            var evtId    = new OracleInfo(oracle.PubKey !, nonce);

            if (!await Repository.AddEvent(evtId, outcomes.ToArray()))
            {
                throw new CommandException("eventfullname", "The specified event already exists");
            }
            await NameRepository.AsEventRepository().SetMapping(evtId, evt.Name);
        }
Ejemplo n.º 3
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            EventFullName evt = context.GetEventName();

            if (await TryGetEvent(evt) is Event)
            {
                throw new CommandException("eventfullname", "This event already exists");
            }
            var outcomes = context.GetOutcomes();
            var oracle   = await this.GetOracle("eventfullname", evt.OracleName);

            if (oracle.RootedKeyPath is null)
            {
                throw new CommandException("eventfullname", "You do not own the keys of this oracle");
            }

            var k = await Repository.CreatePrivateKey();

            var nonce = k.PrivateKey.ToECPrivKey().CreateSchnorrNonce();
            var evtId = new OracleInfo(oracle.PubKey !, nonce);

            if (!await Repository.AddEvent(evtId, outcomes, k.KeyPath))
            {
                throw new CommandException("eventfullname", "This event already exists");
            }
            await NameRepository.AsEventRepository().SetMapping(evtId, evt.Name);

            context.Console.Out.Write(nonce.ToString());
        }
Ejemplo n.º 4
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            var eventName = context.ParseResult.CommandResult.GetArgumentValueOrDefault <string>("name")?.Trim();

            if (eventName is null)
            {
                throw new CommandOptionRequiredException("name");
            }
            if (!EventFullName.TryParse(eventName, out EventFullName? evt) || evt is null)
            {
                throw new CommandException("name", "Invalid event full name, should be in the form 'oracleName/eventName'");
            }
            var rNonce = context.ParseResult.CommandResult.GetArgumentValueOrDefault <string>("nonce")?.ToLowerInvariant().Trim();

            if (rNonce is null)
            {
                throw new CommandOptionRequiredException("nonce");
            }
            if (!SchnorrNonce.TryParse(rNonce, out var nonce) || nonce is null)
            {
                throw new CommandException("nonce", "Invalid nonce");
            }
            var outcomes = context.GetOutcomes();

            if (!await Repository.OracleExists(evt.OracleName))
            {
                throw new CommandException("name", "The specified oracle do not exists");
            }
            if (!await Repository.AddEvent(evt, nonce, outcomes.ToArray()))
            {
                throw new CommandException("name", "The specified event already exists");
            }
        }