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.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);
        }