Exemplo n.º 1
0
        public async Task <ActionResult <IEnumerable <Block> > > Get(
            AccountParameter baker,
            Int32Parameter level,
            DateTimeParameter timestamp,
            Int32Parameter priority,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            Symbols quote = Symbols.None)
        {
            #region validate
            if (baker != null)
            {
                if (baker.Eqx != null)
                {
                    return(new BadRequest($"{nameof(baker)}.eqx", "This parameter doesn't support .eqx mode."));
                }

                if (baker.Nex != null)
                {
                    return(new BadRequest($"{nameof(baker)}.nex", "This parameter doesn't support .nex mode."));
                }

                if (baker.Eq == -1 || baker.In?.Count == 0)
                {
                    return(Ok(Enumerable.Empty <OriginationOperation>()));
                }
            }

            if (sort != null && !sort.Validate("id", "level", "priority", "validations", "reward", "fees"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

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

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Values[0], quote)));
                }
                else
                {
                    return(Ok(await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Values, quote)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Fields[0], quote)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Blocks.Get(baker, level, timestamp, priority, sort, offset, limit, select.Fields, quote)
                    }));
                }
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <IEnumerable <Account> > > Get(
            AccountTypeParameter type,
            ContractKindParameter kind,
            AccountParameter @delegate,
            Int64Parameter balance,
            BoolParameter staked,
            Int32Parameter lastActivity,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100)
        {
            #region validate
            if (@delegate != null)
            {
                if (@delegate.Eqx != null)
                {
                    return(new BadRequest($"{nameof(@delegate)}.eqx", "This parameter doesn't support .eqx mode."));
                }

                if (@delegate.Nex != null)
                {
                    return(new BadRequest($"{nameof(@delegate)}.nex", "This parameter doesn't support .nex mode."));
                }

                if (@delegate.Eq == -1 || @delegate.In?.Count == 0)
                {
                    return(Ok(Enumerable.Empty <Account>()));
                }
            }

            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, @delegate, balance, staked, lastActivity, sort, offset, limit)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values[0])));
                }
                else
                {
                    return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields[0])));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields)
                    }));
                }
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult <IEnumerable <Contract> > > Get(
            ContractKindParameter kind,
            AccountParameter creator,
            AccountParameter manager,
            AccountParameter @delegate,
            Int32Parameter lastActivity,
            SelectParameter select,
            SortParameter sort,
            OffsetParameter offset,
            [Range(0, 10000)] int limit = 100,
            bool includeStorage         = false)
        {
            #region validates
            if (creator != null)
            {
                if (creator.Eqx != null && creator.Eqx != "manager" && creator.Eqx != "delegate")
                {
                    return(new BadRequest($"{nameof(creator)}.eqx", "The 'creator' field can be compared with the 'manager' or 'delegate' field only."));
                }

                if (creator.Nex != null && creator.Nex != "manager" && creator.Nex != "delegate")
                {
                    return(new BadRequest($"{nameof(creator)}.nex", "The 'creator' field can be compared with the 'manager' or 'delegate' field only."));
                }

                if (creator.Eq == -1 || creator.In?.Count == 0)
                {
                    return(Ok(Enumerable.Empty <Contract>()));
                }
            }

            if (manager != null)
            {
                if (manager.Eqx != null && manager.Eqx != "creator" && manager.Eqx != "delegate")
                {
                    return(new BadRequest($"{nameof(manager)}.eqx", "The 'manager' field can be compared with the 'creator' or 'delegate' field only."));
                }

                if (manager.Nex != null && manager.Nex != "creator" && manager.Nex != "delegate")
                {
                    return(new BadRequest($"{nameof(manager)}.nex", "The 'manager' field can be compared with the 'creator' or 'delegate' field only."));
                }

                if (manager.Eq == -1 || manager.In?.Count == 0)
                {
                    return(Ok(Enumerable.Empty <Contract>()));
                }
            }

            if (@delegate != null)
            {
                if (@delegate.Eqx != null && @delegate.Eqx != "creator" && @delegate.Eqx != "manager")
                {
                    return(new BadRequest($"{nameof(@delegate)}.eqx", "The 'delegate' field can be compared with the 'creator' or 'manager' field only."));
                }

                if (@delegate.Nex != null && @delegate.Nex != "creator" && @delegate.Nex != "manager")
                {
                    return(new BadRequest($"{nameof(@delegate)}.nex", "The 'delegate' field can be compared with the 'creator' or 'manager' field only."));
                }

                if (@delegate.Eq == -1 || @delegate.In?.Count == 0)
                {
                    return(Ok(Enumerable.Empty <Contract>()));
                }
            }

            if (sort != null && !sort.Validate("id", "balance", "firstActivity", "lastActivity", "numTransactions"))
            {
                return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed."));
            }
            #endregion

            if (select == null)
            {
                return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, includeStorage)));
            }

            if (select.Values != null)
            {
                if (select.Values.Length == 1)
                {
                    return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Values[0], includeStorage)));
                }
                else
                {
                    return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Values, includeStorage)));
                }
            }
            else
            {
                if (select.Fields.Length == 1)
                {
                    return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Fields[0], includeStorage)));
                }
                else
                {
                    return(Ok(new SelectionResponse
                    {
                        Cols = select.Fields,
                        Rows = await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Fields, includeStorage)
                    }));
                }
            }
        }