private WalletMessenger(UserContext userContext) { _userContext = userContext; _token = _userContext.Token; _walletProvider = new WalletProvider(_userContext); _messenger.RegisterAsync <WalletAllRequestMessage>(this, _token, WalletAllRequestMessage); _messenger.RegisterAsync <WalletAddressRequestMessage>(this, _token, WalletAddressRequestMessage); }
public CommandFabric(IRequestFabric fabric, AsyncListener asyncListener, Blockchain blockchain) { WalletProvider.UnlockWallet(); requestFabric = fabric; listener = asyncListener; Blockchain = blockchain; listener.StartListening(); threadsInfo = new Dictionary <string, int>(); }
public void Run(string[] args) { Console.WriteLine("Wallet creation..."); WalletProvider walletProvider = new WalletProvider(); if (!walletProvider.HasWallet()) { walletProvider.GenerateWallet(); } else { Console.WriteLine("Already has wallet..."); Console.WriteLine(walletProvider.Address); } }
public Block AddBlock(int nonce, WalletProvider walletProvider) { string lastBlockHash = this.LastBlock.BlockHash; string winnerHash = CryptographyUtilities.BytesToHex(CryptographyUtilities.CalcSHA256($"{lastBlockHash}{nonce}")); if (!winnerHash.ToCharArray().Take(this.Difficulty).All(s => s == '0')) { Console.WriteLine("Incorrect winner hash..."); return(null); } var transactions = this.pendingTransactions; foreach (var transaction in transactions) { transaction.DateReceived = DateTime.Now; transaction.MinedInBlockIndex = this.LastBlock.Index + 1; } var block = new Block() { Index = this.LastBlock.Index + 1, DateCreated = DateTime.Now, Difficulty = this.Difficulty, MinedBy = walletProvider.Address, Nonce = nonce, PreviousBlockHash = this.LastBlock.BlockHash, Transactions = transactions.ToList() }; string blockJson = JsonConvert.SerializeObject(block); var blockHash = CryptographyUtilities.BytesToHex(CryptographyUtilities.CalcSHA256(blockJson)); block.BlockHash = blockHash; this.blocks.Add(block); StorageFileProvider <Block> .SetModel($"{Constants.BlocksFilePath}/block_{block.Index}.json", block); //Shoud think :-) this.pendingTransactions = new List <Transaction>(); StorageFileProvider <Transaction[]> .SetModel(Constants.PendingTransactionsFilePath, this.pendingTransactions.ToArray()); return(block); }
public GetAccountInfo() { this.blockchain = CommandFabric.Blockchain; this.walletProvider = new WalletProvider(); }
public AddTransaction() { this.blockchain = CommandFabric.Blockchain; this.walletProvider = new WalletProvider(); }
public SendMiningResult() { this.walletProvider = new WalletProvider(); this.blockchain = CommandFabric.Blockchain; }