Exemplo n.º 1
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)
            }));
        }
 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"
     })
 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");
Exemplo n.º 4
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");
Exemplo n.º 5
0
        public async Task <ActionResult <IEnumerable <BigMapKeyUpdate> > > GetKeyUpdates(
            [Min(0)] int id,
            [Required] string key,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            MichelineFormat micheline   = MichelineFormat.Json)
        {
            #region validate
            if (sort != null && !sort.Validate("id"))
            {
                return(new BadRequest(nameof(sort), "Sorting by the specified field is not allowed."));
            }
            #endregion

            try
            {
                if (Regex.IsMatch(key, @"^expr[0-9A-z]{50}$"))
                {
                    return(Ok(await BigMaps.GetKeyByHashUpdates(id, key, sort, offset, limit, micheline)));
                }

                using var doc = JsonDocument.Parse(WrapKey(key));
                return(Ok(await BigMaps.GetKeyUpdates(id, doc.RootElement.GetRawText(), sort, offset, limit, micheline)));
            }
            catch (JsonException)
            {
                return(new BadRequest(nameof(key), "invalid json value"));
            }
            catch
            {
                throw;
            }
        }
        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)
            }));
        }
Exemplo n.º 7
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)
            }));
        }
Exemplo n.º 8
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)
            }));
        }
Exemplo 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")
     });
Exemplo n.º 10
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")
            });
Exemplo n.º 11
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)));
        }
Exemplo n.º 12
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)
            }));
        }
Exemplo n.º 13
0
        public async Task <ActionResult <IEnumerable <Account> > > Get(
            AccountTypeParameter type,
            ContractKindParameter kind,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "balance", "firstActivity", "lastActivity", "numTransactions", "numContracts"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            #region optimize
            if (kind?.Eq != null && type == null)
            {
                type = new AccountTypeParameter {
                    Eq = 2
                }
            }
            ;
            #endregion

            if (select == null)
            {
                return(Ok(await Accounts.Get(type, kind, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Accounts.Get(type, kind, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
Exemplo n.º 14
0
 public async Task <IEnumerable <Software> > Get(SortParameter sort, OffsetParameter offset, int limit)
 {
     var sql = new SqlBuilder(@"SELECT * FROM ""Software""")
               .Take(sort, offset, limit, x => x switch
     {
         "firstLevel" => ("FirstLevel", "FirstLevel"),
         "lastLevel" => ("LastLevel", "LastLevel"),
         "blocksCount" => ("BlocksCount", "BlocksCount"),
         _ => ("Id", "Id")
     });
Exemplo n.º 15
0
 public async Task <IEnumerable <Protocol> > Get(SortParameter sort, OffsetParameter offset, int limit)
 {
     var sql = new SqlBuilder(@"SELECT * FROM ""Protocols""")
               .Take(sort, offset, limit, x => x switch
     {
         "code" => ("Id", "Code"),
         "firstLevel" => ("Id", "FirstLevel"),
         "lastLevel" => ("Id", "LastLevel"),
         _ => ("Id", "Id")
     });
Exemplo n.º 16
0
        public async Task <object[]> GetPeriods(SortParameter sort, OffsetParameter offset, int limit, string field)
        {
            var columns = new HashSet <string>(1);

            switch (field)
            {
            case "kind": columns.Add(@"""Kind"""); break;

            case "firstLevel": columns.Add(@"""StartLevel"""); break;

            case "lastLevel": columns.Add(@"""EndLevel"""); break;
            }

            if (columns.Count == 0)
            {
                return(Array.Empty <object>());
            }

            var sql = new SqlBuilder($@"SELECT {string.Join(',', columns)} FROM ""VotingPeriods""")
                      .Take(sort, offset, limit, x => ("Id", "Id"));

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

            //TODO: optimize memory allocation
            var result = new object[rows.Count()];
            var j      = 0;

            switch (field)
            {
            case "kind":
                foreach (var row in rows)
                {
                    result[j++] = KindToString(row.Kind);
                }
                break;

            case "firstLevel":
                foreach (var row in rows)
                {
                    result[j++] = row.StartLevel;
                }
                break;

            case "lastLevel":
                foreach (var row in rows)
                {
                    result[j++] = row.EndLevel;
                }
                break;
            }

            return(result);
        }
Exemplo n.º 17
0
 public async Task <IEnumerable <Block> > Get(SortParameter sort, OffsetParameter offset, int limit)
 {
     var sql = new SqlBuilder(@"SELECT ""Level"", ""Hash"", ""Timestamp"", ""ProtoCode"", ""Priority"", ""Validations"", ""Operations"", ""Reward"", ""Fees"", ""BakerId"", ""RevelationId"" FROM ""Blocks""")
               .Take(sort, offset, limit, x => x switch
     {
         "level" => ("Id", "Level"),
         "priority" => ("Priority", "Priority"),
         "validations" => ("Validations", "Validations"),
         "reward" => ("Reward", "Reward"),
         "fees" => ("Fees", "Fees"),
         _ => ("Id", "Id")
     });
Exemplo n.º 18
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)
                    }));
                }
            }
        }
Exemplo n.º 19
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)
                    }));
                }
            }
        }
Exemplo n.º 20
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)
                    }));
                }
            }
        }
Exemplo n.º 21
0
        public async Task <ActionResult <IEnumerable <BigMapKeyHistorical> > > GetHistoricalKeys(
            [Min(0)] int id,
            [Min(0)] int level,
            bool?active,
            JsonParameter key,
            JsonParameter value,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            MichelineFormat micheline   = MichelineFormat.Json)
        {
            #region validate
            if (sort != null && !sort.Validate("id"))
            {
                return(new BadRequest(nameof(sort), "Sorting by the specified field is not allowed."));
            }
            #endregion

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

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Values[0], micheline)));
                }
                else
                {
                    return(Ok(await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Values, micheline)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Fields[0], micheline)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await BigMaps.GetHistoricalKeys(id, level, active, key, value, sort, offset, limit, select.Fields, micheline)
                    }));
                }
            }
        }
Exemplo n.º 22
0
        public async Task <ActionResult <IEnumerable <VotingEpoch> > > GetEpochs(
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            return(Ok(await Voting.GetEpochs(sort, offset, limit)));
        }
Exemplo n.º 23
0
        public async Task <ActionResult <IEnumerable <Protocol> > > Get(
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "code", "firstLevel", "lastLevel"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            return(Ok(await Protocols.Get(sort, offset, limit)));
        }
Exemplo n.º 24
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")
     });
Exemplo n.º 25
0
        public async Task <ActionResult <IEnumerable <VoterSnapshot> > > GetPeriodVoters(
            VoterStatusParameter status,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "rolls"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            return(Ok(await Voting.GetVoters(State.Current.VotingPeriod, status, sort, offset, limit)));
        }
Exemplo n.º 26
0
        public async Task <ActionResult <IEnumerable <RelatedContract> > > GetContracts(
            [Address] string address,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("id", "balance"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            return(Ok(await Accounts.GetRelatedContracts(address, sort, offset, limit)));
        }
Exemplo n.º 27
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")
     });
Exemplo n.º 28
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)
                    }));
                }
            }
        }
Exemplo n.º 29
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)
                    }));
                }
            }
        }
Exemplo n.º 30
0
        public async Task <ActionResult <IEnumerable <Commitment> > > Get(
            bool?activated,
            Int32NullParameter activationLevel,
            Int64Parameter balance,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (sort != null && !sort.Validate("activationLevel", "balance"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Commitments.Get(activated, activationLevel, balance, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }