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); }
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()); }