public async Task <IEnumerable <RevelationPenaltyOperation> > GetRevelationPenalties(
            AccountParameter baker,
            Int32Parameter level,
            DateTimeParameter timestamp,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            Symbols quote)
        {
            var sql = new SqlBuilder(@"SELECT o.*, b.""Hash"" FROM ""RevelationPenaltyOps"" AS o INNER JOIN ""Blocks"" as b ON b.""Level"" = o.""Level""")
                      .FilterA(@"o.""BakerId""", baker)
                      .FilterA(@"o.""Level""", level)
                      .FilterA(@"o.""Timestamp""", timestamp)
                      .Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"), "o");

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            return(rows.Select(row => new RevelationPenaltyOperation
            {
                Id = row.Id,
                Level = row.Level,
                Block = row.Hash,
                Timestamp = row.Timestamp,
                Baker = Accounts.GetAlias(row.BakerId),
                MissedLevel = row.MissedLevel,
                LostReward = row.LostReward,
                LostFees = row.LostFees,
                Quote = Quotes.Get(quote, row.Level)
            }));
        }
 public async Task <IEnumerable <RegisterConstantOperation> > GetRegisterConstants(
     AccountParameter sender,
     ExpressionParameter address,
     Int32Parameter level,
     DateTimeParameter timestamp,
     OperationStatusParameter status,
     SortParameter sort,
     OffsetParameter offset,
     int limit,
     MichelineFormat format,
     Symbols quote)
 {
     var sql = new SqlBuilder(@"
         SELECT      o.*, b.""Hash""
         FROM        ""RegisterConstantOps"" AS o
         INNER JOIN  ""Blocks"" as b
                 ON  b.""Level"" = o.""Level""")
               .Filter("SenderId", sender)
               .Filter("Address", address)
               .FilterA(@"o.""Level""", level)
               .FilterA(@"o.""Timestamp""", timestamp)
               .Filter("Status", status)
               .Take(sort, offset, limit, x => x switch
     {
         "level" => ("Id", "Level"),
         "gasUsed" => ("GasUsed", "GasUsed"),
         "storageUsed" => ("StorageUsed", "StorageUsed"),
         "bakerFee" => ("BakerFee", "BakerFee"),
         "storageFee" => ("StorageFee", "StorageFee"),
         _ => ("Id", "Id")
     }, "o");
 public async Task <IEnumerable <OriginationOperation> > GetOriginations(
     AnyOfParameter anyof,
     AccountParameter initiator,
     AccountParameter sender,
     AccountParameter contractManager,
     AccountParameter contractDelegate,
     AccountParameter originatedContract,
     Int32Parameter typeHash,
     Int32Parameter codeHash,
     Int32Parameter level,
     DateTimeParameter timestamp,
     OperationStatusParameter status,
     SortParameter sort,
     OffsetParameter offset,
     int limit,
     MichelineFormat format,
     Symbols quote,
     bool includeStorage = false,
     bool includeBigmaps = false)
 {
     var sql = new SqlBuilder($@"
         SELECT      o.*, b.""Hash""
         FROM        ""OriginationOps"" AS o
         INNER JOIN  ""Blocks"" as b
                 ON  b.""Level"" = o.""Level""
         {(typeHash != null || codeHash != null ? @"LEFT JOIN ""Accounts"" as c ON c.""Id"" = o.""ContractId""" : "")}")
               .Filter(anyof, x => x switch
     {
         "initiator" => "InitiatorId",
         "sender" => "SenderId",
         "contractManager" => "ManagerId",
         "contractDelegate" => "DelegateId",
         _ => "ContractId"
     })
Ejemplo n.º 4
0
        public async Task <ActionResult <IEnumerable <BigMapUpdate> > > GetBigMapUpdates(
            Int32Parameter bigmap,
            StringParameter path,
            AccountParameter contract,
            BigMapTagsParameter tags,
            BigMapActionParameter action,
            JsonParameter value,
            Int32Parameter level,
            TimestampParameter timestamp,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            MichelineFormat micheline   = MichelineFormat.Json)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "level"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (path == null && contract == null && tags == null)
            {
                return(Ok(await BigMaps.GetUpdates(bigmap, action, value, level, timestamp, sort, offset, limit, micheline)));
            }

            return(Ok(await BigMaps.GetUpdates(bigmap, path, contract, action, value, tags, level, timestamp, sort, offset, limit, micheline)));
        }
Ejemplo n.º 5
0
        public async Task <IEnumerable <Statistics> > Get(
            StatisticsPeriod period,
            Int32Parameter cycle,
            Int32Parameter level,
            TimestampParameter timestamp,
            DateTimeParameter date,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            Symbols quote)
        {
            var sql = new SqlBuilder(@"SELECT * FROM ""Statistics""");

            if (period == StatisticsPeriod.Cyclic)
            {
                sql.Filter(@"""Cycle"" IS NOT NULL");
            }
            else if (period == StatisticsPeriod.Daily)
            {
                sql.Filter(@"""Date"" IS NOT NULL");
            }

            sql.Filter("Cycle", cycle)
            .Filter("Level", level)
            .Filter("Level", timestamp)
            .Filter("Date", date)
            .Take(sort, offset, limit, x => x switch
            {
                "level" => ("Level", "Level"),
                "cycle" => ("Cycle", "Cycle"),
                "date" => ("Date", "Date"),
                _ => ("Id", "Id")
            });
Ejemplo n.º 6
0
 public async Task <IEnumerable <DoubleBakingOperation> > GetDoubleBakings(
     AnyOfParameter anyof,
     AccountParameter accuser,
     AccountParameter offender,
     Int32Parameter level,
     DateTimeParameter timestamp,
     SortParameter sort,
     OffsetParameter offset,
     int limit,
     Symbols quote)
 {
     var sql = new SqlBuilder(@"SELECT o.*, b.""Hash"" FROM ""DoubleBakingOps"" AS o INNER JOIN ""Blocks"" as b ON b.""Level"" = o.""Level""")
               .Filter(anyof, x => x == "accuser" ? "AccuserId" : "OffenderId")
               .Filter("AccuserId", accuser, x => "OffenderId")
               .Filter("OffenderId", offender, x => "AccuserId")
               .FilterA(@"o.""Level""", level)
               .FilterA(@"o.""Timestamp""", timestamp)
               .Take(sort, offset, limit, x => x switch
     {
         "level" => ("Id", "Level"),
         "accusedLevel" => ("AccusedLevel", "AccusedLevel"),
         "accuserRewards" => ("AccuserReward", "AccuserReward"),
         "offenderLostDeposits" => ("OffenderLostDeposit", "OffenderLostDeposit"),
         "offenderLostRewards" => ("OffenderLostReward", "OffenderLostReward"),
         "offenderLostFees" => ("OffenderLostFee", "OffenderLostFee"),
         _ => ("Id", "Id")
     }, "o");
Ejemplo n.º 7
0
        public async Task <IEnumerable <Cycle> > Get(
            Int32Parameter snapshotIndex,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            Symbols quote)
        {
            var sql = new SqlBuilder(@"SELECT * FROM ""Cycles""")
                      .Filter("SnapshotIndex", snapshotIndex)
                      .Take(sort ?? new SortParameter {
                Desc = "index"
            }, offset, limit, x => ("Index", "Index"));

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            return(rows.Select(row => new Cycle
            {
                Index = row.Index,
                FirstLevel = row.FirstLevel,
                StartTime = Times[row.FirstLevel],
                LastLevel = row.LastLevel,
                EndTime = Times[row.LastLevel],
                RandomSeed = row.Seed,
                SnapshotIndex = row.SnapshotIndex,
                SnapshotLevel = row.SnapshotLevel,
                TotalBakers = row.TotalBakers,
                TotalDelegated = row.TotalDelegated,
                TotalDelegators = row.TotalDelegators,
                TotalRolls = row.TotalRolls,
                TotalStaking = row.TotalStaking,
                Quote = Quotes.Get(quote, row.LastLevel)
            }));
        }
Ejemplo n.º 8
0
        public async Task <IEnumerable <BakingOperation> > GetBakings(
            AccountParameter baker,
            Int32Parameter level,
            DateTimeParameter timestamp,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            Symbols quote)
        {
            var sql = new SqlBuilder(@"SELECT ""Id"", ""Level"", ""Timestamp"", ""BakerId"", ""Hash"", ""Priority"", ""Deposit"", ""Reward"", ""Fees"" FROM ""Blocks""")
                      .Filter("BakerId", baker)
                      .Filter(@"""BakerId"" IS NOT NULL")
                      .Filter("Level", level)
                      .Filter("Timestamp", timestamp)
                      .Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"));

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            return(rows.Select(row => new BakingOperation
            {
                Id = row.Id,
                Level = row.Level,
                Timestamp = row.Timestamp,
                Baker = Accounts.GetAlias(row.BakerId),
                Block = row.Hash,
                Priority = row.Priority,
                Deposit = row.Deposit,
                Reward = row.Reward,
                Fees = row.Fees,
                Quote = Quotes.Get(quote, row.Level)
            }));
        }
Ejemplo n.º 9
0
 public async Task <IEnumerable <Constant> > Get(
     ExpressionParameter address,
     Int32Parameter creationLevel,
     TimestampParameter creationTime,
     AccountParameter creator,
     Int32Parameter refs,
     Int32Parameter size,
     SortParameter sort,
     OffsetParameter offset,
     int limit,
     int format)
 {
     var sql = new SqlBuilder(@"SELECT * FROM ""RegisterConstantOps""")
               .Filter(@"""Address"" IS NOT NULL")
               .Filter("Address", address)
               .Filter("Level", creationLevel)
               .Filter("Level", creationTime)
               .Filter("SenderId", creator)
               .Filter("Refs", refs)
               .Filter("StorageUsed", size)
               .Take(sort, offset, limit, x => x switch
     {
         "creationLevel" => ("Level", "Level"),
         "size" => ("StorageUsed", "StorageUsed"),
         "refs" => ("Refs", "Refs"),
         _ => ("Id", "Id")
     });
Ejemplo n.º 10
0
        public async Task <IEnumerable <EndorsementOperation> > GetEndorsements(
            AccountParameter delegat,
            Int32Parameter level,
            DateTimeParameter timestamp,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            Symbols quote)
        {
            var sql = new SqlBuilder(@"SELECT o.*, b.""Hash"" FROM ""EndorsementOps"" AS o INNER JOIN ""Blocks"" as b ON b.""Level"" = o.""Level""")
                      .Filter("DelegateId", delegat)
                      .FilterA(@"o.""Level""", level)
                      .FilterA(@"o.""Timestamp""", timestamp)
                      .Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"), "o");

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            return(rows.Select(row => new EndorsementOperation
            {
                Id = row.Id,
                Level = row.Level,
                Block = row.Hash,
                Timestamp = row.Timestamp,
                Hash = row.OpHash,
                Delegate = Accounts.GetAlias(row.DelegateId),
                Slots = row.Slots,
                Rewards = row.Reward,
                Deposit = row.Deposit,
                Quote = Quotes.Get(quote, row.Level)
            }));
        }
Ejemplo n.º 11
0
        public async Task <IEnumerable <BallotOperation> > GetBallots(
            AccountParameter sender,
            Int32Parameter level,
            DateTimeParameter timestamp,
            Int32Parameter epoch,
            Int32Parameter period,
            ProtocolParameter proposal,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            Symbols quote)
        {
            var sql = new SqlBuilder(@"
                SELECT      o.""Id"", o.""Level"", o.""Timestamp"", o.""OpHash"", o.""SenderId"", o.""Rolls"", o.""Vote"", o.""Epoch"", o.""Period"",
                            b.""Hash"",
                            proposal.""Hash"" as ""ProposalHash"", proposal.""Metadata"" ->> 'alias' as ""ProposalAlias"",
                            period.""Kind"", period.""FirstLevel"", period.""LastLevel""
                FROM        ""BallotOps"" as o
                INNER JOIN  ""Blocks"" as b ON b.""Level"" = o.""Level""
                INNER JOIN  ""Proposals"" as proposal ON proposal.""Id"" = o.""ProposalId""
                INNER JOIN  ""VotingPeriods"" as period ON period.""Index"" = o.""Period""
                ")
                      .Filter("SenderId", sender)
                      .FilterA(@"o.""Level""", level)
                      .FilterA(@"o.""Timestamp""", timestamp)
                      .FilterA(@"o.""Epoch""", epoch)
                      .FilterA(@"o.""Period""", period)
                      .FilterA(@"proposal.""Hash""", proposal)
                      .Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"), "o");

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            return(rows.Select(row => new BallotOperation
            {
                Id = row.Id,
                Level = row.Level,
                Block = row.Hash,
                Timestamp = row.Timestamp,
                Hash = row.OpHash,
                Period = new PeriodInfo
                {
                    Index = row.Period,
                    Epoch = row.Epoch,
                    Kind = PeriodKinds.ToString(row.Kind),
                    FirstLevel = row.FirstLevel,
                    LastLevel = row.LastLevel
                },
                Proposal = new ProposalAlias
                {
                    Hash = row.ProposalHash,
                    Alias = row.ProposalAlias
                },
                Delegate = Accounts.GetAlias(row.SenderId),
                Rolls = row.Rolls,
                Vote = Votes.ToString(row.Vote),
                Quote = Quotes.Get(quote, row.Level)
            }));
        }
Ejemplo n.º 12
0
        public Task <int> GetCount(Int32Parameter refs)
        {
            if (refs == null)
            {
                return(Task.FromResult(State.Current.ConstantsCount));
            }

            return(Constants.GetCount());
        }
Ejemplo n.º 13
0
 public Task <int> GetCount(
     BakingRightTypeParameter type,
     AccountParameter baker,
     Int32Parameter cycle,
     Int32Parameter level,
     Int32NullParameter slots,
     Int32NullParameter priority,
     BakingRightStatusParameter status)
 {
     return(BakingRights.GetCount(type, baker, cycle, level, slots, priority, status));
 }
        public async Task <int> GetOriginationsCount(
            Int32Parameter level,
            DateTimeParameter timestamp)
        {
            var sql = new SqlBuilder(@"SELECT COUNT(*) FROM ""OriginationOps""")
                      .Filter("Level", level)
                      .Filter("Timestamp", timestamp);

            using var db = GetConnection();
            return(await db.QueryFirstAsync <int>(sql.Query, sql.Params));
        }
Ejemplo n.º 15
0
        public async Task <ActionResult <IEnumerable <BakingRight> > > Get(
            BakingRightTypeParameter type,
            AccountParameter baker,
            Int32Parameter cycle,
            Int32Parameter level,
            Int32NullParameter slots,
            Int32NullParameter priority,
            BakingRightStatusParameter status,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("level"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await BakingRights.Get(type, baker, cycle, level, slots, priority, status, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
Ejemplo n.º 16
0
        public async Task <ActionResult <IEnumerable <Constant> > > Get(
            ExpressionParameter address,
            Int32Parameter creationLevel,
            TimestampParameter creationTime,
            AccountParameter creator,
            Int32Parameter refs,
            Int32Parameter size,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            [Range(0, 2)] int format    = 0)
        {
            #region validate
            if (sort != null && !sort.Validate("creationLevel", "size", "refs"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, format)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Values[0], format)));
                }
                else
                {
                    return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Values, format)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Fields[0], format)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Constants.Get(address, creationLevel, creationTime, creator, refs, size, sort, offset, limit, select.Fields, format)
                    }));
                }
            }
        }
Ejemplo n.º 17
0
        public async Task <ActionResult <IEnumerable <BigMapKey> > > GetKeys(
            [Min(0)] int id,
            bool?active,
            JsonParameter key,
            JsonParameter value,
            Int32Parameter lastLevel,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            MichelineFormat micheline   = MichelineFormat.Json)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "firstLevel", "lastLevel", "updates"))
            {
                return(new BadRequest(nameof(sort), "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await BigMaps.GetKeys(id, active, key, value, lastLevel, sort, offset, limit, micheline)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await BigMaps.GetKeys(id, active, key, value, lastLevel, sort, offset, limit, select.Values[0], micheline)));
                }
                else
                {
                    return(Ok(await BigMaps.GetKeys(id, active, key, value, lastLevel, sort, offset, limit, select.Values, micheline)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await BigMaps.GetKeys(id, active, key, value, lastLevel, sort, offset, limit, select.Fields[0], micheline)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await BigMaps.GetKeys(id, active, key, value, lastLevel, sort, offset, limit, select.Fields, micheline)
                    }));
                }
            }
        }
Ejemplo n.º 18
0
        public async Task <ActionResult <IEnumerable <BigMap> > > GetBigMaps(
            AccountParameter contract,
            StringParameter path,
            BigMapTagsParameter tags,
            bool?active,
            Int32Parameter lastLevel,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            MichelineFormat micheline   = MichelineFormat.Json)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "ptr", "firstLevel", "lastLevel", "totalKeys", "activeKeys", "updates"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, micheline)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Values[0], micheline)));
                }
                else
                {
                    return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Values, micheline)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Fields[0], micheline)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await BigMaps.Get(contract, path, tags, active, lastLevel, sort, offset, limit, select.Fields, micheline)
                    }));
                }
            }
        }
Ejemplo n.º 19
0
 public async Task <IEnumerable <Proposal> > GetProposals(
     Int32Parameter epoch,
     SortParameter sort,
     OffsetParameter offset,
     int limit)
 {
     var sql = new SqlBuilder(@"SELECT * FROM ""Proposals""")
               .Filter("Epoch", epoch)
               .Take(sort, offset, limit, x => x switch
     {
         "upvotes" => ("Upvotes", "Upvotes"),
         "rolls" => ("Rolls", "Rolls"),
         _ => ("Id", "Id")
     });
Ejemplo n.º 20
0
 public async Task <IEnumerable <Quote> > Get(
     Int32Parameter level,
     DateTimeParameter timestamp,
     SortParameter sort,
     OffsetParameter offset,
     int limit)
 {
     var sql = new SqlBuilder(@"SELECT * FROM ""Quotes""")
               .Filter("Level", level)
               .Filter("Timestamp", timestamp)
               .Take(sort, offset, limit, x => x switch
     {
         "level" => ("Id", "Level"),
         _ => ("Id", "Id")
     });
Ejemplo n.º 21
0
        public async Task <ActionResult <IEnumerable <BakerRewards> > > GetBakerRewards(
            [Required][TzAddress] string address,
            Int32Parameter cycle,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (sort != null && !sort.Validate("cycle"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Rewards.GetBakerRewards(address, cycle, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
Ejemplo n.º 22
0
        public async Task <ActionResult <IEnumerable <Statistics> > > Get(
            Int32Parameter level,
            TimestampParameter timestamp,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "level", "cycle", "date"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Statistics.Get(StatisticsPeriod.None, null, level, timestamp, null, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
Ejemplo n.º 23
0
        public async Task <ActionResult <IEnumerable <Quote> > > Get(
            Int32Parameter level,
            DateTimeParameter timestamp,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("level"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Quotes.Get(level, timestamp, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Quotes.Get(level, timestamp, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
Ejemplo n.º 24
0
        public async Task <ActionResult <IEnumerable <Proposal> > > GetProposals(
            ProtocolParameter hash,
            Int32Parameter epoch,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "upvotes", "rolls"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Voting.GetProposals(hash, epoch, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
Ejemplo n.º 25
0
        public async Task <ActionResult <IEnumerable <Models.Delegate> > > Get(
            BoolParameter active,
            Int32Parameter lastActivity,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "stakingBalance", "balance", "numDelegators", "activationLevel", "deactivationLevel"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Accounts.GetDelegates(active, lastActivity, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
Ejemplo n.º 26
0
        public async Task <ActionResult <IEnumerable <Cycle> > > Get(
            Int32Parameter snapshotIndex,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (sort != null && !sort.Validate("index"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, quote)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Cycles.Get(snapshotIndex, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Cycles.Get(snapshotIndex, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
Ejemplo n.º 27
0
		public void ChangeValues()
		{
			IConfigParameter<int> param1 = new Int32Parameter("int32");
			Assert.AreEqual(0, param1.Value);
			param1.SetValue(2);
			Assert.AreEqual(2, param1.Value);

			IConfigParameter<string> param2 = new StringParameter("string");
			Assert.AreEqual(null, param2.Value);
			param2.SetValue("yyy");
			Assert.AreEqual("yyy", param2.Value);

			IConfigParameter<TimeSpan> param3 = new TimeSpanParameter("timespan");
			Assert.AreEqual(TimeSpan.Zero, param3.Value);
			param3.SetValue(TimeSpan.FromDays(1.5));
			Assert.AreEqual(TimeSpan.FromDays(1.5), param3.Value);
		}
Ejemplo n.º 28
0
        public async Task <ActionResult <IEnumerable <Delegator> > > GetDelegators(
            [Address] string address,
            AccountTypeParameter type,
            Int64Parameter balance,
            Int32Parameter delegationLevel,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("balance", "delegationLevel"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            return(Ok(await Accounts.GetDelegators(address, type, balance, delegationLevel, sort, offset, limit)));
        }
 public async Task <IEnumerable <ActivationOperation> > GetActivations(
     AccountParameter account,
     Int32Parameter level,
     DateTimeParameter timestamp,
     SortParameter sort,
     OffsetParameter offset,
     int limit,
     Symbols quote)
 {
     var sql = new SqlBuilder(@"SELECT o.*, b.""Hash"" FROM ""ActivationOps"" AS o INNER JOIN ""Blocks"" as b ON b.""Level"" = o.""Level""")
               .Filter("AccountId", account)
               .FilterA(@"o.""Level""", level)
               .FilterA(@"o.""Timestamp""", timestamp)
               .Take(sort, offset, limit, x => x switch
     {
         "level" => ("Id", "Level"),
         "balance" => ("Balance", "Balance"),
         _ => ("Id", "Id")
     }, "o");
Ejemplo n.º 30
0
		public void Validation()
		{
			var param1 = new Int32Parameter("p1")
				.With(p => p.Validation(value => {
					if (value < 1 || value > 10)
					{
						return "valid values are in the range [1, 10]";
					}
					return null;
				}));

			var param2 = new Int32Parameter("p2");

			Assert.IsNull(param1.Extra.Validate(1));
			Assert.AreEqual("valid values are in the range [1, 10]", ((IConfigParameter<int>)param1).Validate(11));

			Assert.IsNull(param2.Extra.Validate(0));
			Assert.IsNull(param2.Extra.Validate(int.MaxValue));
		}
Ejemplo n.º 31
0
 public async Task <IEnumerable <Models.Delegate> > GetDelegates(
     BoolParameter active,
     Int32Parameter lastActivity,
     SortParameter sort,
     OffsetParameter offset,
     int limit)
 {
     var sql = new SqlBuilder($@"SELECT *, {AliasQuery} FROM ""Accounts""")
               .Filter("Type", 1)
               .Filter("Staked", active)
               .Filter("LastLevel", lastActivity)
               .Take(sort, offset, limit, x => x switch
     {
         "activationLevel" => ("ActivationLevel", "ActivationLevel"),
         "deactivationLevel" => ("DeactivationLevel", "DeactivationLevel"),
         "stakingBalance" => ("StakingBalance", "StakingBalance"),
         "balance" => ("Balance", "Balance"),
         "numDelegators" => ("DelegatorsCount", "DelegatorsCount"),
         _ => ("Id", "Id")
     });
Ejemplo n.º 32
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)
            }));
        }
Ejemplo n.º 33
0
		public void ImplicitConversion()
		{
			var intp = new Int32Parameter("intp").With(p => p.DefaultValue(22));
			var intValue = intp * 4;
			Assert.AreEqual(88, intValue);

			var stringp = new StringParameter("stringp").With(p => p.DefaultValue("Hello world"));
			var stringValue = stringp + "!";
			Assert.AreEqual("Hello world!", stringValue);
		}
Ejemplo n.º 34
0
		public void ScratchPad()
		{
			Int32Parameter param = new Int32Parameter("name")
				.With(p => {
					p.Description("Some description");
					p.ValidRange(1, 10);
					p.DefaultValue(4);
					p.ChangeAction(DoSomething);
				});
		}
Ejemplo n.º 35
0
		public void WhenChanged()
		{
			var changed = false;
			var param = new Int32Parameter("test1")
				.With(with => with.ChangeAction(() => changed = true));
			Assert.AreEqual(0, param.Value);

			((IConfigParameter<int>)param).SetValue(2);
			Assert.IsTrue(changed);
			Assert.AreEqual(2, param.Value);

			changed = false;
			((IConfigParameter<int>)param).SetValue(2);
			Assert.IsFalse(changed);
			Assert.AreEqual(2, param.Value);
		}