Skip to content

Commit 213ac4b

Browse files
committed
Clean style
1 parent ab03bc2 commit 213ac4b

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

src/Plugins/StorageDumper/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private Settings(IConfigurationSection section) : base(section)
4040
StoragePerFolder = section.GetValue("StoragePerFolder", 100000u);
4141
Exclude = section.GetSection("Exclude").Exists()
4242
? section.GetSection("Exclude").GetChildren().Select(p => int.Parse(p.Value!)).ToArray()
43-
: new[] { NativeContract.Ledger.Id };
43+
: [NativeContract.Ledger.Id];
4444
}
4545

4646
public static void Load(IConfigurationSection section)

src/Plugins/StorageDumper/StorageDumper.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Neo.Plugins.StorageDumper
2323
public class StorageDumper : Plugin, ICommittingHandler, ICommittedHandler
2424
{
2525
private NeoSystem? _system;
26-
private readonly Dictionary<uint, JArray> bs_cache = [];
26+
private readonly Dictionary<uint, JArray> _bs_cache = [];
2727
protected override UnhandledExceptionPolicy ExceptionPolicy => Settings.Default?.ExceptionPolicy ?? UnhandledExceptionPolicy.Ignore;
2828

2929
public override string Description => "Exports Neo-CLI status data";
@@ -63,12 +63,12 @@ internal void OnDumpStorage(UInt160? contractHash = null)
6363
byte[]? prefix = null;
6464
if (contractHash is not null)
6565
{
66-
var contract = NativeContract.ContractManagement.GetContract(_system.StoreView, contractHash);
67-
if (contract is null) throw new InvalidOperationException("contract not found");
66+
var contract = NativeContract.ContractManagement.GetContract(_system.StoreView, contractHash)
67+
?? throw new InvalidOperationException("contract not found");
6868
prefix = BitConverter.GetBytes(contract.Id);
6969
}
7070
var states = _system.StoreView.Find(prefix);
71-
JArray array = new JArray(states.Where(p => !Settings.Default!.Exclude.Contains(p.Key.Id)).Select(p => new JObject
71+
var array = new JArray(states.Where(p => !Settings.Default!.Exclude.Contains(p.Key.Id)).Select(p => new JObject
7272
{
7373
["key"] = Convert.ToBase64String(p.Key.ToArray()),
7474
["value"] = Convert.ToBase64String(p.Value.ToArray())
@@ -90,7 +90,7 @@ private void OnPersistStorage(uint network, DataCache snapshot)
9090
var blockIndex = NativeContract.Ledger.CurrentIndex(snapshot);
9191
if (blockIndex >= Settings.Default!.HeightToBegin)
9292
{
93-
JArray array = new JArray();
93+
var array = new JArray();
9494

9595
foreach (var trackable in snapshot.GetChangeSet())
9696
{
@@ -124,29 +124,29 @@ private void OnPersistStorage(uint network, DataCache snapshot)
124124
bs_item["block"] = blockIndex;
125125
bs_item["size"] = array.Count;
126126
bs_item["storage"] = array;
127-
if (!bs_cache.TryGetValue(network, out var cache))
127+
if (!_bs_cache.TryGetValue(network, out var cache))
128128
{
129-
cache = new JArray();
129+
cache = [];
130130
}
131131
cache.Add(bs_item);
132-
bs_cache[network] = cache;
132+
_bs_cache[network] = cache;
133133
}
134134
}
135135

136136

137137
void ICommittedHandler.Blockchain_Committed_Handler(NeoSystem system, Block block)
138138
{
139-
OnCommitStorage(system.Settings.Network, system);
139+
OnCommitStorage(system.Settings.Network, system.GetSnapshotCache());
140140
}
141141

142-
void OnCommitStorage(uint network, NeoSystem system)
142+
void OnCommitStorage(uint network, IReadOnlyStore snapshot)
143143
{
144-
if (!bs_cache.TryGetValue(network, out var cache)) return;
144+
if (!_bs_cache.TryGetValue(network, out var cache)) return;
145145
if (cache.Count == 0) return;
146-
uint blockIndex = NativeContract.Ledger.CurrentIndex(system.GetSnapshotCache());
146+
var blockIndex = NativeContract.Ledger.CurrentIndex(snapshot);
147147
if (blockIndex % Settings.Default!.BlockCacheSize == 0)
148148
{
149-
string path = HandlePaths(network, blockIndex);
149+
var path = HandlePaths(network, blockIndex);
150150
path = $"{path}/dump-block-{blockIndex}.json";
151151
File.WriteAllText(path, cache.ToString());
152152
cache.Clear();
@@ -155,20 +155,13 @@ void OnCommitStorage(uint network, NeoSystem system)
155155

156156
private static string HandlePaths(uint network, uint blockIndex)
157157
{
158-
uint storagePerFolder = Settings.Default!.StoragePerFolder;
159-
uint folder = (((blockIndex - 1) / storagePerFolder) + 1) * storagePerFolder;
158+
var storagePerFolder = Settings.Default!.StoragePerFolder;
159+
var folder = (((blockIndex - 1) / storagePerFolder) + 1) * storagePerFolder;
160160
if (blockIndex == 0)
161161
folder = 0;
162-
string dirPathWithBlock = $"./Storage_{network:x8}/BlockStorage_{folder}";
162+
var dirPathWithBlock = $"./Storage_{network:x8}/BlockStorage_{folder}";
163163
Directory.CreateDirectory(dirPathWithBlock);
164164
return dirPathWithBlock;
165165
}
166-
167-
private string GetDirectoryPath(uint network, uint blockIndex)
168-
{
169-
uint folder = (blockIndex / Settings.Default!.StoragePerFolder) * Settings.Default.StoragePerFolder;
170-
return $"./StorageDumper_{network}/BlockStorage_{folder}";
171-
}
172-
173166
}
174167
}

0 commit comments

Comments
 (0)