Beispiel #1
0
        public IEnumerable <FilterLog> GetLogs(
            BlockParameter fromBlock,
            BlockParameter toBlock,
            object address = null,
            IEnumerable <object> topics         = null,
            CancellationToken cancellationToken = default)
        {
            LogFilter filter = _filterStore.CreateLogFilter(fromBlock, toBlock, address, topics, false);

            return(_logFinder.FindLogs(filter, cancellationToken));
        }
        public IEnumerable <FilterLog> GetLogs(BlockParameter fromBlock, BlockParameter toBlock, object address = null,
                                               IEnumerable <object> topics = null)
        {
            LogFilter filter = _filterStore.CreateLogFilter(fromBlock, toBlock, address, topics, false);

            return(_logFinder.FindLogs(filter));
        }
Beispiel #3
0
        public FilterLog[] GetLogs(FilterBlock fromBlock, FilterBlock toBlock, object address = null,
                                   IEnumerable <object> topics = null)
        {
            LogFilter filter = _filterStore.CreateLogFilter(fromBlock, toBlock, address, topics, false);

            return(_logFinder.FindLogs(filter));
        }
Beispiel #4
0
        private BaselineTree RebuildEntireTree(Address treeAddress, Keccak blockHash)
        {
            // bad

            Keccak    leavesTopic        = new Keccak("0x8ec50f97970775682a68d3c6f9caedf60fd82448ea40706b8b65d6c03648b922");
            LogFilter insertLeavesFilter = new LogFilter(
                0,
                new BlockParameter(0L),
                new BlockParameter(blockHash),
                new AddressFilter(treeAddress),
                new TopicsFilter(new SpecificTopic(leavesTopic)));

            Keccak    leafTopic        = new Keccak("0x6a82ba2aa1d2c039c41e6e2b5a5a1090d09906f060d32af9c1ac0beff7af75c0");
            LogFilter insertLeafFilter = new LogFilter(
                0,
                new BlockParameter(0L),
                new BlockParameter(blockHash),
                new AddressFilter(treeAddress),
                new TopicsFilter(new SpecificTopic(leafTopic))); // find tree topics

            var          insertLeavesLogs = _logFinder.FindLogs(insertLeavesFilter);
            var          insertLeafLogs   = _logFinder.FindLogs(insertLeafFilter);
            BaselineTree baselineTree     = new ShaBaselineTree(new MemDb(), Array.Empty <byte>(), 5);

            // Keccak leafTopic = new Keccak("0x8ec50f97970775682a68d3c6f9caedf60fd82448ea40706b8b65d6c03648b922");
            foreach (FilterLog filterLog in insertLeavesLogs
                     .Union(insertLeafLogs)
                     .OrderBy(fl => fl.BlockNumber).ThenBy(fl => fl.LogIndex))
            {
                if (filterLog.Data.Length == 96)
                {
                    Keccak leafHash = new Keccak(filterLog.Data.Slice(32, 32).ToArray());
                    baselineTree.Insert(leafHash);
                }
                else
                {
                    for (int i = 0; i < (filterLog.Data.Length - 128) / 32; i++)
                    {
                        Keccak leafHash = new Keccak(filterLog.Data.Slice(128 + 32 * i, 32).ToArray());
                        baselineTree.Insert(leafHash);
                    }
                }
            }

            return(baselineTree);
        }
Beispiel #5
0
        private BaselineTree RebuildEntireTree(Address treeAddress)
        {
            // bad

            Keccak    leavesTopic        = new Keccak("0x8ec50f97970775682a68d3c6f9caedf60fd82448ea40706b8b65d6c03648b922");
            LogFilter insertLeavesFilter = new LogFilter(
                0,
                new BlockParameter(0L),
                new BlockParameter(_blockFinder.Head.Number),
                new AddressFilter(treeAddress),
                new TopicsFilter(new SpecificTopic(leavesTopic)));

            Keccak    leafTopic        = new Keccak("0x6a82ba2aa1d2c039c41e6e2b5a5a1090d09906f060d32af9c1ac0beff7af75c0");
            LogFilter insertLeafFilter = new LogFilter(
                0,
                new BlockParameter(0L),
                new BlockParameter(_blockFinder.Head.Number),
                new AddressFilter(treeAddress),
                new TopicsFilter(new SpecificTopic(leafTopic))); // find tree topics

            var          insertLeavesLogs = _logFinder.FindLogs(insertLeavesFilter);
            var          insertLeafLogs   = _logFinder.FindLogs(insertLeafFilter);
            BaselineTree baselineTree     = new ShaBaselineTree(new MemDb(), new byte[0], 5);

            // Keccak leafTopic = new Keccak("0x8ec50f97970775682a68d3c6f9caedf60fd82448ea40706b8b65d6c03648b922");
            foreach (FilterLog filterLog in insertLeavesLogs)
            {
                for (int i = 0; i < (filterLog.Data.Length - 128) / 32; i++)
                {
                    Bytes32 leafHash = Bytes32.Wrap(filterLog.Data.Slice(128 + 32 * i, 32).ToArray());
                    baselineTree.Insert(leafHash);
                }
            }

            foreach (FilterLog filterLog in insertLeafLogs)
            {
                Bytes32 leafHash = Bytes32.Wrap(filterLog.Data.Slice(32, 32).ToArray());
                baselineTree.Insert(leafHash);
            }

            return(baselineTree);
        }
Beispiel #6
0
        public ValueTask <ResultWrapper <DepositData[]> > deposit_getAll()
        {
            ResultWrapper <DepositData[]> result;

            if (_depositContract == null)
            {
                result = ResultWrapper <DepositData[]> .Fail("Deposit contract address not specified.", ErrorCodes.InternalError);

                return(new ValueTask <ResultWrapper <DepositData[]> >(result));
            }

            var logFilter = new LogFilter(
                1,
                new BlockParameter(0L),
                BlockParameter.Latest,
                new AddressFilter(_depositContract.ContractAddress),
                new TopicsFilter(new SpecificTopic(_depositContract.DepositEventHash)));

            var logs = _logFinder.FindLogs(logFilter);
            List <DepositData> allData = new List <DepositData>();

            foreach (FilterLog filterLog in logs)
            {
                DepositData depositData = new DepositData();
                depositData.LogIndex              = filterLog.LogIndex;
                depositData.TxIndex               = filterLog.TransactionIndex;
                depositData.BlockNumber           = filterLog.BlockNumber;
                depositData.Amount                = filterLog.Data.Slice(352, 8);
                depositData.PubKey                = filterLog.Data.Slice(192, 48);
                depositData.WithdrawalCredentials = filterLog.Data.Slice(288, 32);
                depositData.BlsSignature          = filterLog.Data.Slice(416, 96);
                allData.Add(depositData);
            }

            // foreach log

            result = ResultWrapper <DepositData[]> .Success(allData.ToArray());

            return(new ValueTask <ResultWrapper <DepositData[]> >(result));
        }
Beispiel #7
0
        public BaselineTree BuildTree(BaselineTree baselineTree, Address treeAddress, BlockParameter blockFrom, BlockParameter blockTo)
        {
            if (_logger.IsWarn)
            {
                _logger.Warn($"Build {baselineTree} from {blockFrom} to {blockTo}");
            }

            var       initCount          = baselineTree.Count;
            LogFilter insertLeavesFilter = new LogFilter(
                0,
                blockFrom,
                blockTo,
                new AddressFilter(treeAddress),
                new SequenceTopicsFilter(new SpecificTopic(BaselineModule.LeavesTopic)));

            LogFilter insertLeafFilter = new LogFilter(
                0,
                blockFrom,
                blockTo,
                new AddressFilter(treeAddress),
                new SequenceTopicsFilter(new SpecificTopic(BaselineModule.LeafTopic)));

            var insertLeavesLogs = _logFinder.FindLogs(insertLeavesFilter);
            var insertLeafLogs   = _logFinder.FindLogs(insertLeafFilter);

            long?currentBlockNumber = null;
            uint count = 0;

            using var batch = baselineTree.StartBatch();
            foreach (FilterLog filterLog in insertLeavesLogs
                     .Union(insertLeafLogs)
                     .OrderBy(fl => fl.BlockNumber).ThenBy(fl => fl.LogIndex))
            {
                if (filterLog.BlockHash == baselineTree.LastBlockDbHash)
                {
                    continue;
                }
                if (currentBlockNumber == null)
                {
                    currentBlockNumber = filterLog.BlockNumber;
                }

                if (currentBlockNumber != filterLog.BlockNumber)
                {
                    baselineTree.MemorizePastCount(currentBlockNumber.Value, count);
                    currentBlockNumber = filterLog.BlockNumber;
                }

                if (filterLog.Data.Length == 96)
                {
                    Keccak leafHash = new Keccak(filterLog.Data.Slice(32, 32).ToArray());

                    if (_logger.IsWarn)
                    {
                        _logger.Warn($"Inserting leaf into {baselineTree} in block {currentBlockNumber}");
                    }
                    baselineTree.Insert(leafHash, false);
                    ++count;
                }
                else
                {
                    for (int i = 0; i < (filterLog.Data.Length - 128) / 32; i++)
                    {
                        Keccak leafHash = new Keccak(filterLog.Data.Slice(128 + 32 * i, 32).ToArray());
                        if (_logger.IsWarn)
                        {
                            _logger.Warn($"Inserting leaf {i} into {baselineTree} in block {currentBlockNumber}");
                        }
                        baselineTree.Insert(leafHash, false);
                        ++count;
                    }
                }
            }

            if (currentBlockNumber != null && count != 0)
            {
                baselineTree.MemorizePastCount(currentBlockNumber.Value, baselineTree.Count);
            }

            baselineTree.CalculateHashes(initCount);
            return(baselineTree);
        }