Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 public CommandFabric(IRequestFabric fabric, AsyncListener asyncListener, Blockchain blockchain)
 {
     WalletProvider.UnlockWallet();
     requestFabric = fabric;
     listener      = asyncListener;
     Blockchain    = blockchain;
     listener.StartListening();
     threadsInfo = new Dictionary <string, int>();
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public GetAccountInfo()
 {
     this.blockchain     = CommandFabric.Blockchain;
     this.walletProvider = new WalletProvider();
 }
Ejemplo n.º 6
0
 public AddTransaction()
 {
     this.blockchain     = CommandFabric.Blockchain;
     this.walletProvider = new WalletProvider();
 }
Ejemplo n.º 7
0
 public SendMiningResult()
 {
     this.walletProvider = new WalletProvider();
     this.blockchain     = CommandFabric.Blockchain;
 }