@@ -23,7 +23,7 @@ namespace Neo.Plugins.StorageDumper
23
23
public class StorageDumper : Plugin , ICommittingHandler , ICommittedHandler
24
24
{
25
25
private NeoSystem ? _system ;
26
- private readonly Dictionary < uint , JArray > bs_cache = [ ] ;
26
+ private readonly Dictionary < uint , JArray > _bs_cache = [ ] ;
27
27
protected override UnhandledExceptionPolicy ExceptionPolicy => Settings . Default ? . ExceptionPolicy ?? UnhandledExceptionPolicy . Ignore ;
28
28
29
29
public override string Description => "Exports Neo-CLI status data" ;
@@ -63,12 +63,12 @@ internal void OnDumpStorage(UInt160? contractHash = null)
63
63
byte [ ] ? prefix = null ;
64
64
if ( contractHash is not null )
65
65
{
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" ) ;
68
68
prefix = BitConverter . GetBytes ( contract . Id ) ;
69
69
}
70
70
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
72
72
{
73
73
[ "key" ] = Convert . ToBase64String ( p . Key . ToArray ( ) ) ,
74
74
[ "value" ] = Convert . ToBase64String ( p . Value . ToArray ( ) )
@@ -90,7 +90,7 @@ private void OnPersistStorage(uint network, DataCache snapshot)
90
90
var blockIndex = NativeContract . Ledger . CurrentIndex ( snapshot ) ;
91
91
if ( blockIndex >= Settings . Default ! . HeightToBegin )
92
92
{
93
- JArray array = new JArray ( ) ;
93
+ var array = new JArray ( ) ;
94
94
95
95
foreach ( var trackable in snapshot . GetChangeSet ( ) )
96
96
{
@@ -124,29 +124,29 @@ private void OnPersistStorage(uint network, DataCache snapshot)
124
124
bs_item [ "block" ] = blockIndex ;
125
125
bs_item [ "size" ] = array . Count ;
126
126
bs_item [ "storage" ] = array ;
127
- if ( ! bs_cache . TryGetValue ( network , out var cache ) )
127
+ if ( ! _bs_cache . TryGetValue ( network , out var cache ) )
128
128
{
129
- cache = new JArray ( ) ;
129
+ cache = [ ] ;
130
130
}
131
131
cache . Add ( bs_item ) ;
132
- bs_cache [ network ] = cache ;
132
+ _bs_cache [ network ] = cache ;
133
133
}
134
134
}
135
135
136
136
137
137
void ICommittedHandler . Blockchain_Committed_Handler ( NeoSystem system , Block block )
138
138
{
139
- OnCommitStorage ( system . Settings . Network , system ) ;
139
+ OnCommitStorage ( system . Settings . Network , system . GetSnapshotCache ( ) ) ;
140
140
}
141
141
142
- void OnCommitStorage ( uint network , NeoSystem system )
142
+ void OnCommitStorage ( uint network , IReadOnlyStore snapshot )
143
143
{
144
- if ( ! bs_cache . TryGetValue ( network , out var cache ) ) return ;
144
+ if ( ! _bs_cache . TryGetValue ( network , out var cache ) ) return ;
145
145
if ( cache . Count == 0 ) return ;
146
- uint blockIndex = NativeContract . Ledger . CurrentIndex ( system . GetSnapshotCache ( ) ) ;
146
+ var blockIndex = NativeContract . Ledger . CurrentIndex ( snapshot ) ;
147
147
if ( blockIndex % Settings . Default ! . BlockCacheSize == 0 )
148
148
{
149
- string path = HandlePaths ( network , blockIndex ) ;
149
+ var path = HandlePaths ( network , blockIndex ) ;
150
150
path = $ "{ path } /dump-block-{ blockIndex } .json";
151
151
File . WriteAllText ( path , cache . ToString ( ) ) ;
152
152
cache . Clear ( ) ;
@@ -155,20 +155,13 @@ void OnCommitStorage(uint network, NeoSystem system)
155
155
156
156
private static string HandlePaths ( uint network , uint blockIndex )
157
157
{
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 ;
160
160
if ( blockIndex == 0 )
161
161
folder = 0 ;
162
- string dirPathWithBlock = $ "./Storage_{ network : x8} /BlockStorage_{ folder } ";
162
+ var dirPathWithBlock = $ "./Storage_{ network : x8} /BlockStorage_{ folder } ";
163
163
Directory . CreateDirectory ( dirPathWithBlock ) ;
164
164
return dirPathWithBlock ;
165
165
}
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
-
173
166
}
174
167
}
0 commit comments