//creates a new wallet entry public string Wallet_CreateAddress() { //Use the Crypto provider to generate a new public + private key pair _cryptoProvider.GenerateKeyPair(); //export encoded string representations (usually base 64) of the public and private keys string privateKey = _cryptoProvider.ExportPrivateKey(); string publicKey = _cryptoProvider.ExportPublicKey(); //use the Address Encode mentods of the Cryto provider to create a BitCoin like address from the public key string address = CryptoProvider.AddressEncoder.CreateAddress(publicKey); //create the wallet entry object and add it to the wallet WalletLib.WalletEntry we = new WalletLib.WalletEntry(address, publicKey, privateKey, 0); _wallet.WalletEntries.Add(we); //return the new entry return(we.address); }
//command console entry point static void Main(string[] args) { string nodeId = System.Configuration.ConfigurationManager.AppSettings["nodeId"]; //get the crypto provider to use from the App.config string cryptoProvider = System.Configuration.ConfigurationManager.AppSettings["cryptoProvider"]; string cryptoProviderFilename = Path.Combine(appDir, cryptoProvider + "_CryptoProvider.dll"); string keyFilename = Path.Combine(appDir, cryptoProvider + ".key"); //load the specified crypto provider if (File.Exists(cryptoProviderFilename)) { _cryptoProvider = LoadCryptoProvider(cryptoProviderFilename); } else { throw new Exception(string.Format("Crypto Provider not found : {0}", cryptoProviderFilename)); } //load the server node key pair (not currently used) if (File.Exists(keyFilename)) { _cryptoProvider.ImportKeyPairFromFile(keyFilename); } else { _cryptoProvider.GenerateKeyPair(); _cryptoProvider.ExportKeyPairToFile(keyFilename); Logger.Log("Key pair generated"); } //create a new server node web-server instance and intialize the server node's block chain chain = new BlockChain(); server = new WebServer(chain); System.Console.WriteLine("BlockChainServerNode initialized with an empty chain"); //If a previous server node state was saved, load it chain.Rollback(); //display the server node status chain.status(); System.Console.WriteLine("enter help for a list of commands"); bool exit = false; string cmd = ""; //main command loop while (!exit) { System.Console.Write($"Server {nodeId}>"); cmd = System.Console.ReadLine().Trim().ToLower(); string[] cmdArgs = cmd.Split(' '); switch (cmdArgs[0]) { case "help": help(cmdArgs); break; case "checkpoint": checkpoint(cmdArgs); break; case "rollback": rollback(cmdArgs); break; case "exit": checkpoint(cmdArgs); exit = true; break; case "init": init(cmdArgs); break; case "echo": echo(cmdArgs); break; case "status": status(cmdArgs); break; case "list": list(cmdArgs); break; case "publickey": publicKey(cmdArgs); break; case "balance": Balance(cmdArgs); break; case "validate": validate(); break; case "resolve": Resolve(false); break; case "mine": Mine(cmdArgs); break; case "miner": miner(cmdArgs); break; } } }