Exemple #1
0
        public IExpressStore GetCheckpointStore(string checkPointPath)
        {
            if (chain.ConsensusNodes.Count != 1)
            {
                throw new ArgumentException("Checkpoint restore is only supported on single node express instances", nameof(chain));
            }

            var node = chain.ConsensusNodes[0];

            if (IsRunning(node))
            {
                throw new Exception($"node already running");
            }

            checkPointPath = ResolveCheckpointFileName(checkPointPath);
            if (!fileSystem.File.Exists(checkPointPath))
            {
                throw new Exception($"Checkpoint {checkPointPath} couldn't be found");
            }

            var checkpointTempPath = fileSystem.GetTempFolder();
            var folderCleanup      = AnonymousDisposable.Create(() =>
            {
                if (fileSystem.Directory.Exists(checkpointTempPath))
                {
                    fileSystem.Directory.Delete(checkpointTempPath, true);
                }
            });

            var multiSigAccount = node.Wallet.Accounts.Single(a => a.IsMultiSigContract());

            RocksDbStore.RestoreCheckpoint(checkPointPath, checkpointTempPath, chain.Magic, multiSigAccount.ScriptHash);
            return(new CheckpointStore(RocksDbStore.OpenReadOnly(checkpointTempPath), true, folderCleanup));
        }
Exemple #2
0
        public IExpressStore GetNodeStore(ExpressConsensusNode node, bool discard)
        {
            var folder = fileSystem.GetNodePath(node);

            if (discard)
            {
                try
                {
                    var rocksDbStore = RocksDbStore.OpenReadOnly(folder);
                    return(new CheckpointStore(rocksDbStore));
                }
                catch
                {
                    return(new CheckpointStore(NullReadOnlyStore.Instance));
                }
            }
            else
            {
                return(RocksDbStore.Open(folder));
            }
        }