public async Task <uint256> InsertMerkleProof()
        {
            var blockHex = await RpcClient.GetBlockAsBytesAsync(await RpcClient.GetBestBlockHashAsync());

            var firstBlock     = NBitcoin.Block.Load(blockHex, Network.Main);
            var block          = firstBlock.CreateNextBlockWithCoinbase(firstBlock.Transactions.First().Outputs.First().ScriptPubKey.GetDestinationPublicKeys().First(), new Money(50, MoneyUnit.MilliBTC), new ConsensusFactory());
            var firstBlockHash = firstBlock.GetHash();

            var tx = Transaction.Parse(Tx1Hex, Network.Main);

            block.AddTransaction(tx);
            tx = Transaction.Parse(Tx2Hex, Network.Main);
            block.AddTransaction(tx);
            tx = Transaction.Parse(Tx3Hex, Network.Main);
            block.AddTransaction(tx);
            tx = Transaction.Parse(Tx4Hex, Network.Main);
            block.AddTransaction(tx);
            tx = Transaction.Parse(Tx5Hex, Network.Main);
            block.AddTransaction(tx);

            rpcClientFactoryMock.AddKnownBlock((await RpcClient.GetBlockCountAsync()) + 1, block.ToBytes());
            var node      = NodeRepository.GetNodes().First();
            var rpcClient = rpcClientFactoryMock.Create(node.Host, node.Port, node.Username, node.Password);

            PublishBlockHashToEventBus(await rpcClient.GetBestBlockHashAsync());


            return(firstBlockHash);
        }
Exemplo n.º 2
0
        public async Task <(NBitcoin.Block, string)> MineNextBlockAsync(IEnumerable <NBitcoin.Transaction> transactions,
                                                                        bool throwOnError = true, string parentBlockHash = null)
        {
            if (string.IsNullOrEmpty(parentBlockHash))
            {
                parentBlockHash = await rpcClient0.GetBestBlockHashAsync();
            }

            var parentBlockBytes = await rpcClient0.GetBlockAsBytesAsync(parentBlockHash);

            var parentBlock       = NBitcoin.Block.Load(parentBlockBytes, Network.RegTest);
            var parentBlockHeight = (await rpcClient0.GetBlockHeaderAsync(parentBlockHash)).Height;

            return(await MineNextBlockAsync(transactions, throwOnError, parentBlock, parentBlockHeight));
        }