Exemplo n.º 1
0
        public void MultiMergeTest()
        {
            var a = ByteArrayHelpers.FromHexString(string.Concat(
                                                       "1000000000000000000000000000000000000000000000000000000000000000",
                                                       "1000000000000000000000000000000000000000000000000000000000000000",
                                                       "1000000000000000000000000000000000000000000000000000000000000000",
                                                       "1000000000000000000000000000000000000000000000000000000000000000",
                                                       "1000000000000000000000000000000000000000000000000000000000000000",
                                                       "1000000000000000000000000000000000000000000000000000000000000000",
                                                       "1000000000000000000000000000000000000000000000000000000000000000",
                                                       "1000000000000000000000000000000000000000000000000000000000000000"
                                                       ));

            var b = ByteArrayHelpers.FromHexString(string.Concat(
                                                       "0100000000000000000000000000000000000000000000000000000000000000",
                                                       "0100000000000000000000000000000000000000000000000000000000000000",
                                                       "0100000000000000000000000000000000000000000000000000000000000000",
                                                       "0100000000000000000000000000000000000000000000000000000000000000",
                                                       "0100000000000000000000000000000000000000000000000000000000000000",
                                                       "0100000000000000000000000000000000000000000000000000000000000000",
                                                       "0100000000000000000000000000000000000000000000000000000000000000",
                                                       "0100000000000000000000000000000000000000000000000000000000000000"
                                                       ));

            var c = ByteArrayHelpers.FromHexString(string.Concat(
                                                       "1100000000000000000000000000000000000000000000000000000000000000",
                                                       "1100000000000000000000000000000000000000000000000000000000000000",
                                                       "1100000000000000000000000000000000000000000000000000000000000000",
                                                       "1100000000000000000000000000000000000000000000000000000000000000",
                                                       "1100000000000000000000000000000000000000000000000000000000000000",
                                                       "1100000000000000000000000000000000000000000000000000000000000000",
                                                       "1100000000000000000000000000000000000000000000000000000000000000",
                                                       "1100000000000000000000000000000000000000000000000000000000000000"
                                                       ));

            var res = Bloom.AndMultipleBloomBytes(new List <byte[]>()
            {
                a, b
            });

            Assert.Equal(c, res);
        }
Exemplo n.º 2
0
Arquivo: Miner.cs Projeto: wyk125/AElf
        /// <summary>
        /// Generate block
        /// </summary>
        /// <param name="results"></param>
        /// <returns></returns>
        private async Task <IBlock> GenerateBlockAsync(HashSet <TransactionResult> results)
        {
            var blockChain = _chainService.GetBlockChain(Config.ChainId);

            var currentBlockHash = await blockChain.GetCurrentBlockHashAsync();

            var index = await blockChain.GetCurrentBlockHeightAsync() + 1;

            var block = new Block(currentBlockHash)
            {
                Header =
                {
                    Index   = index,
                    ChainId = Config.ChainId,
                    Bloom   = ByteString.CopyFrom(
                        Bloom.AndMultipleBloomBytes(
                            results.Where(x => !x.Bloom.IsEmpty).Select(x => x.Bloom.ToByteArray())
                            )
                        )
                }
            };

            // side chain info
            await CollectSideChainIndexedInfo(block);

            // add tx hash
            block.AddTransactions(results.Select(x => x.TransactionId));

            // set ws merkle tree root
            block.Header.MerkleTreeRootOfWorldState =
                new BinaryMerkleTree().AddNodes(results.Select(x => x.StateHash)).ComputeRootHash();
            block.Header.Time = Timestamp.FromDateTime(DateTime.UtcNow);

            // calculate and set tx merkle tree root
            block.Complete();
            block.Sign(_keyPair);
            return(block);
        }