Skip to content

Commit

Permalink
v2.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Jan 7, 2019
1 parent 768b885 commit 64826c0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 55 deletions.
4 changes: 2 additions & 2 deletions ApplicationLogs/ApplicationLogs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.9.3</Version>
<Version>2.9.4</Version>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.9.3" />
<PackageReference Include="Neo" Version="2.9.4" />
</ItemGroup>

</Project>
91 changes: 47 additions & 44 deletions ImportBlocks/ImportBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,14 @@
using System.IO.Compression;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Neo.Plugins
{
public class ImportBlocks : Plugin
{
public ImportBlocks()
{
Task.Run(() =>
{
const string path_acc = "chain.acc";
if (File.Exists(path_acc))
using (FileStream fs = new FileStream(path_acc, FileMode.Open, FileAccess.Read, FileShare.Read))
System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(fs)
}).Wait();
const string path_acc_zip = path_acc + ".zip";
if (File.Exists(path_acc_zip))
using (FileStream fs = new FileStream(path_acc_zip, FileMode.Open, FileAccess.Read, FileShare.Read))
using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
using (Stream zs = zip.GetEntry(path_acc).Open())
System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(zs)
}).Wait();
var paths = Directory.EnumerateFiles(".", "chain.*.acc", SearchOption.TopDirectoryOnly).Concat(Directory.EnumerateFiles(".", "chain.*.acc.zip", SearchOption.TopDirectoryOnly)).Select(p => new
{
FileName = Path.GetFileName(p),
Start = uint.Parse(Regex.Match(p, @"\d+").Value),
IsCompressed = p.EndsWith(".zip")
}).OrderBy(p => p.Start);
foreach (var path in paths)
{
if (path.Start > Blockchain.Singleton.Height + 1) break;
if (path.IsCompressed)
using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
using (Stream zs = zip.GetEntry(Path.GetFileNameWithoutExtension(path.FileName)).Open())
System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(zs, true)
}).Wait();
else
using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(fs, true)
}).Wait();
}
});
OnImport();
}

private static bool CheckMaxOnImportHeight(uint currentImportBlockHeight)
Expand Down Expand Up @@ -181,6 +138,52 @@ private bool OnHelp(string[] args)
return true;
}

private async void OnImport()
{
SuspendNodeStartup();
const string path_acc = "chain.acc";
if (File.Exists(path_acc))
using (FileStream fs = new FileStream(path_acc, FileMode.Open, FileAccess.Read, FileShare.Read))
await System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(fs)
});
const string path_acc_zip = path_acc + ".zip";
if (File.Exists(path_acc_zip))
using (FileStream fs = new FileStream(path_acc_zip, FileMode.Open, FileAccess.Read, FileShare.Read))
using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
using (Stream zs = zip.GetEntry(path_acc).Open())
await System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(zs)
});
var paths = Directory.EnumerateFiles(".", "chain.*.acc", SearchOption.TopDirectoryOnly).Concat(Directory.EnumerateFiles(".", "chain.*.acc.zip", SearchOption.TopDirectoryOnly)).Select(p => new
{
FileName = Path.GetFileName(p),
Start = uint.Parse(Regex.Match(p, @"\d+").Value),
IsCompressed = p.EndsWith(".zip")
}).OrderBy(p => p.Start);
foreach (var path in paths)
{
if (path.Start > Blockchain.Singleton.Height + 1) break;
if (path.IsCompressed)
using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Read))
using (Stream zs = zip.GetEntry(Path.GetFileNameWithoutExtension(path.FileName)).Open())
await System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(zs, true)
});
else
using (FileStream fs = new FileStream(path.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
await System.Blockchain.Ask<Blockchain.ImportCompleted>(new Blockchain.Import
{
Blocks = GetBlocks(fs, true)
});
}
ResumeNodeStartup();
}

protected override bool OnMessage(object message)
{
if (!(message is string[] args)) return false;
Expand Down
4 changes: 2 additions & 2 deletions ImportBlocks/ImportBlocks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.9.3</Version>
<Version>2.9.4</Version>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.9.3" />
<PackageReference Include="Neo" Version="2.9.4" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions RpcSecurity/RpcSecurity.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.9.3</Version>
<Version>2.9.4</Version>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.9.3" />
<PackageReference Include="Neo" Version="2.9.4" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions SimplePolicy/SimplePolicy.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.9.3</Version>
<Version>2.9.4</Version>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
<LangVersion>latest</LangVersion>
Expand All @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.9.3" />
<PackageReference Include="Neo" Version="2.9.4" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion StatesDumper/StatesDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private bool OnHelp(string[] args)
return true;
}

public void OnPersist(Snapshot snapshot)
public void OnPersist(Snapshot snapshot, IReadOnlyList<Blockchain.ApplicationExecuted> applicationExecutedList)
{
if (Settings.Default.PersistAction.HasFlag(PersistActions.StorageChanges))
OnPersistStorage(snapshot);
Expand Down
4 changes: 2 additions & 2 deletions StatesDumper/StatesDumper.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>2.9.3</Version>
<Version>2.9.4</Version>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.9.3" />
<PackageReference Include="Neo" Version="2.9.4" />
</ItemGroup>

</Project>

0 comments on commit 64826c0

Please sign in to comment.