Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public static bool TryParse(string str, [MaybeNullWhen(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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 private string GetEventFullName(OracleId oracleId, string name)
 {
     return($"{oracleId.ToString()}/{name}");
 }