Example #1
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            byte[] buf = new byte[32];

            var names = await NameRepository.AsOracleNameRepository().GetIds();

            foreach (var o in names.OrderBy(n => n.Key))
            {
                context.Console.Out.WriteLine($"{o.Key}\t{o.Value}");
            }
        }
Example #2
0
        protected override async Task InvokeAsyncBase(InvocationContext context)
        {
            var name = context.ParseResult.CommandResult.GetArgumentValueOrDefault <string>("name");

            if (name is null)
            {
                throw new CommandOptionRequiredException("name");
            }
            var oracle = await GetOracle("name", name);

            await NameRepository.RemoveMapping(Scopes.Oracles, name);

            await Repository.RemoveOracle(oracle.PubKey);
        }
Example #3
0
        public async Task <int> InvokeAsync(InvocationContext context)
        {
            try
            {
                Network         = Bitcoin.Instance.GetNetwork(GetNetworkType(context.ParseResult.RootCommandResult.ValueForOption("network") as string ?? "mainnet"));
                _Repository     = new Repository(context.ParseResult.RootCommandResult.ValueForOption <string>("datadir"), Network);
                _NameRepository = new NameRepository(Path.Combine(_Repository.RepositoryDirectory, "names.json"));
                NDLC.Messages.Serializer.Configure(JsonSerializerSettings, Network);
                await InvokeAsyncBase(context);

                return(0);
            }
            catch (CommandException ex)
            {
                context.Console.Error.WriteLine(ex.Message);
                return(1);
            }
        }
Example #4
0
        public async Task <int> InvokeAsync(InvocationContext context)
        {
            try
            {
                Network = context.ParseResult.RootCommandResult.ValueForOption <bool>("testnet") ? Network.TestNet :
                          context.ParseResult.RootCommandResult.ValueForOption <bool>("regtest") ? Network.RegTest :
                          Network.Main;
                _Repository     = new Repository(context.ParseResult.RootCommandResult.ValueForOption <string>("datadir"), Network);
                _NameRepository = new NameRepository(Path.Combine(_Repository.RepositoryDirectory, "names.json"));
                NDLC.Messages.Serializer.Configure(JsonSerializerSettings, Network);
                await InvokeAsyncBase(context);

                return(0);
            }
            catch (CommandException ex)
            {
                context.Console.Error.WriteLine(ex.Message);
                return(1);
            }
        }
Example #5
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));
        }
Example #6
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());
        }
Example #7
0
 public DLCNameRepository(NameRepository nameRepository)
 {
     this.NameRepository = nameRepository;
 }
 public OracleNameRepository(NameRepository nameRepository)
 {
     NameRepository = nameRepository;
 }
Example #9
0
 public EventNameRepository(NameRepository nameRepository)
 {
     NameRepository = nameRepository;
 }