예제 #1
0
        public static void Main(string[] args)
        {
            IFullNodeBuilder fullNodeBuilder = null;

            // configure logging
            Logs.Configure(Logs.GetLoggerFactory(args));

            // get the api uri
            var apiUri = args.SingleOrDefault(arg => arg.StartsWith("apiuri"));

            if (!string.IsNullOrEmpty(apiUri))
            {
                apiUri = apiUri.Replace("apiuri=", string.Empty);
            }

            if (args.Contains("stratis"))
            {
                if (NodeSettings.PrintHelp(args, Network.StratisMain))
                {
                    return;
                }

                var network      = args.Contains("-testnet") ? InitStratisTest() : Network.StratisMain;
                var nodeSettings = NodeSettings.FromArguments(args, "stratis", network, ProtocolVersion.ALT_PROTOCOL_VERSION);
                nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultStratisUri : apiUri);

                if (args.Contains("light"))
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseLightWallet()
                                      .UseBlockNotification()
                                      .UseTransactionNotification()
                                      .UseApi();
                }
                else
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseStratisConsensus()
                                      .UseBlockStore()
                                      .UseMempool()
                                      .UseWallet()
                                      .AddPowPosMining()
                                      .UseApi();
                }
            }
            else
            {
                NodeSettings nodeSettings = NodeSettings.FromArguments(args);
                nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultBitcoinUri : apiUri);

                if (args.Contains("light"))
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseLightWallet()
                                      .UseBlockNotification()
                                      .UseTransactionNotification()
                                      .UseApi();
                }
                else
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseConsensus()
                                      .UseBlockStore()
                                      .UseMempool()
                                      .UseWallet()
                                      .UseApi();
                }
            }

            // add the tumbler's settings
            var tumblerAddress = args.SingleOrDefault(arg => arg.StartsWith("-tumbler-uri="));

            if (!string.IsNullOrEmpty(tumblerAddress))
            {
                tumblerAddress = tumblerAddress.Replace("-tumbler-uri=", string.Empty);
                fullNodeBuilder.UseTumbleBit(new Uri(tumblerAddress));
                fullNodeBuilder.UseWatchOnlyWallet();
            }

            var node = fullNodeBuilder.Build();

            //start Full Node - this will also start the API
            node.Run();
        }
예제 #2
0
파일: Program.cs 프로젝트: bep42/Tumblebit
        public static void Main(string[] args)
        {
            IFullNodeBuilder fullNodeBuilder = null;

            // get the api uri
            var apiUri = args.GetValueOf("apiuri");

            if (args.Contains("stratis"))
            {
                if (NodeSettings.PrintHelp(args, Network.StratisMain))
                {
                    return;
                }

                var network = args.Contains("-testnet") ? InitStratisTest() : Network.StratisMain;
                if (args.Contains("-testnet"))
                {
                    args = args.Append("-addnode=13.64.76.48").ToArray(); // TODO: fix this temp hack
                }
                var nodeSettings = NodeSettings.FromArguments(args, "stratis", network, ProtocolVersion.ALT_PROTOCOL_VERSION);
                nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultStratisUri : apiUri);

                if (args.Contains("light"))
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseLightWallet()
                                      .UseBlockNotification()
                                      .UseTransactionNotification()
                                      .UseApi();
                }
                else
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseStratisConsensus()
                                      .UseBlockStore()
                                      .UseMempool()
                                      .UseWallet()
                                      .AddPowPosMining()
                                      .UseApi();
                }
            }
            else
            {
                NodeSettings nodeSettings = NodeSettings.FromArguments(args);
                nodeSettings.ApiUri = new Uri(string.IsNullOrEmpty(apiUri) ? DefaultBitcoinUri : apiUri);

                if (args.Contains("light"))
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseLightWallet()
                                      .UseBlockNotification()
                                      .UseTransactionNotification()
                                      .UseApi();
                }
                else
                {
                    fullNodeBuilder = new FullNodeBuilder()
                                      .UseNodeSettings(nodeSettings)
                                      .UseConsensus()
                                      .UseBlockStore()
                                      .UseMempool()
                                      .UseWallet()
                                      .UseApi();
                }
            }

            var node = fullNodeBuilder.Build();

            //start Full Node - this will also start the API
            node.Run();
        }
예제 #3
0
        /// <summary>
        /// Creates the test chain with some default blocks and txs.
        /// </summary>
        /// <param name="network">Network to create the chain on.</param>
        /// <param name="scriptPubKey">Public key to create blocks/txs with.</param>
        /// <returns>Context object representing the test chain.</returns>
        public static async Task <ITestChainContext> CreateAsync(Network network, Script scriptPubKey, string dataDir)
        {
            NodeSettings nodeSettings = NodeSettings.FromArguments(new string[] { $"-datadir={dataDir}" }, network.Name, network);

            if (dataDir != null)
            {
                nodeSettings.DataDir = dataDir;
            }

            LoggerFactory     loggerFactory    = new LoggerFactory();
            IDateTimeProvider dateTimeProvider = DateTimeProvider.Default;

            network.Consensus.Options = new PowConsensusOptions();
            PowConsensusValidator consensusValidator = new PowConsensusValidator(network, new Checkpoints(network), dateTimeProvider, loggerFactory);
            ConcurrentChain       chain          = new ConcurrentChain(network);
            CachedCoinView        cachedCoinView = new CachedCoinView(new InMemoryCoinView(chain.Tip.HashBlock), DateTimeProvider.Default, loggerFactory);

            ConnectionManager    connectionManager = new ConnectionManager(network, new NodeConnectionParameters(), nodeSettings, loggerFactory, new NodeLifetime());
            LookaheadBlockPuller blockPuller       = new LookaheadBlockPuller(chain, connectionManager, new LoggerFactory());

            ConsensusLoop consensus = new ConsensusLoop(new AsyncLoopFactory(loggerFactory), consensusValidator, new NodeLifetime(), chain, cachedCoinView, blockPuller, new NodeDeployments(network, chain), loggerFactory, new ChainState(new FullNode()), connectionManager, dateTimeProvider, new Signals.Signals(), new Checkpoints(network));
            await consensus.StartAsync();

            BlockPolicyEstimator blockPolicyEstimator = new BlockPolicyEstimator(new MempoolSettings(nodeSettings), loggerFactory, nodeSettings);
            TxMempool            mempool     = new TxMempool(dateTimeProvider, blockPolicyEstimator, loggerFactory, nodeSettings);
            MempoolSchedulerLock mempoolLock = new MempoolSchedulerLock();

            // Simple block creation, nothing special yet:
            PowBlockAssembler blockAssembler = CreatePowBlockAssembler(network, consensus, chain, mempoolLock, mempool, dateTimeProvider, loggerFactory);
            BlockTemplate     newBlock       = blockAssembler.CreateNewBlock(scriptPubKey);

            chain.SetTip(newBlock.Block.Header);
            consensus.ValidateAndExecuteBlock(new ContextInformation(new BlockValidationContext {
                Block = newBlock.Block
            }, network.Consensus)
            {
                CheckPow = false, CheckMerkleRoot = false
            });

            List <BlockInfo> blockinfo = CreateBlockInfoList();

            // We can't make transactions until we have inputs
            // Therefore, load 100 blocks :)
            int                baseheight = 0;
            List <Block>       blocks     = new List <Block>();
            List <Transaction> srcTxs     = new List <Transaction>();

            for (int i = 0; i < blockinfo.Count; ++i)
            {
                Block currentBlock = newBlock.Block.Clone(); // pointer for convenience
                currentBlock.Header.HashPrevBlock = chain.Tip.HashBlock;
                currentBlock.Header.Version       = 1;
                currentBlock.Header.Time          = Utils.DateTimeToUnixTime(chain.Tip.GetMedianTimePast()) + 1;
                Transaction txCoinbase = currentBlock.Transactions[0].Clone();
                txCoinbase.Inputs.Clear();
                txCoinbase.Version = 1;
                txCoinbase.AddInput(new TxIn(new Script(new[] { Op.GetPushOp(blockinfo[i].extraNonce), Op.GetPushOp(chain.Height) })));
                // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this)
                txCoinbase.AddOutput(new TxOut(Money.Zero, new Script()));
                currentBlock.Transactions[0] = txCoinbase;

                if (srcTxs.Count == 0)
                {
                    baseheight = chain.Height;
                }
                if (srcTxs.Count < 4)
                {
                    srcTxs.Add(currentBlock.Transactions[0]);
                }
                currentBlock.UpdateMerkleRoot();

                currentBlock.Header.Nonce = blockinfo[i].nonce;

                chain.SetTip(currentBlock.Header);
                consensus.ValidateAndExecuteBlock(new ContextInformation(new BlockValidationContext {
                    Block = currentBlock
                }, network.Consensus)
                {
                    CheckPow = false, CheckMerkleRoot = false
                });
                blocks.Add(currentBlock);
            }

            // Just to make sure we can still make simple blocks
            blockAssembler = CreatePowBlockAssembler(network, consensus, chain, mempoolLock, mempool, dateTimeProvider, loggerFactory);
            newBlock       = blockAssembler.CreateNewBlock(scriptPubKey);

            MempoolValidator mempoolValidator = new MempoolValidator(mempool, mempoolLock, consensusValidator, dateTimeProvider, new MempoolSettings(nodeSettings), chain, cachedCoinView, loggerFactory, nodeSettings);

            return(new TestChainContext {
                MempoolValidator = mempoolValidator, SrcTxs = srcTxs
            });
        }