Skip to content

Commit 0b16530

Browse files
Code cleanup to comply with new convention
1 parent f54839b commit 0b16530

9 files changed

+37
-37
lines changed

Src/Denovo/Models/UtxoModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public bool TryConvertToUtxo(out Utxo result, out string error)
5959
return false;
6060
}
6161

62-
var scr = new PubkeyScript(scrBa);
62+
PubkeyScript scr = new(scrBa);
6363
result = new Utxo(Index, Amount, scr);
6464
error = null;
6565
return true;

Src/Denovo/Services/FileManager.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void AppendData(byte[] data, string fileName, string dir)
8080
string path = Path.Combine(dir, $"{fileName}.ddat");
8181
if (File.Exists(path))
8282
{
83-
using FileStream stream = new FileStream(path, FileMode.Append);
83+
using FileStream stream = new(path, FileMode.Append);
8484
stream.Write(data);
8585
}
8686
else
@@ -133,7 +133,7 @@ private void WriteData(byte[] data, string fileName, string dir)
133133
private void WriteBlockInfo(IBlock block)
134134
{
135135
// block hash[32] | block size[4] | file name[4]
136-
var stream = new FastStream(32 + 4 + 4);
136+
FastStream stream = new(32 + 4 + 4);
137137
stream.Write(block.Header.GetHash(false));
138138
stream.Write(block.TotalSize);
139139
stream.Write(blockFileNum);
@@ -145,11 +145,11 @@ private void WriteBlockInfo(IBlock block)
145145
/// <inheritdoc/>
146146
public void WriteBlock(IBlock block)
147147
{
148-
var temp = new FastStream(block.TotalSize);
148+
FastStream temp = new(block.TotalSize);
149149
block.Serialize(temp);
150150

151151
string fileName = $"Block{blockFileNum:D6}";
152-
var info = new FileInfo(Path.Combine(blockDir, fileName));
152+
FileInfo info = new(Path.Combine(blockDir, fileName));
153153
long len = info.Exists ? info.Length : 0;
154154
if (len + temp.GetSize() > Max)
155155
{

Src/Denovo/Services/TestNetMiner.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public async Task<IBlock> Start(IBlock prev, int height, CancellationToken token
3434
// and IBlockchain.GetTarget() to mine at the correct difficulty.
3535
// For now it is a good way of mining any transaction that won't propagate in TestNet by bitcoin core clients.
3636

37-
var consensus = new Consensus(height, NetworkType.TestNet);
37+
Consensus consensus = new(height, NetworkType.TestNet);
3838
string cbText = "Mined using Denovo v0.1.0";
3939
// A weak key used only for testing
40-
using var key = new PrivateKey(new Sha256().ComputeHash(Encoding.UTF8.GetBytes(cbText)));
41-
var pkScr = new PubkeyScript();
40+
using PrivateKey key = new(new Sha256().ComputeHash(Encoding.UTF8.GetBytes(cbText)));
41+
PubkeyScript pkScr = new();
4242
pkScr.SetToP2WPKH(key.ToPublicKey());
4343

4444
byte[] commitment = null;
@@ -48,7 +48,7 @@ public async Task<IBlock> Start(IBlock prev, int height, CancellationToken token
4848

4949
ulong fee = 0;
5050

51-
var coinbase = new Transaction()
51+
Transaction coinbase = new()
5252
{
5353
Version = 1,
5454
TxInList = new TxIn[]
@@ -67,7 +67,7 @@ public async Task<IBlock> Start(IBlock prev, int height, CancellationToken token
6767
((PubkeyScript)coinbase.TxOutList[1].PubScript).SetToReturn(Encoding.UTF8.GetBytes("Testing Mining View Model."));
6868

6969

70-
var block = new Block()
70+
Block block = new()
7171
{
7272
Header = new BlockHeader()
7373
{
@@ -86,7 +86,7 @@ public async Task<IBlock> Start(IBlock prev, int height, CancellationToken token
8686
new Witness(new byte[][]{ commitment })
8787
};
8888

89-
var temp = new TxOut[coinbase.TxOutList.Length + 1];
89+
TxOut[] temp = new TxOut[coinbase.TxOutList.Length + 1];
9090
Array.Copy(coinbase.TxOutList, 0, temp, 0, coinbase.TxOutList.Length);
9191
temp[^1] = new TxOut();
9292

Src/Denovo/Services/UtxoDatabase.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ private void Init()
6767
byte[] data = fileMan.ReadData(DbName);
6868
if (data is not null && data.Length != 0)
6969
{
70-
var stream = new FastStreamReader(data);
70+
FastStreamReader stream = new(data);
7171
while (true)
7272
{
73-
var utxo = new Utxo();
73+
Utxo utxo = new();
7474
if (stream.TryReadByteArray(32, out byte[] hash) && utxo.TryDeserialize(stream, out _))
7575
{
7676
if (database.ContainsKey(hash))
@@ -92,7 +92,7 @@ private void Init()
9292
data = fileMan.ReadData(CoinBaseDbName);
9393
if (data is not null && data.Length != 0)
9494
{
95-
var stream = new FastStreamReader(data);
95+
FastStreamReader stream = new(data);
9696
if (!stream.CheckRemaining(8))
9797
{
9898
return;
@@ -102,7 +102,7 @@ private void Init()
102102
int index = 0;
103103
while (true)
104104
{
105-
var coinbase = new Transaction();
105+
Transaction coinbase = new();
106106
if (coinbase.TryDeserialize(stream, out _))
107107
{
108108
coinbaseQueue[index++] = coinbase;
@@ -118,10 +118,10 @@ private void Init()
118118

119119
private void WriteCoinbaseToDisk()
120120
{
121-
var stream = new FastStream(coinbaseQueue.Length * 250);
121+
FastStream stream = new(coinbaseQueue.Length * 250);
122122
stream.Write(i1);
123123
stream.Write(i2);
124-
foreach (var item in coinbaseQueue)
124+
foreach (ITransaction item in coinbaseQueue)
125125
{
126126
if (item is null)
127127
{
@@ -164,10 +164,10 @@ private void UpdateCoinbase(ITransaction coinbase)
164164

165165
private void WriteDbToDisk()
166166
{
167-
var stream = new FastStream(database.Count * 90);
168-
foreach (var item in database)
167+
FastStream stream = new(database.Count * 90);
168+
foreach (KeyValuePair<byte[], List<Utxo>> item in database)
169169
{
170-
foreach (var item2 in item.Value)
170+
foreach (Utxo item2 in item.Value)
171171
{
172172
stream.Write(item.Key);
173173
item2.Serialize(stream);
@@ -182,7 +182,7 @@ public IUtxo Find(TxIn tin)
182182
{
183183
if (database.TryGetValue(tin.TxHash, out List<Utxo> value))
184184
{
185-
var index = value.FindIndex(x => x.Index == tin.Index);
185+
int index = value.FindIndex(x => x.Index == tin.Index);
186186
return index < 0 ? null : value[index];
187187
}
188188
else
@@ -238,7 +238,7 @@ public void Undo(ITransaction[] txs, int lastIndex)
238238

239239
for (int i = 1; i <= lastIndex; i++)
240240
{
241-
foreach (var item in txs[i].TxInList)
241+
foreach (TxIn item in txs[i].TxInList)
242242
{
243243
IUtxo utxo = Find(item);
244244
if (utxo is not null)

Src/Denovo/Services/WindowManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class WindowManager : IWindowManager
2121
{
2222
public Task ShowDialog(VmWithSizeBase vm)
2323
{
24-
Window win = new Window()
24+
Window win = new()
2525
{
2626
Content = vm,
2727
WindowStartupLocation = WindowStartupLocation.CenterOwner,

Src/Denovo/ViewModels/AboutViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static void ShellExec(string cmd, bool waitForExit = true)
6161
{
6262
string escapedArgs = cmd.Replace("\"", "\\\"");
6363

64-
using var process = Process.Start(
64+
using Process process = Process.Start(
6565
new ProcessStartInfo
6666
{
6767
FileName = "/bin/sh",

Src/Denovo/ViewModels/MainWindowViewModel.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ private void Init(Configuration config)
6868
FileMan.SetBlockPath(config.BlockchainPath);
6969

7070
AllNodes = new NodePool(config.MaxConnectionCount);
71-
var utxoDb = new UtxoDatabase(FileMan);
72-
var memPool = new MemoryPool();
71+
UtxoDatabase utxoDb = new(FileMan);
72+
MemoryPool memPool = new();
7373
clientSettings =
7474
new FullClientSettings(
7575
config.AcceptIncoming,
@@ -112,7 +112,7 @@ public async void OpenConfig()
112112
config = new Configuration(Network) { IsDefault = true };
113113
}
114114

115-
var vm = new ConfigurationViewModel(config);
115+
ConfigurationViewModel vm = new(config);
116116
await WinMan.ShowDialog(vm);
117117

118118
if (vm.IsChanged)
@@ -129,32 +129,32 @@ public async void OpenConfig()
129129
public async void OpenMiner()
130130
{
131131
// TODO: A better way is to make the following VM disposable
132-
var vm = new MinerViewModel();
132+
MinerViewModel vm = new();
133133
await WinMan.ShowDialog(vm);
134134
vm.StopMining();
135135
}
136136

137137
public async void OpenEcies()
138138
{
139-
var vm = new EciesViewModel();
139+
EciesViewModel vm = new();
140140
await WinMan.ShowDialog(vm);
141141
}
142142

143143
public async void OpenVerifyTx()
144144
{
145-
var vm = new VerifyTxViewModel();
145+
VerifyTxViewModel vm = new();
146146
await WinMan.ShowDialog(vm);
147147
}
148148

149149
public async void OpenWifHelper()
150150
{
151-
var vm = new WifHelperViewModel();
151+
WifHelperViewModel vm = new();
152152
await WinMan.ShowDialog(vm);
153153
}
154154

155155
public async void OpenPushTx()
156156
{
157-
var vm = new PushTxViewModel();
157+
PushTxViewModel vm = new();
158158
await WinMan.ShowDialog(vm);
159159
vm.Dispose();
160160
}

Src/Denovo/ViewModels/MinerViewModel.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MinerViewModel : VmWithSizeBase
2323
public MinerViewModel() : base(650, 650)
2424
{
2525
AllNodes = new NodePool(5);
26-
var clientSettings = new MinimalClientSettings(NetworkType.TestNet, 5, AllNodes)
26+
MinimalClientSettings clientSettings = new(NetworkType.TestNet, 5, AllNodes)
2727
{
2828
DnsSeeds = Configuration.DnsTest,
2929
UserAgent = "/Satoshi:0.22.0/",
@@ -92,7 +92,7 @@ public async void StartMining()
9292
tokenSource?.Dispose();
9393
tokenSource = null;
9494

95-
var prvBlock = new Block();
95+
Block prvBlock = new();
9696
if (!Base16.TryDecode(PreviousBlockHex, out byte[] data))
9797
{
9898
BlockHex = "Invalid hex.";
@@ -111,11 +111,11 @@ public async void StartMining()
111111

112112
if (!(result is null))
113113
{
114-
var stream = new FastStream();
114+
FastStream stream = new();
115115
result.Serialize(stream);
116116
BlockHex = stream.ToByteArray().ToBase16();
117117

118-
var msg = new Message(new BlockPayload(result), NetworkType.TestNet);
118+
Message msg = new(new BlockPayload(result), NetworkType.TestNet);
119119

120120
client.Send(msg);
121121
}

Src/Denovo/ViewModels/VerifyTxViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private set
118118
public BindableCommand VerifyCommand { get; private set; }
119119
private void Verify()
120120
{
121-
var temp = new Utxo[UtxoList.Length];
121+
Utxo[] temp = new Utxo[UtxoList.Length];
122122
for (int i = 0; i < UtxoList.Length; i++)
123123
{
124124
if (!UtxoList[i].TryConvertToUtxo(out Utxo u, out string error))

0 commit comments

Comments
 (0)