예제 #1
0
        public async Task <Proposal> GetProposal(string hash)
        {
            var sql = @"
                SELECT      p.""InitiatorId"", p.""Upvotes"", p.""ExplorationPeriodId"", p.""PromotionPeriodId"", v.""Code""
                FROM        ""Proposals"" as p
                INNER JOIN  ""VotingPeriods"" as v
                        ON  v.""Id"" = p.""ProposalPeriodId""
                WHERE       p.""Hash"" = @hash::character(51)
                LIMIT       1";

            using var db = GetConnection();
            var row = await db.QueryFirstOrDefaultAsync(sql, new { hash });

            if (row == null)
            {
                return(null);
            }

            return(new Proposal
            {
                Hash = hash,
                Initiator = Accounts.GetAlias(row.InitiatorId),
                Period = row.Code,
                Upvotes = row.Upvotes,
                Status = row.ExplorationPeriodId == null ? "skipped" : row.PromotionPeriodId == null ? "rejected" : "accepted",
                Metadata = ProposalMetadata[hash]
            });
        }
예제 #2
0
        public async Task <Proposal> GetProposal(string hash)
        {
            var sql = @"
                SELECT      *
                FROM        ""Proposals""
                WHERE       ""Hash"" = @hash::character(51)
                ORDER BY    ""Epoch"" DESC
                LIMIT       1";

            using var db = GetConnection();
            var row = await db.QueryFirstOrDefaultAsync(sql, new { hash });

            if (row == null)
            {
                return(null);
            }

            return(new Proposal
            {
                Hash = hash,
                Initiator = Accounts.GetAlias(row.InitiatorId),
                FirstPeriod = row.FirstPeriod,
                LastPeriod = row.LastPeriod,
                Epoch = row.Epoch,
                Upvotes = row.Upvotes,
                Rolls = row.Rolls,
                Status = ProposalStatuses.ToString(row.Status),
                Metadata = row.Metadata
            });
        }
예제 #3
0
        public async Task <Commitment> Get(string address)
        {
            using var db = GetConnection();
            var row = await db.QueryFirstOrDefaultAsync(@"SELECT * FROM ""Commitments"" WHERE ""Address"" = @address::character(37)", new { address });

            if (row == null)
            {
                return(null);
            }

            return(new Commitment
            {
                Activated = row.Level != null,
                ActivatedAccount = row.AccountId == null ? null : Accounts.GetAlias(row.AccountId),
                ActivationLevel = row.Level,
                ActivationTime = row.Level == null ? null : Time[row.Level],
                Address = row.Address,
                Balance = row.Balance
            });
        }
예제 #4
0
        public async Task <IEnumerable <BakingRight> > Get(
            BakingRightTypeParameter type,
            AccountParameter baker,
            Int32Parameter cycle,
            Int32Parameter level,
            Int32NullParameter slots,
            Int32NullParameter priority,
            BakingRightStatusParameter status,
            SortParameter sort,
            OffsetParameter offset,
            int limit)
        {
            var sql = new SqlBuilder(@"SELECT * 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 state = State.GetState();

            return(rows.Select(row => new BakingRight
            {
                Type = TypeToString(row.Type),
                Cycle = row.Cycle,
                Level = row.Level,
                Timestamp = row.Status == 0 ? state.Timestamp.AddMinutes(row.Level - state.Level) : Time[row.Level],
                Baker = Accounts.GetAlias(row.BakerId),
                Priority = row.Priority,
                Slots = row.Slots,
                Status = StatusToString(row.Status)
            }));
        }