internal static FFIResult create_many_channel_monitor(
            InstallWatchTx installWatchTx,
            InstallWatchOutPoint installWatchOutPoint,
            WatchAllTxn watchAllTxn,
            GetChainUtxo getChainUtxo,
            FilterBlock filterBlock,
            ReEntered reEntered,

            BroadcastTransaction broadcastTransaction,
            Log log,
            GetEstSatPer1000Weight getEstSatPer1000Weight,
            out ManyChannelMonitorHandle handle,
            bool check = true
            ) =>
        MaybeCheck(_create_many_channel_monitor(
                       ref installWatchTx,
                       ref installWatchOutPoint,
                       ref watchAllTxn,
                       ref getChainUtxo,
                       ref filterBlock,
                       ref reEntered,
                       ref broadcastTransaction,
                       ref log,
                       ref getEstSatPer1000Weight,
                       out handle
                       ), check);
예제 #2
0
        public async Task TestTryReceive()
        {
            var inputBlock = new BufferBlock <int>();
            var testBlock  = new FilterBlock <int>(x => x % 2 != 0);

            inputBlock.LinkWithCompletion(testBlock);

            for (var i = 1; i <= 6; i++)
            {
                inputBlock.Post(i);
            }

            await Task.Delay(TestUtils.SometimeSoon);

            testBlock.TryReceive(out var item).IsTrue();
            item.Is(1);

            await Task.Delay(TestUtils.SometimeSoon);

            testBlock.TryReceive(out item).IsTrue();
            item.Is(3);

            await Task.Delay(TestUtils.SometimeSoon);

            testBlock.TryReceive(out item).IsTrue();
            item.Is(5);

            await Task.Delay(TestUtils.SometimeSoon);

            testBlock.TryReceive(out item).IsFalse();
        }
예제 #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));
        }
예제 #4
0
        internal static unsafe FFIResult create_peer_manager(
            IntPtr seed,
            UserConfig *userConfig,

            ChannelManagerHandle channelManagerHandle,
            InstallWatchTx installWatchTx,
            InstallWatchOutPoint installWatchOutPoint,
            WatchAllTxn watchAllTxn,
            GetChainUtxo getChainUtxo,
            FilterBlock filterBlock,
            ReEntered reEntered,

            Log log,

            IntPtr ourNodeSecret,
            out PeerManagerHandle handle,
            bool check = true
            ) =>
        MaybeCheck(_create_peer_manager(
                       seed,
                       userConfig,
                       channelManagerHandle,
                       ref installWatchTx,
                       ref installWatchOutPoint,
                       ref watchAllTxn,
                       ref getChainUtxo,
                       ref filterBlock,
                       ref reEntered,

                       ref log,
                       ourNodeSecret,
                       out handle),
                   check);
예제 #5
0
 public void Correctly_creates_topics_filter(IEnumerable <object> topics)
 {
     FilterBlock from   = new FilterBlock(100);
     FilterBlock to     = new FilterBlock(FilterBlockType.Latest);
     FilterStore store  = new FilterStore();
     LogFilter   filter = store.CreateLogFilter(from, to, null, topics);
 }
예제 #6
0
        public ResultWrapper <BigInteger?> eth_newFilter(Filter filter)
        {
            FilterBlock fromBlock = MapFilterBlock(filter.FromBlock);
            FilterBlock toBlock   = MapFilterBlock(filter.ToBlock);
            int         filterId  = _blockchainBridge.NewFilter(fromBlock, toBlock, filter.Address, filter.Topics);

            return(ResultWrapper <BigInteger?> .Success(filterId));
        }
예제 #7
0
        public ResultWrapper <UInt256?> eth_newFilter(Filter filter)
        {
            FilterBlock fromBlock = filter.FromBlock.ToFilterBlock();
            FilterBlock toBlock   = filter.ToBlock.ToFilterBlock();
            int         filterId  = _blockchainBridge.NewFilter(fromBlock, toBlock, filter.Address, filter.Topics);

            return(ResultWrapper <UInt256?> .Success((UInt256)filterId));
        }
예제 #8
0
        public int NewFilter(FilterBlock fromBlock, FilterBlock toBlock,
                             object address = null, IEnumerable <object> topics = null)
        {
            LogFilter filter = _filterStore.CreateLogFilter(fromBlock, toBlock, address, topics);

            _filterStore.SaveFilter(filter);
            return(filter.Id);
        }
 static extern FFIResult _create_block_notifier(
     ref InstallWatchTx installWatchTx,
     ref InstallWatchOutPoint installWatchOutPoint,
     ref WatchAllTxn watchAllTxn,
     ref GetChainUtxo getChainUtxo,
     ref FilterBlock filterBlock,
     ref ReEntered reEntered,
     out BlockNotifierHandle handle
     );
예제 #10
0
        public ResultWrapper <IEnumerable <FilterLog> > eth_getLogs(Filter filter)
        {
            FilterBlock fromBlock = filter.FromBlock.ToFilterBlock();
            FilterBlock toBlock   = filter.ToBlock.ToFilterBlock();

            return(ResultWrapper <IEnumerable <FilterLog> > .Success(_blockchainBridge.GetLogs(fromBlock, toBlock,
                                                                                               filter.Address,
                                                                                               filter.Topics)));
        }
예제 #11
0
        public void Correctly_creates_address_filter(object address, AddressFilter expected)
        {
            FilterBlock from   = new FilterBlock(100);
            FilterBlock to     = new FilterBlock(FilterBlockType.Latest);
            FilterStore store  = new FilterStore();
            LogFilter   filter = store.CreateLogFilter(from, to, address);

            filter.AddressFilter.Should().BeEquivalentTo(expected);
        }
예제 #12
0
        /// <summary>
        /// Creates a new instance of <see cref="FlowIndex"/>.
        /// </summary>
        /// <param name="blockCapacity">Desired block capacity. Block capacity influences the size of the Bloom filter in the following way: filterCapacity = blockCapacity / packetFlowRatio</param>
        /// <param name="packetFlowRatio">Expected ratio between packets and flows. For instance, if an average flow contains 10 packets that this ratio would be 10.</param>
        /// <param name="linkType">The type of link layer.</param>
        public FlowIndex(int blockCapacity, int packetFlowRatio, int linkType)
        {
            m_blockCapacity   = blockCapacity;
            m_packetFlowRatio = packetFlowRatio;
            m_linkType        = linkType;

            m_filterArray = new List <FilterBlock>();
            m_lastBlock   = null;
        }
 internal static FFIResult create_block_notifier(
     InstallWatchTx installWatchTx,
     InstallWatchOutPoint installWatchOutPoint,
     WatchAllTxn watchAllTxn,
     GetChainUtxo getChainUtxo,
     FilterBlock filterBlock,
     ReEntered reEntered,
     out BlockNotifierHandle handle,
     bool check = true
     ) => MaybeCheck(_create_block_notifier(ref installWatchTx, ref installWatchOutPoint, ref watchAllTxn, ref getChainUtxo, ref filterBlock, ref reEntered, out handle), check);
예제 #14
0
            protected internal override void VisitFilterBlock(FilterBlock node, object data)
            {
                StackTypes stack = data as StackTypes;

                if (stack.Count != 0)
                {
                    throw new VerifierException();
                }

                stack.Push(typeof(object));
                AddTask(node.Next, stack);
            }
        private static extern FFIResult _create_many_channel_monitor(
            ref InstallWatchTx installWatchTx,
            ref InstallWatchOutPoint installWatchOutPoint,
            ref WatchAllTxn watchAllTxn,
            ref GetChainUtxo getChainUtxo,
            ref FilterBlock filterBlock,
            ref ReEntered reEntered,

            ref BroadcastTransaction broadcastTransaction,
            ref Log log,
            ref GetEstSatPer1000Weight getEstSatPer1000Weight,
            out ManyChannelMonitorHandle handle
            );
예제 #16
0
 public void Add(int packetNumber, long packetOffset, FlowKey flowkey)
 {
     if (m_lastBlock == null)
     {
         var filterCapacity = m_blockCapacity / m_packetFlowRatio;
         m_lastBlock = new FilterBlock(m_blockCapacity, filterCapacity, m_linkType, packetOffset);
         m_filterArray.Add(m_lastBlock);
     }
     m_lastBlock.Add(flowkey);
     if (m_lastBlock.IsFull)
     {
         m_lastBlock = null;
     }
 }
예제 #17
0
        protected void SiftBlocks(Block node, object data)
        {
            BasicBlock basicBlock = data as BasicBlock;

            basicBlock.AddNode(node);

            if (node is ProtectedBlock)
            {
                foreach (EHBlock block in (node as ProtectedBlock))
                {
                    if (block.Options.ContainsOption(BasicBlock.BASIC_BLOCK_OPTION))
                    {
                        basicBlock.AddLink(block.Options[BasicBlock.BASIC_BLOCK_OPTION] as BasicBlock);
                    }
                    else
                    {
                        BasicBlock newBlock = createBasicBlock();
                        basicBlock.AddLink(newBlock);
                        AddTask(block, newBlock);
                    }
                }
            }
            else if (node is UserFilteredBlock)
            {
                FilterBlock block = (node as UserFilteredBlock).Filter;

                if (block.Options.ContainsOption(BasicBlock.BASIC_BLOCK_OPTION))
                {
                    basicBlock.AddLink(block.Options[BasicBlock.BASIC_BLOCK_OPTION] as BasicBlock);
                }
                else
                {
                    BasicBlock newBlock = createBasicBlock();
                    basicBlock.AddLink(newBlock);
                    AddTask(block, newBlock);
                }
            }

            if (node.Next.Options.ContainsOption(BasicBlock.BASIC_BLOCK_OPTION))
            {
                basicBlock.AddNextBasicBlock(node.Next.Options[BasicBlock.BASIC_BLOCK_OPTION] as BasicBlock);
            }
            else
            {
                BasicBlock nextBlock = createBasicBlock();
                basicBlock.AddNextBasicBlock(nextBlock);
                AddTask(node.Next, nextBlock);
            }
        }
예제 #18
0
        public async Task TestCompleteAndCancelSending()
        {
            var testBlock = new FilterBlock <int>(x => x % 2 != 0, new ExecutionDataflowBlockOptions()
            {
                BoundedCapacity = 1
            });

            testBlock.Post(1).IsTrue();

            var sendTask = testBlock.SendAsync(2);
            await sendTask.NeverComplete();

            testBlock.Complete();

            (await sendTask.CompleteSoon()).IsFalse();
        }
예제 #19
0
        private static extern unsafe FFIResult _create_peer_manager(
            IntPtr seedPtr,
            UserConfig *userConfig,

            ChannelManagerHandle channelManagerHandle,
            ref InstallWatchTx installWatchTx,
            ref InstallWatchOutPoint installWatchOutPoint,
            ref WatchAllTxn watchAllTxn,
            ref GetChainUtxo getChainUtxo,
            ref FilterBlock filterBlock,
            ref ReEntered reEntered,

            ref Log log,

            IntPtr ourNodeSecret,
            out PeerManagerHandle handle
            );
예제 #20
0
        public async Task TestCancel()
        {
            var cts       = new CancellationTokenSource();
            var testBlock = new FilterBlock <int>(
                x => x % 2 != 0,
                new ExecutionDataflowBlockOptions()
            {
                CancellationToken = cts.Token
            });

            testBlock.Completion.IsCompleted.IsFalse();

            cts.Cancel();

            await testBlock.Completion.CanceledSoon();

            (await testBlock.SendAsync(1)).IsFalse();
        }
        private static extern FFIResult _deserialize_many_channel_monitor(
            IntPtr bufPtr,
            UIntPtr bufLen,
            ref InstallWatchTx installWatchTx,
            ref InstallWatchOutPoint installWatchOutPoint,
            ref WatchAllTxn watchAllTxn,
            ref GetChainUtxo getChainUtxo,
            ref FilterBlock filterBlock,
            ref ReEntered reEntered,

            ref BroadcastTransaction broadcastTransaction,
            ref Log log,
            ref GetEstSatPer1000Weight getEstSatPer1000Weight,

            IntPtr outputBufPtr,
            UIntPtr outputBufLen,
            out UIntPtr actualBufLen,
            out ManyChannelMonitorHandle manyChannelMonitorHandle
            );
예제 #22
0
        public static BlockHeader GetHeader(this IBlockFinder blockFinder, FilterBlock blockFilter)
        {
            switch (blockFilter.Type)
            {
            case FilterBlockType.Pending:
                return(blockFinder.FindPendingHeader());

            case FilterBlockType.Latest:
                return(blockFinder.FindLatestHeader());

            case FilterBlockType.Earliest:
                return(blockFinder.FindEarliestHeader());

            case FilterBlockType.BlockNumber:
                return(blockFinder.FindHeader(blockFilter.BlockNumber));

            default:
                throw new ArgumentException($"{nameof(FilterBlockType)} not supported: {blockFilter.Type}");
            }
        }
예제 #23
0
        public async Task TestFilter()
        {
            var inputBlock = new BufferBlock <int>();
            // drops even values
            var testBlock = new FilterBlock <int>(x => x % 2 != 0, new ExecutionDataflowBlockOptions()
            {
                BoundedCapacity = 1
            });

            inputBlock.LinkWithCompletion(testBlock);

            for (var i = 1; i <= 6; i++)
            {
                inputBlock.Post(i);
            }
            inputBlock.Complete();

            await Task.Delay(TestUtils.SometimeSoon);

            inputBlock.Count.Is(5);
            testBlock.Completion.IsCompleted.IsFalse();

            (await testBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(1);
            await Task.Delay(TestUtils.SometimeSoon);

            inputBlock.Count.Is(3);
            testBlock.Completion.IsCompleted.IsFalse();

            (await testBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(3);
            await Task.Delay(TestUtils.SometimeSoon);

            inputBlock.Count.Is(1);
            testBlock.Completion.IsCompleted.IsFalse();

            (await testBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(5);
            await Task.Delay(TestUtils.SometimeSoon);

            inputBlock.Count.Is(0);

            await testBlock.Completion.CompleteSoon();
        }
        internal static FFIResult deserialize_many_channel_monitor(
            IntPtr bufPtr,
            UIntPtr bufLen,
            InstallWatchTx installWatchTx,
            InstallWatchOutPoint installWatchOutPoint,
            WatchAllTxn watchAllTxn,
            GetChainUtxo getChainUtxo,
            FilterBlock filterBlock,
            ReEntered reEntered,

            BroadcastTransaction broadcastTransaction,
            Log log,
            GetEstSatPer1000Weight getEstSatPer1000Weight,

            IntPtr outputBufPtr,
            UIntPtr outputBufLen,
            out UIntPtr actualBufLen,
            out ManyChannelMonitorHandle manyChannelMonitorHandle,
            bool check = true
            )
        => MaybeCheck(
            _deserialize_many_channel_monitor(
                bufPtr,
                bufLen,
                ref installWatchTx,
                ref installWatchOutPoint,
                ref watchAllTxn,
                ref getChainUtxo,
                ref filterBlock,
                ref reEntered,

                ref broadcastTransaction,
                ref log,
                ref getEstSatPer1000Weight,
                outputBufPtr,
                outputBufLen,
                out actualBufLen,
                out manyChannelMonitorHandle
                ),
            check);
예제 #25
0
        public async void TestLink()
        {
            var testBlock = new FilterBlock <int>(x => x % 2 != 0);

            var target1 = new WriteOnceBlock <int>(null);
            var target2 = new WriteOnceBlock <int>(null);
            var target3 = new WriteOnceBlock <int>(null);

            testBlock.LinkTo(target1);
            testBlock.LinkTo(target2, x => x != 3);
            testBlock.LinkTo(target3);

            testBlock.Post(1).IsTrue();
            (await testBlock.SendAsync(2).CompleteSoon()).IsTrue(); // drop
            (await testBlock.SendAsync(3).CompleteSoon()).IsTrue();
            (await testBlock.SendAsync(4).CompleteSoon()).IsTrue(); // drop
            (await testBlock.SendAsync(5).CompleteSoon()).IsTrue();

            target1.Receive(TestUtils.SometimeSoon).Is(1);
            target2.Receive(TestUtils.SometimeSoon).Is(5);
            target3.Receive(TestUtils.SometimeSoon).Is(3);
        }
예제 #26
0
        public async Task TestMaxMessages()
        {
            var testBlock = new FilterBlock <int>(x => x % 2 != 0, new ExecutionDataflowBlockOptions()
            {
                BoundedCapacity = 1
            });
            var targetBlock = new BufferBlock <int>();

            testBlock.LinkTo(targetBlock, new DataflowLinkOptions()
            {
                MaxMessages = 1, PropagateCompletion = true
            });

            testBlock.Post(0).IsTrue();
            (await testBlock.SendAsync(1).CompleteSoon()).IsTrue();

            (await targetBlock.ReceiveAsync(TestUtils.SometimeSoon)).Is(1);
            await targetBlock.Completion.NeverComplete();

            (await testBlock.SendAsync(2).CompleteSoon()).IsTrue(); // drop
            (await testBlock.SendAsync(3).CompleteSoon()).IsTrue();
            await testBlock.SendAsync(4).NeverComplete();           // Reach BoundedCapacity"
        }
예제 #27
0
 public FilterLog[] GetLogs(FilterBlock fromBlock, FilterBlock toBlock, object address = null, IEnumerable <object> topics = null)
 {
     throw new System.NotImplementedException();
 }
예제 #28
0
파일: State.cs 프로젝트: PlumpMath/cilpe-1
 protected override void VisitFilterBlock(FilterBlock node, object data)
 {
     result = false;
 }
예제 #29
0
 public int NewFilter(FilterBlock fromBlock, FilterBlock toBlock, object address = null, IEnumerable <object> topics = null)
 {
     throw new NotImplementedException();
 }
예제 #30
0
        public ChainWatchInterfaceConverter(IChainWatchInterface chainWatchInterface)
        {
            _filterBlock = (ref byte blockPtr, UIntPtr blockLen, ref UIntPtr indexPtr, ref UIntPtr indexLen) =>
            {
                unsafe
                {
                    var blockS = new Span <byte>(Unsafe.AsPointer(ref blockPtr), (int)blockLen);
                    var block  = Block.Load(blockS.ToArray(), chainWatchInterface.Network);

                    var indexes = chainWatchInterface.FilterBlockImpl(block).Select(uintIndex => (UIntPtr)uintIndex).ToArray();
                    if (indexes.Length == 0)
                    {
                        indexLen = UIntPtr.Zero;
                        indexPtr = UIntPtr.Zero;
                        return;
                    }

                    fixed(UIntPtr *_ = indexes)
                    {
                        Unsafe.Write(Unsafe.AsPointer(ref indexLen), (UIntPtr)indexes.Length);
                        Unsafe.CopyBlockUnaligned(
                            ref Unsafe.As <UIntPtr, byte>(ref indexPtr),
                            ref Unsafe.As <UIntPtr, byte>(ref indexes[0]),
                            (uint)(indexes.Length * Unsafe.SizeOf <UIntPtr>()));
                    }
                }
            };

            _installWatchTx = (ref FFISha256dHash txid, ref FFIScript spk) =>
            {
                chainWatchInterface.InstallWatchTxImpl(txid.ToUInt256(), spk.ToScript());
            };

            _installWatchOutPoint = (ref FFIOutPoint ffiOutPoint, ref FFIScript script) =>
            {
                var t        = ffiOutPoint.ToTuple();
                var outpoint = new OutPoint(t.Item1, t.Item2);
                chainWatchInterface.InstallWatchOutPointImpl(outpoint, script.ToScript());
            };

            _getChainUtxo = (ref FFISha256dHash hash, ulong id, ref ChainError error, ref byte scriptPtr, ref UIntPtr scriptLen,
                             ref ulong satoshis) =>
            {
                if (chainWatchInterface.TryGetChainUtxoImpl(hash.ToUInt256(), id, ref error, out var script, out var a))
                {
                    using var m = new MemoryStream();
                    var stream = new BitcoinStream(m, true);
                    stream.ReadWrite(ref script);
                    var scriptPubKeyBytes = m.ToArray();
                    scriptLen = (UIntPtr)scriptPubKeyBytes.Length;
                    satoshis  = (ulong)a.Satoshi;
                    Unsafe.CopyBlock(ref scriptPtr, ref scriptPubKeyBytes[0], (uint)scriptPubKeyBytes.Length);
                }
            };

            _watchAllTxn = () =>
            {
                chainWatchInterface.WatchAllTxnImpl();
            };

            _reEntered = () => (UIntPtr)chainWatchInterface.ReEntered();
        }