public async Task <Block> Get(int level, bool operations, MichelineFormat format, Symbols quote) { var sql = @" SELECT * FROM ""Blocks"" WHERE ""Level"" = @level LIMIT 1"; using var db = GetConnection(); var row = await db.QueryFirstOrDefaultAsync(sql, new { level }); if (row == null) { return(null); } var block = new Block { Cycle = row.Cycle, Level = level, Hash = row.Hash, Timestamp = row.Timestamp, Proto = row.ProtoCode, Priority = row.Priority, Validations = row.Validations, Deposit = row.Deposit, Reward = row.Reward, Fees = row.Fees, NonceRevealed = row.RevelationId != null, Baker = row.BakerId != null ? await Accounts.GetAliasAsync(row.BakerId) : null, Software = row.SoftwareId != null ? Software[row.SoftwareId] : null, LBEscapeVote = row.LBEscapeVote, LBEscapeEma = row.LBEscapeEma, Quote = Quotes.Get(quote, level) }; if (operations) { await LoadOperations(block, (Data.Models.Operations) row.Operations, format, quote); } return(block); }
public async Task <Block> Get(int level, bool operations = false) { var sql = @" SELECT ""Hash"", ""Timestamp"", ""ProtoCode"", ""Priority"", ""Validations"", ""Operations"", ""Reward"", ""Fees"", ""BakerId"", ""RevelationId"" FROM ""Blocks"" WHERE ""Level"" = @level LIMIT 1"; using var db = GetConnection(); var row = await db.QueryFirstOrDefaultAsync(sql, new { level }); if (row == null) { return(null); } var block = new Block { Level = level, Hash = row.Hash, Timestamp = row.Timestamp, Proto = row.ProtoCode, Priority = row.Priority, Validations = row.Validations, Reward = row.Reward, Fees = row.Fees, NonceRevealed = row.RevelationId != null, Baker = row.BakerId != null ? await Accounts.GetAliasAsync(row.BakerId) : null }; if (operations) { await LoadOperations(block, (Data.Models.Operations) row.Operations); } return(block); }
public async Task <object[][]> Get( BakingRightTypeParameter type, AccountParameter baker, Int32Parameter cycle, Int32Parameter level, Int32NullParameter slots, Int32NullParameter priority, BakingRightStatusParameter status, SortParameter sort, OffsetParameter offset, int limit, string[] fields) { var columns = new HashSet <string>(fields.Length); foreach (var field in fields) { switch (field) { case "type": columns.Add(@"""Type"""); break; case "cycle": columns.Add(@"""Cycle"""); break; case "level": columns.Add(@"""Level"""); break; case "timestamp": columns.Add(@"""Level"""); columns.Add(@"""Status"""); break; case "baker": columns.Add(@"""BakerId"""); break; case "priority": columns.Add(@"""Priority"""); break; case "slots": columns.Add(@"""Slots"""); break; case "status": columns.Add(@"""Status"""); break; } } if (columns.Count == 0) { return(Array.Empty <object[]>()); } var sql = new SqlBuilder($@"SELECT {string.Join(',', columns)} FROM ""BakingRights""") .Filter("Cycle", cycle) .Filter("Level", level) .Filter("BakerId", baker) .Filter("Type", type) .Filter("Status", status) .Filter("Priority", priority) .Filter("Slots", slots) .Take(sort ?? new SortParameter { Asc = "level" }, offset, limit, x => ("Level", "Level")); using var db = GetConnection(); var rows = await db.QueryAsync(sql.Query, sql.Params); var result = new object[rows.Count()][]; for (int i = 0; i < result.Length; i++) { result[i] = new object[fields.Length]; } for (int i = 0, j = 0; i < fields.Length; j = 0, i++) { switch (fields[i]) { case "type": foreach (var row in rows) { result[j++][i] = BakingRightTypes.ToString(row.Type); } break; case "cycle": foreach (var row in rows) { result[j++][i] = row.Cycle; } break; case "level": foreach (var row in rows) { result[j++][i] = row.Level; } break; case "timestamp": foreach (var row in rows) { result[j++][i] = Time[row.Level]; } break; case "baker": foreach (var row in rows) { result[j++][i] = await Accounts.GetAliasAsync(row.BakerId); } break; case "priority": foreach (var row in rows) { result[j++][i] = row.Priority; } break; case "slots": foreach (var row in rows) { result[j++][i] = row.Slots; } break; case "status": foreach (var row in rows) { result[j++][i] = BakingRightStatuses.ToString(row.Status); } break; } } return(result); }
public async Task <object[][]> GetProposals(SortParameter sort, OffsetParameter offset, int limit, string[] fields) { var columns = new HashSet <string>(fields.Length + 1); var joins = new HashSet <string>(1); foreach (var field in fields) { switch (field) { case "hash": columns.Add(@"p.""Hash"""); break; case "initiator": columns.Add(@"p.""InitiatorId"""); break; case "upvotes": columns.Add(@"p.""Upvotes"""); break; case "metadata": columns.Add(@"p.""Hash"""); break; case "status": columns.Add(@"p.""ExplorationPeriodId"""); columns.Add(@"p.""PromotionPeriodId"""); break; case "period": columns.Add(@"v.""Code"""); joins.Add(@"INNER JOIN ""VotingPeriods"" as v ON v.""Id"" = p.""ProposalPeriodId"""); break; } } if (columns.Count == 0) { return(Array.Empty <object[]>()); } var sql = new SqlBuilder($@"SELECT {string.Join(',', columns)} FROM ""Proposals"" as p {string.Join(' ', joins)}") .Take(sort, offset, limit, x => ("Id", "Id"), "p"); using var db = GetConnection(); var rows = await db.QueryAsync(sql.Query, sql.Params); var result = new object[rows.Count()][]; for (int i = 0; i < result.Length; i++) { result[i] = new object[fields.Length]; } for (int i = 0, j = 0; i < fields.Length; j = 0, i++) { switch (fields[i]) { case "hash": foreach (var row in rows) { result[j++][i] = row.Hash; } break; case "initiator": foreach (var row in rows) { result[j++][i] = await Accounts.GetAliasAsync(row.InitiatorId); } break; case "upvotes": foreach (var row in rows) { result[j++][i] = row.Upvotes; } break; case "metadata": foreach (var row in rows) { result[j++][i] = ProposalMetadata[row.Hash]; } break; case "status": foreach (var row in rows) { result[j++][i] = row.ExplorationPeriodId == null ? "skipped" : row.PromotionPeriodId == null ? "rejected" : "accepted"; } break; case "period": foreach (var row in rows) { result[j++][i] = row.Code; } break; } } return(result); }