Beispiel #1
0
        //Wallet sub functions
        static void Wallet(string[] cmdArgs, BlockChainClassLib.CommandProcessor cmdProc)
        {
            switch (cmdArgs[1])
            {
            case "list":
                int i = 0;
                System.Console.WriteLine("wallet entries:-");
                List <WalletLib.WalletEntry> entries = cmdProc.Wallet_ListEntries();
                foreach (WalletLib.WalletEntry wa in entries)
                {
                    System.Console.WriteLine(i.ToString("000") + ") " + wa.address + " = " + wa.amount);
                    i++;
                }
                System.Console.WriteLine("");
                break;

            case "select":
                i = int.Parse(cmdArgs[2]);
                cmdProc.Wallet_SelectAddress(i);
                break;

            case "add":
                cmdProc.Wallet_CreateAddress();
                break;

            case "load":
                cmdProc.Wallet_Load();
                break;

            case "save":
                cmdProc.Wallet_Save();
                break;

            case "balance":
                cmdProc.Wallet_Balance();
                break;
            }
        }
Beispiel #2
0
        //Provides an interactive mechanism for the user to create blockchain transactions
        static void InteractiveCreateTransaction(string[] cmdArgs, BlockChainClassLib.CommandProcessor cmdProc)
        {
            //1) ask the user for a list of input transactions:
            System.Console.WriteLine("Create Transaction:");
            System.Console.WriteLine("Enter Addresses from your Wallet (one on each line, blank to cancel entry):");

            WalletLib.WalletEntry we;

            //build a list of input addresses
            List <string> addressList = new List <string>();
            int           i           = 1;
            string        line        = "";

            do
            {
                System.Console.Write(string.Format("Enter Source Address ({0})=", i));
                line = System.Console.ReadLine().Trim();

                if (line == "")
                {
                    break;
                }

                we = cmdProc.Wallet_FindEntry(line);
                if (we != null)
                {
                    addressList.Add(line);
                    i++;
                }
                else
                {
                    System.Console.WriteLine("address not found");
                }
            } while (line != "");

            if (addressList.Count() == 0)
            {
                return;
            }

            //2) Enter primary payment address
            System.Console.Write("Enter payment address (blank line to cancel transaction)=");
            string paymentAddress = System.Console.ReadLine().Trim();

            if (paymentAddress == "")
            {
                return;
            }

            //3) Enter payment amount
            string paymentAmount = "";
            int    amount        = 0;

            do
            {
                System.Console.Write("Enter payment amount=");
                paymentAmount = System.Console.ReadLine().Trim();

                if (paymentAmount == "")
                {
                    return;
                }
            } while (!int.TryParse(paymentAmount, out amount));


            //Enter address to post any change to (enter "new" to create a new one and add to your wallet)
            System.Console.Write("Enter change address (new to create one)=");
            string changeAddress = System.Console.ReadLine().Trim();

            if (changeAddress == "")
            {
                return;
            }

            if (changeAddress.Trim() == "new")
            {
                changeAddress = cmdProc.Wallet_CreateAddress();
                cmdProc.Wallet_Save();
                System.Console.WriteLine("Address added to your wallet: " + changeAddress);
            }

            CreateTransaction(addressList, paymentAddress, amount, changeAddress, cmdProc);
        }