public async Task <OracleId?> GetId(string name)
        {
            var id = await NameRepository.GetId(Scopes.Oracles, name);

            if (id is null)
            {
                return(null);
            }
            OracleId.TryParse(id, out var r);
            return(r);
        }
        public async Task <ICollection <KeyValuePair <string, OracleId> > > GetIds()
        {
            var ids = await NameRepository.GetIds(Scopes.Oracles);

            var result = new List <KeyValuePair <string, OracleId> >();

            foreach (var id in ids)
            {
                if (OracleId.TryParse(id.Value, out var idObj))
                {
                    result.Add(new KeyValuePair <string, OracleId>(id.Key, idObj));
                }
            }
            return(result);
        }
Example #3
0
        public static bool TryParse(string str, [MaybeNullWhenAttribute(false)] out OracleId id)
        {
            id = null;
            if (!HexEncoder.IsWellFormed(str))
            {
                return(false);
            }
            var bytes = Encoders.Hex.DecodeData(str);

            if (!ECXOnlyPubKey.TryCreate(bytes, Context.Instance, out var k) || k is null)
            {
                return(false);
            }
            id = new OracleId(k);
            return(true);
        }
Example #4
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 #5
0
        public async Task <EventFullName?> ResolveName(OracleInfo eventId)
        {
            var events = await NameRepository.GetIds(Scopes.Events);

            foreach (var ev in events)
            {
                var oracleId = new OracleId(eventId.PubKey);
                if (ev.Key.StartsWith(oracleId.ToString()))
                {
                    if (ev.Value == eventId.RValue.ToString())
                    {
                        var oracleName = await NameRepository.GetName(Scopes.Oracles, oracleId.ToString());

                        if (oracleName is null)
                        {
                            return(null);
                        }
                        var idx = ev.Key.IndexOf('/');
                        return(new EventFullName(oracleName, ev.Key.Substring(idx + 1)));
                    }
                }
            }
            return(null);
        }
Example #6
0
 private string GetEventFullName(OracleId oracleId, string name)
 {
     return($"{oracleId.ToString()}/{name}");
 }