public static async Task MainAsync(string[] args) { try { Network network = null; if (args.Contains("-testnet")) { network = Network.DeStreamTest; } else { network = Network.DeStreamMain; } DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, args: args, loadConfiguration: false); Console.WriteLine($"current network: {network.Name}"); // NOTES: running BTC and STRAT side by side is not possible yet as the flags for serialization are static FullNode node = (FullNode) new FullNodeBuilder() .UseNodeSettings(nodeSettings) .UseBlockStore() .UsePosConsensus() .UseMempool() .UseWallet() .AddPowPosMining() .UseApi() .AddRPC() .Build(); //(Wallet wallet, Block block, ChainedHeader chainedHeader) result = TestClassHelper.CreateFirstTransaction(nodeSettings, node.WalletManager(), node.NodeService<WalletSettings>(), // node.NodeService<IWalletFeePolicy>()); //var walletManager = node.WalletManager(); //walletManager.Wallets.Add(result.wallet); //HdAddress addr = result.wallet.AccountsRoot.ElementAt(0).Accounts.ElementAt(0).ExternalAddresses.ElementAt(0); //Key key = result.wallet.GetExtendedPrivateKeyForAddress("password", addr).PrivateKey; //TestClassHelper.CreateTestBlock(node, key); //walletManager.SaveWallets(); //var test = node.WalletManager().GetSpendableTransactionsInWallet("myWallet1").Sum(s => s.Transaction.Amount); Process currentProcess = Process.GetCurrentProcess(); Console.WriteLine("##############################: " + currentProcess.Id.ToString()); int qwe0 = 1; if (node != null) { await node.RunAsync(); } int qwe = 1; } catch (Exception ex) { Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message); } }
public static async Task MainAsync(string[] args) { try { // Get the API uri. var isTestNet = args.Contains("-testnet"); var isDeStream = args.Contains("destream"); var agent = "Breeze"; DeStreamNodeSettings nodeSettings; if (isDeStream) { Network network = isTestNet ? Network.DeStreamTest : Network.DeStreamMain; nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, agent, args: args, loadConfiguration: false); } else { nodeSettings = new DeStreamNodeSettings(agent: agent, args: args, loadConfiguration: false); } IFullNodeBuilder fullNodeBuilder = new FullNodeBuilder() .UseNodeSettings(nodeSettings) .UseLightWallet() .UseBlockNotification() .UseTransactionNotification() .UseApi(); IFullNode node = fullNodeBuilder.Build(); // Start Full Node - this will also start the API. if (node != null) { await node.RunAsync(); } } catch (Exception ex) { Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message); } }
public static async Task MainAsync(string[] args) { try { Network network = null; if (args.Contains("-testnet")) { network = Network.DeStreamTest; } else { network = Network.DeStreamMain; } DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, args: args, loadConfiguration: false); Console.WriteLine($"current network: {network.Name}"); // NOTES: running BTC and STRAT side by side is not possible yet as the flags for serialization are static var node = new FullNodeBuilder() .UseNodeSettings(nodeSettings) .UseBlockStore() .UsePosConsensus() .UseMempool() .UseWallet() .AddPowPosMining() .UseApi() .AddRPC() .Build(); if (node != null) { await node.RunAsync(); } } catch (Exception ex) { Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message); } }
/// <summary> /// The expected sequence of arguments: /// <list> /// <item> /// 1, [network-name] [options] [rpc-command] [rpc-params]. /// </item> /// <item> /// 2, [network-name] [options] [api-controller "/" api-command] [api-params]. /// </item> /// </list> /// </summary> public static void Main(string[] args) { try { // Preprocess the command line arguments var argList = new List <string>(args); string networkName = null; if (argList.Any()) { networkName = argList.First(); argList.RemoveAt(0); } var optionList = new List <string>(); while ((argList.Any()) && (argList[0].StartsWith('-'))) { optionList.Add(argList[0]); argList.RemoveAt(0); } string command = string.Empty; if (argList.Any()) { command = argList.First(); argList.RemoveAt(0); } var commandArgList = new List <string>(argList); // Display help if required. if (optionList.Contains("-help") || optionList.Contains("--help") || string.IsNullOrWhiteSpace(command)) { var builder = new StringBuilder(); builder.AppendLine("Usage:"); builder.AppendLine(" dotnet run <DeStream.Stratis.Bitcoin.Cli/DeStream.Stratis.Bitcoin.Cli.dll> [network-name] [options] <command> [arguments]"); builder.AppendLine(); builder.AppendLine("Command line arguments:"); builder.AppendLine(); builder.AppendLine("[network-name] Name of the network - e.g. \"destream\", \"destreammain\", \"destreamtest\", \"bitcoinmain\", \"bitcointest\"."); builder.AppendLine("[options] Options for the CLI (optional) - e.g. -help, -rpcuser, see below."); builder.AppendLine("[command] Name of RPC method or API <controller>/<method>."); builder.AppendLine("[arguments] Argument by position (RPC) or Name = Value pairs (API) (optional)."); builder.AppendLine(); builder.AppendLine("Options:"); builder.AppendLine("-help This help message"); builder.AppendLine("-rpcconnect=<ip> Send commands to node running on <ip> (default: 127.0.0.1)"); builder.AppendLine("-rpcport=<port> Connect to JSON-RPC on <port> (default for destream: 26174 or default for Bitcoin: 8332)"); builder.AppendLine("-rpcuser=<user> Username for JSON-RPC connections"); builder.AppendLine("-rpcpassword=<pw> Password for JSON-RPC connections"); builder.AppendLine(); builder.AppendLine("Examples:"); builder.AppendLine(); builder.AppendLine("dotnet run destream Wallet/history WalletName=testwallet - Lists all the historical transactions of the wallet called 'testwallet'."); builder.AppendLine("dotnet run destream getinfo -rpcuser=destreamtestuser -rpcpassword=destreamtestpassword -rpcconnect=127.0.0.3 -rpcport=26174 - Displays general information about the destream node on the 127.0.0.3:26174, authenticating with the RPC specified user."); builder.AppendLine("dotnet run bitcoin getbalance -rpcuser=btctestuser -rpcpassword=btctestpass - Displays the current balance of the opened wallet on the 127.0.0.1:8332 node, authenticating with the RPC specified user."); Console.WriteLine(builder); return; } // Determine API port. int defaultRestApiPort = 0; Network network = null; if (networkName.Contains("destream")) { defaultRestApiPort = 37221; network = Network.DeStreamMain; } else { defaultRestApiPort = 37220; network = Network.Main; } // API calls require both the contoller name and the method name separated by "/". // If this is not an API call then assume it is an RPC call. if (!command.Contains("/")) { // Process RPC call. try { var options = optionList.ToArray(); DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, args: options); var rpcSettings = new RpcSettings(nodeSettings); // Find the binding to 127.0.0.1 or the first available. The logic in RPC settings ensures there will be at least 1. System.Net.IPEndPoint nodeEndPoint = rpcSettings.Bind.FirstOrDefault(b => b.Address.ToString() == "127.0.0.1") ?? rpcSettings.Bind[0]; Uri rpcUri = new Uri($"http://{nodeEndPoint}"); // Process the command line RPC arguments // TODO: this should probably be moved to the NodeSettings.FromArguments if (options.GetValueOf("-rpcbind") != null) { rpcUri = new Uri($"http://{options.GetValueOf("-rpcbind")}"); } if (options.GetValueOf("-rpcconnect") != null || options.GetValueOf("-rpcport") != null) { string rpcAddress = options.GetValueOf("-rpcconnect") ?? "127.0.0.1"; int rpcPort = rpcSettings.RPCPort; int.TryParse(options.GetValueOf("-rpcport"), out rpcPort); rpcUri = new Uri($"http://{rpcAddress}:{rpcPort}"); } rpcSettings.RpcUser = options.GetValueOf("-rpcuser") ?? rpcSettings.RpcUser; rpcSettings.RpcPassword = options.GetValueOf("-rpcpassword") ?? rpcSettings.RpcPassword; Console.WriteLine($"Connecting to the following RPC node: http://{rpcSettings.RpcUser}:{rpcSettings.RpcPassword}@{rpcUri.Authority}..."); // Initialize the RPC client with the configured or passed userid, password and endpoint. var rpcClient = new RPCClient($"{rpcSettings.RpcUser}:{rpcSettings.RpcPassword}", rpcUri, network); // Execute the RPC command Console.WriteLine($"Sending RPC command '{command} {string.Join(" ", commandArgList)}' to '{rpcUri}'..."); RPCResponse response = rpcClient.SendCommand(command, commandArgList.ToArray()); // Return the result as a string to the console. Console.WriteLine(response.ResultString); } catch (Exception err) { Console.WriteLine(err.Message); } } else { // Process API call. using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var url = $"http://localhost:{defaultRestApiPort}/api/{command}"; if (commandArgList.Any()) { url += $"?{string.Join("&", commandArgList)}"; } try { // Get the response. Console.WriteLine($"Sending API command to {url}..."); var response = client.GetStringAsync(url).GetAwaiter().GetResult(); // Format and return the result as a string to the console. Console.WriteLine(JsonConvert.SerializeObject(JsonConvert.DeserializeObject <object>(response), Formatting.Indented)); } catch (Exception err) { Console.WriteLine(ExceptionToString(err)); } } } } catch (Exception err) { // Report any errors to the console. Console.WriteLine(ExceptionToString(err)); } }