public override Result QueryFeature(FeatureQuery query)
        {
            if (query.Action == LastTransactionInfoAction)
            {
                return(GetAccountData <PreviousAccountTransactionContainer>(query, 0, (container) =>
                {
                    return new PackableResult(container?.LastTransactionInfo ?? LastTransactionCountInfo.Empty);
                }));
            }
            else if (query.Action == LastTransactionInfoBatchAction)
            {
                return(GetBatchData <long>(query, 0, (u, l) => u.Unpack(l), (accountIds) =>
                {
                    var batchResult = new LastTransactionCountInfoBatch();

                    foreach (var accountId in accountIds)
                    {
                        var account = CurrentChain.GetFeatureAccount(accountId);
                        var info = account?.GetFeatureContainer <PreviousAccountTransactionContainer>(FeatureId)?.LastTransactionInfo ?? LastTransactionCountInfo.Empty;

                        batchResult.Add(account != null, accountId, info);
                    }

                    return new PackableResult(batchResult);
                }));
            }

            return(Result.InvalidQuery);
        }
예제 #2
0
 public override Result QueryFeature(FeatureQuery query)
 {
     if (query.GetLong(0, out var accountId))
     {
         var account = CurrentChain.GetFeatureAccount(accountId);
         if (account != null)
         {
             var container = account.GetFeatureContainer <FanContainer>(FeatureId);
             if (container != null)
             {
                 var action = query.Action;
                 if (action == FansAction)
                 {
                     return(new PackableResult(container.GetFans()));
                 }
                 else if (action == FanOfAction)
                 {
                     return(new PackableResult(container.GetFanOf()));
                 }
                 else if (action == FansLastTransactionInfoAction)
                 {
                     return(new PackableResult(container.LastFansTransactionInfo));
                 }
                 else if (action == FanOfLastTransactionInfoAction)
                 {
                     return(new PackableResult(container.LastFanOfTransactionInfo));
                 }
             }
             return(Result.DataNotFound);
         }
         return(Result.AccountNotFound);
     }
     return(Result.InvalidQuery);
 }
예제 #3
0
        public override Result QueryFeature(FeatureQuery query)
        {
            if (query.GetLong(0, out var groupId))
            {
                var groupInfo = _handler.GetGroupInfo(groupId);
                if (groupInfo == null)
                {
                    return(Result.DataNotFound);
                }

                var action = query.Action;

                if (action == LastTransactionInfoAction)
                {
                    return(new PackableResult(groupInfo.LastTransactionInfo));
                }
                else if (action == IndexLastTransactionInfoAction)
                {
                    if (query.GetString(1, out var indexHex))
                    {
                        var index = new Chain.Index(indexHex);
                        return(new PackableResult(groupInfo.GetLastGroupIndexTransactionInfo(index, true)));
                    }
                }
            }

            return(Result.InvalidQuery);
        }
예제 #4
0
        protected Result GetAccountData <T>(FeatureQuery query, int queryIndex, Func <T, Result> handle) where T : FeatureAccountContainer
        {
            if (query.GetLong(queryIndex, out var accountId))
            {
                var account = CurrentChain.GetFeatureAccount(accountId);
                if (account != null)
                {
                    var container = account.GetFeatureContainer <T>(FeatureId);
                    return(handle?.Invoke(container));
                }

                return(Result.AccountNotFound);
            }

            return(Result.InvalidQuery);
        }
예제 #5
0
        public override Result QueryFeature(FeatureQuery query)
        {
            if (query.Action == LastTransactionInfoAction)
            {
                if (query.GetLong(0, out var transactionId))
                {
                    var targetInfo = _chainHandler.GetTransactionTargetInfo(transactionId);
                    if (targetInfo != null)
                    {
                        return(new PackableResult(targetInfo.LastTransactionInfo));
                    }

                    return(Result.DataNotFound);
                }
            }

            return(Result.InvalidQuery);
        }
예제 #6
0
        public override Result QueryFeature(FeatureQuery query)
        {
            var action = query.Action;

            if (action == FriendInfoAction)
            {
                return(GetAccountData <FriendContainer>(query, 0, (container) =>
                {
                    if (container != null)
                    {
                        return new PackableResult(container.GetFriendInfo());
                    }

                    return Result.DataNotFound;
                }));
            }

            return(Result.InvalidQuery);
        }
예제 #7
0
        public override Result QueryFeature(FeatureQuery query)
        {
            var action = query.Action;

            if (action == GroupsAction)
            {
                return(GetAccountData <GroupAdministrationContainer>(query, 0, (container) =>
                {
                    if (container != null)
                    {
                        return new LongArrayResult(container.GetGroups());
                    }

                    return Result.DataNotFound;
                }));
            }
            else if (query.GetLong(0, out var groupId))
            {
                var groupInfo = _handler.GetGroupInfo(groupId);
                if (groupInfo == null)
                {
                    return(Result.DataNotFound);
                }

                if (action == AccountsAction)
                {
                    return(new GroupUsersResult(groupInfo.GetAccounts()));
                }
                else if (action == PendingAccountsAction)
                {
                    return(new GroupUsersResult(groupInfo.GetPendingAccounts()));
                }
                else if (action == AdministrationLastTransactionInfoAction)
                {
                    return(new PackableResult(groupInfo.AdministrationLastTransactionInfo));
                }
            }

            return(Result.InvalidQuery);
        }
예제 #8
0
        protected Result GetBatchData <T>(FeatureQuery query, int queryIndex, Action <Unpacker, List <T> > unpack, Func <IReadOnlyList <T>, Result> handle)
        {
            if (query.GetString(queryIndex, out var hexString))
            {
                var list = new List <T>();
                if (HexPacker.FromHex(hexString, (unpacker) =>
                {
                    var count = unpacker.UnpackUshort();
                    if (count > MaxBatchSize)
                    {
                        throw new ArgumentOutOfRangeException();
                    }

                    unpacker.Position -= 2;
                    unpack.Invoke(unpacker, list);
                }))
                {
                    return(handle.Invoke(list));
                }
            }

            return(Result.InvalidQuery);
        }
예제 #9
0
 public abstract Result QueryFeature(FeatureQuery query);
예제 #10
0
        public override Result QueryFeature(FeatureQuery query)
        {
            if (query.Action == LastTransactionInfoAction)
            {
                if (query.GetString(1, out var indexHex))
                {
                    var index = new Chain.Index(indexHex);
                    return(GetAccountData <AccountIndexContainerBase>(query, 0, (container) =>
                    {
                        return new PackableResult(container?.GetLastTransactionInfo(index) ?? LastTransactionCountInfo.Empty);
                    }));
                }
            }
            else if (query.Action == LastTransactionInfoBatchAction)
            {
                if (query.GetString(1, out var indexHex))
                {
                    var index = new Chain.Index(indexHex);

                    return(GetBatchData <long>(query, 0, (u, l) => u.Unpack(l), (accountIds) =>
                    {
                        var batchResult = new LastTransactionCountInfoBatch();

                        foreach (var accountId in accountIds)
                        {
                            var account = CurrentChain.GetFeatureAccount(accountId);
                            var info = account?.GetFeatureContainer <AccountIndexContainerBase>(FeatureId)?.GetLastTransactionInfo(index) ?? LastTransactionCountInfo.Empty;

                            batchResult.Add(info != null, accountId, info);
                        }

                        return new PackableResult(batchResult);
                    }));
                }
            }
            else if (query.Action == LastTransactionInfoIndicesBatchAction)
            {
                if (query.GetLong(0, out var accountId) && query.GetString(1, out var indicesHex))
                {
                    return(GetBatchData <Chain.Index>(query, 1, (unpacker, list) => unpacker.Unpack(list, (u) => new Chain.Index(u)), (indices) =>
                    {
                        var account = CurrentChain.GetFeatureAccount(accountId);
                        var container = account?.GetFeatureContainer <AccountIndexContainerBase>(FeatureId);

                        if (account != null)
                        {
                            var batchResult = new LastTransactionCountInfoBatch();

                            foreach (var index in indices)
                            {
                                var info = container?.GetLastTransactionInfo(index);
                                batchResult.Add(info != null, accountId, info);
                            }

                            return new PackableResult(batchResult);
                        }

                        return Result.AccountNotFound;
                    }));
                }
            }

            return(Result.InvalidQuery);
        }