Ejemplo n.º 1
0
        public Boolean Save(IChainStorageProvider StorageProvider, System.Security.Cryptography.HashAlgorithm _HashAlgorithm)
        {
            TimeStamp = DateTime.Now;
            this.PreviousBlockHash = StorageProvider.PopBlock()?.BlockHash;
            this.BlockHash         = _generateHashOfSelf(_HashAlgorithm);

            return(StorageProvider.Add(this));
        }
Ejemplo n.º 2
0
 // If required, this routine will empty the blockchain storage prior to each test
 public void ResetStore(IChainStorageProvider store)
 {
     switch (store.GetType().ToString())
     {
     case "SimpleBlockChain.RedisChainStorageProvider":
         ConnectionMultiplexer redis = ConnectionMultiplexer.Connect($"{RedisIp}:{RedisPort},allowAdmin=true");
         IServer server = redis.GetServer($"{RedisIp}:{RedisPort}");
         server.FlushDatabase(0);
         break;
     }
 }
Ejemplo n.º 3
0
        public void Initiate(INodeConnector NodeConnector = null, IChainStorageProvider ChainStore = null, Boolean SkipGenesisBlock = false)
        {
            if (ChainStore == null)
            {
                ChainStore = new InMemoryChainStorageProvider();
            }
            ;

            BlockChain = ChainStore;

            BlockChain.initiate();

            if (NodeConnector != null)
            {
                this.NodeConnector = NodeConnector;
                //this.NodeConnector.RegisterNode(this);
            }

            if ((NodeConnector == null || NodeConnector?.TotalNodeCount() == 0) && SkipGenesisBlock != true)
            {
                // This node either has no connector (is therefore independent) or has a connector but
                // is only listening (hasn't connected to an existing network, possibly the first for a new network)
                AddGenesisBlock();
            }
            else
            {
                // This node if part of a network of nodes, populate our blockchain with that
                // of the primary connected node.


                // BlockChain = NodeConnector.RequestInitialBlockChain();
                // if(!(BlockChain?.Count > 0))
                // {
                //     throw new Exception("Unable to retrieve initial blockchain from connected node");
                // }
            }



            Initiated = true;
        }