Esempio n. 1
0
        private static void HandleSwitchMineGenesisBlockCommand(string userInput)
        {
            int index = userInput.IndexOf("text=");

            if (index < 0)
            {
                throw new ArgumentException("The -text=\"<text>\" argument is missing.");
            }

            string text = userInput.Substring(userInput.IndexOf("text=") + 5);

            if (text.Substring(0, 1) != "\"" || text.Substring(text.Length - 1, 1) != "\"")
            {
                throw new ArgumentException("The -text=\"<text>\" argument should have double-quotes.");
            }

            text = text.Substring(1, text.Length - 2);

            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("Please specify the text to be included in the genesis block.");
            }

            Console.WriteLine(new GenesisMiner().MineGenesisBlocks(new SmartContractPoAConsensusFactory(), text));
            FederationSetup.OutputSuccess();
        }
Esempio n. 2
0
        private static void HandleSwitchMenuCommand(string[] args)
        {
            if (args.Length != 1)
            {
                throw new ArgumentException("Please enter the exact number of argument required.");
            }

            FederationSetup.OutputMenu();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                SwitchCommand(args, args[0], string.Join(" ", args));
                return;
            }

            Console.SetIn(new StreamReader(Console.OpenStandardInput(), Console.InputEncoding, false, bufferSize: 1024));

            // Start with the banner and the help message.
            FederationSetup.OutputHeader();
            FederationSetup.OutputMenu();

            while (true)
            {
                try
                {
                    Console.Write("Your choice: ");
                    string userInput = Console.ReadLine().Trim();

                    string command = null;
                    if (!string.IsNullOrEmpty(userInput))
                    {
                        args    = userInput.Split(" ");
                        command = args[0];
                    }
                    else
                    {
                        args = null;
                    }

                    Console.WriteLine();

                    SwitchCommand(args, command, userInput);
                }
                catch (Exception ex)
                {
                    FederationSetup.OutputErrorLine($"An error occurred: {ex.Message}");
                    Console.WriteLine();
                    FederationSetup.OutputMenu();
                }
            }
        }
Esempio n. 4
0
        private static void HandleSwitchGenerateFedPublicPrivateKeysCommand(string[] args)
        {
            if (args.Length != 1 && args.Length != 2 && args.Length != 3 && args.Length != 4)
            {
                throw new ArgumentException("Please enter the exact number of argument required.");
            }

            string passphrase  = null;
            string dataDirPath = null;
            string isMultisig  = null;

            dataDirPath = Array.Find(args, element =>
                                     element.StartsWith("-datadir=", StringComparison.Ordinal));

            passphrase = Array.Find(args, element =>
                                    element.StartsWith("-passphrase=", StringComparison.Ordinal));

            isMultisig = Array.Find(args, element =>
                                    element.StartsWith("-ismultisig=", StringComparison.Ordinal));

            if (string.IsNullOrEmpty(passphrase))
            {
                throw new ArgumentException("The -passphrase=\"<passphrase>\" argument is missing.");
            }

            passphrase = passphrase.Replace("-passphrase=", string.Empty);

            //ToDo wont allow for datadir with equal sign
            dataDirPath = string.IsNullOrEmpty(dataDirPath)
                ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                : dataDirPath.Replace("-datadir=", string.Empty);

            if (string.IsNullOrEmpty(isMultisig) || isMultisig.Replace("-ismultisig=", string.Empty) == "true")
            {
                GeneratePublicPrivateKeys(passphrase, dataDirPath);
            }
            else
            {
                GeneratePublicPrivateKeys(passphrase, dataDirPath, isMultiSigOutput: false);
            }

            FederationSetup.OutputSuccess();
        }
Esempio n. 5
0
        private static void HandleSwitchGenerateFedPublicPrivateKeysCommand(string[] args)
        {
            if (args.Length != 1 && args.Length != 2)
            {
                throw new ArgumentException("Please enter the exact number of argument required.");
            }

            string passphrase = null;

            if (args.Length == 2)
            {
                int index = args[1].IndexOf("-passphrase=");
                if (index < 0)
                {
                    throw new ArgumentException("The -passphrase=\"<passphrase>\" argument is missing.");
                }
                passphrase = args[1].Replace("-passphrase=", string.Empty);
            }

            GeneratePublicPrivateKeys(passphrase);
            FederationSetup.OutputSuccess();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Console.SetIn(new StreamReader(Console.OpenStandardInput(), Console.InputEncoding, false, bufferSize: 1024));

            // Start with the banner and the help message.
            FederationSetup.OutputHeader();
            FederationSetup.OutputMenu();

            while (true)
            {
                try
                {
                    Console.Write("Your choice: ");
                    string userInput = Console.ReadLine().Trim();

                    string command = null;
                    if (!string.IsNullOrEmpty(userInput))
                    {
                        args    = userInput.Split(" ");
                        command = args[0];
                    }
                    else
                    {
                        args    = null;
                        command = null;
                    }

                    Console.WriteLine();

                    switch (command)
                    {
                    case SwitchExit:
                    {
                        return;
                    }

                    case SwitchMenu:
                    {
                        HandleSwitchMenuCommand(args);
                        break;
                    }

                    case SwitchMineGenesisBlock:
                    {
                        HandleSwitchMineGenesisBlockCommand(userInput);
                        break;
                    }

                    case SwitchGenerateFedPublicPrivateKeys:
                    {
                        HandleSwitchGenerateFedPublicPrivateKeysCommand(args);
                        break;
                    }

                    case SwitchGenerateMultiSigAddresses:
                    {
                        HandleSwitchGenerateMultiSigAddressesCommand(args);
                        break;
                    }
                    }
                }
                catch (Exception ex)
                {
                    FederationSetup.OutputErrorLine($"An error occurred: {ex.Message}");
                    Console.WriteLine();
                    FederationSetup.OutputMenu();
                }
            }
        }
        static void Main(string[] args)
        {
            Console.SetIn(new StreamReader(Console.OpenStandardInput(),
                                           Console.InputEncoding,
                                           false,
                                           bufferSize: 1024));

            // Start with the banner and the help message.
            FederationSetup.OutputHeader();
            FederationSetup.OutputMenu();


            while (true)
            {
                try
                {
                    Console.Write("Your choice: ");
                    string userInput = Console.ReadLine().Trim();

                    string command = null;
                    if (!string.IsNullOrEmpty(userInput))
                    {
                        args    = userInput.Split(" ");
                        command = args[0];
                    }
                    else
                    {
                        args    = null;
                        command = null;
                    }

                    Console.WriteLine();

                    if (command == SwitchExit)
                    {
                        return;
                    }

                    if (command == SwitchMenu)
                    {
                        if (args.Length != 1)
                        {
                            throw new ArgumentException("Please enter the exact number of argument required.");
                        }

                        FederationSetup.OutputMenu();
                    }

                    if (command == SwitchMineGenesisBlock)
                    {
                        int index = userInput.IndexOf("text=");
                        if (index < 0)
                        {
                            throw new ArgumentException("The -text=\"<text>\" argument is missing.");
                        }

                        string text = userInput.Substring(userInput.IndexOf("text=") + 5);

                        if (text.Substring(0, 1) != "\"" || text.Substring(text.Length - 1, 1) != "\"")
                        {
                            throw new ArgumentException("The -text=\"<text>\" argument should have double-quotes.");
                        }

                        text = text.Substring(1, text.Length - 2);

                        if (string.IsNullOrEmpty(text))
                        {
                            throw new ArgumentException("Please specify the text to be included in the genesis block.");
                        }

                        Console.WriteLine(new GenesisMiner().MineGenesisBlocks(new SmartContractPoAConsensusFactory(), text));
                        FederationSetup.OutputSuccess();
                    }

                    if (command == SwitchGenerateFedPublicPrivateKeys)
                    {
                        if (args.Length != 1)
                        {
                            throw new ArgumentException("Please enter the exact number of argument required.");
                        }

                        GeneratePublicPrivateKeys();
                        FederationSetup.OutputSuccess();
                    }

                    if (command == SwitchGenerateMultiSigAddresses)
                    {
                        if (args.Length != 4)
                        {
                            throw new ArgumentException("Please enter the exact number of argument required.");
                        }

                        ConfigReader = new TextFileConfiguration(args);

                        int      quorum = GetQuorumFromArguments();
                        string[] federatedPublicKeys = GetFederatedPublicKeysFromArguments();

                        if (quorum > federatedPublicKeys.Length)
                        {
                            throw new ArgumentException("Quorum has to be smaller than the number of members within the federation.");
                        }

                        if (quorum < federatedPublicKeys.Length / 2)
                        {
                            throw new ArgumentException("Quorum has to be greater than half of the members within the federation.");
                        }

                        (Network mainChain, Network sideChain) = GetMainAndSideChainNetworksFromArguments();

                        Console.WriteLine($"Creating multisig addresses for {mainChain.Name} and {sideChain.Name}.");
                        Console.WriteLine(new MultisigAddressCreator().CreateMultisigAddresses(mainChain, sideChain, federatedPublicKeys.Select(f => new PubKey(f)).ToArray(), quorum));
                    }
                }
                catch (Exception ex)
                {
                    FederationSetup.OutputErrorLine($"An error occurred: {ex.Message}");
                    Console.WriteLine();
                    FederationSetup.OutputMenu();
                }
            }
        }