-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
4403 lines (3675 loc) · 195 KB
/
Copy pathMain.cs
File metadata and controls
4403 lines (3675 loc) · 195 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Drawing;
using System.Security.Cryptography;
using System.Web;
using BitcoinNET.RPCClient;
using ADD.Tools;
using System.Threading;
using System.Windows.Media;
using System.Text.RegularExpressions;
using Secp256k1;
using System.Numerics;
using Microsoft.Win32;
using System.ComponentModel;
using System.Drawing.Imaging;
using System.Diagnostics;
namespace ADD
{
public partial class Main : Form
{
public static Dictionary<string, byte> coinVersion;
public static Dictionary<string, string> coinShortName;
public static Dictionary<string, int> coinPayloadByteSize;
public static Dictionary<string, string> coinPort;
public static Dictionary<string, string> coinIP;
public static Dictionary<string, string> coinUser;
public static Dictionary<string, string> coinPassword;
public static Dictionary<string, string> coinSigningAddress;
public static Dictionary<string, string> coinTrackingAddress;
public static Dictionary<string, decimal> coinTransactionFee;
public static Dictionary<string, decimal> coinMinTransaction;
public static Dictionary<string, decimal> coinTipAmount;
public static Dictionary<string, int> coinTransactionSize;
public static Dictionary<string, Boolean> coinEnableMonitoring;
public static Dictionary<string, Boolean> coinFeePerAddress;
public static Dictionary<string, Boolean> coinEnabled;
public static Dictionary<string, Boolean> coinEnableSigning;
public static Dictionary<string, Boolean> coinEnableTracking;
public static Dictionary<string, string> coinHelperUrl;
public static Dictionary<string, string> friendTransID;
public static Dictionary<string, Boolean> coinVariablePayloadByteSize;
public static string CoinType = "";
public static string arcfileName = "";
public static string arcmessage = "";
public static string WalletLabel = "";
public static string SignatureLabel = "";
public static string FriendLabel = "";
public static string VaultLabel = "";
public static string ProfileLabel = "";
public static string TransIDSearch = "";
public static string ProfileID = "";
IDictionary<string, decimal> allAccounts;
Dictionary<string, IEnumerable<string>> coinLastMemoryDump;
Decimal fileSize;
int transactionsSearched = 0;
int transactionsFound = 0;
int msgId = 0;
int fileId = 0;
Boolean trustTrustedlistContent = false;
Boolean blockBlockedListContent = false;
Boolean blockUnSignedContent = false;
Boolean blockUntrustedContent = false;
Boolean followFollowedlistContent = false;
HashSet<string> hashTrustedList = new HashSet<string>(StringComparer.Ordinal);
HashSet<string> hashBlockedList = new HashSet<string>(StringComparer.Ordinal);
HashSet<string> hashFollowedList = new HashSet<string>(StringComparer.Ordinal);
HashSet<string> hashFavoritedList = new HashSet<string>(StringComparer.Ordinal);
HashSet<string> hashFriendList = new HashSet<string>(StringComparer.Ordinal);
List<string> batchList = new List<string>();
static readonly object _batchLocker = new object();
static readonly object _buildLocker = new object();
GlyphTypeface glyphTypeface = new GlyphTypeface(new Uri("file:///C:\\WINDOWS\\Fonts\\Arial.ttf"));
IDictionary<int, ushort> characterMap;
string[] infoArray;
bool Loading = true;
string PROLinks = "";
string lastTransID = "";
string strProofAddress = "";
decimal totalTransactionCost = 0;
public Main()
{
InitializeComponent();
Startup();
backgroundWorker1.WorkerReportsProgress = true;
}
public void Startup()
{
Tools.WebBrowserHelper.FixBrowserVersion();
tmrProcessBatch.Start();
characterMap = glyphTypeface.CharacterToGlyphMap;
infoArray = "Apertus immutably stores and interprets data on blockchains.|Never build files or click links from sources you do not trust.|Send a direct message by using @ followed by Address.|Click Help, then info for assistance.|Create a Profile and start sharing your thoughts.|#keywords allow people to discover and follow your causes.|Encrypt items by creating and selecting a Vault.|Signing your archives allows people to trust you.|This is beta software use at your own risk!|Press CTRL while submitting a search to rebuild the cache.|Search by Trans ID, Address, Free Text or #Keyword|Publish your work using a profile, signature, & tip address".Split('|');
URLSecurityZoneAPI.InternetSetFeatureEnabled(URLSecurityZoneAPI.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS, URLSecurityZoneAPI.SetFeatureOn.PROCESS, true);
}
private char GetRandomDivider()
{
char[] chars = "\\/:*?\"><|".ToCharArray();
Random r = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);
int i = r.Next(chars.Length);
System.Threading.Thread.Sleep(100);
return chars[i];
}
private string GetURL(string url)
{
if (url.ToUpper().StartsWith("HTTP"))
{
return url;
}
return "http://" + url;
}
private string GetRandomBuffer(int BufferLength)
{
//Quick Fix to allow Keyword functionality will eventually deprecate this call.
const string allowedChars = "####################";
char[] chars = new char[BufferLength];
var rd = new Random();
for (int i = 0; i < BufferLength; i++)
{
chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
}
return new string(chars);
}
private void processLedger(string processId)
{
System.IO.StreamReader readLGR = new System.IO.StreamReader("process\\" + processId + ".LGR");
string line = "";
string TransId = null;
int lineCount = 0;
while ((line = readLGR.ReadLine()) != null && lineCount <= 1)
{
if (TransId == null) { TransId = line; }
lineCount++;
}
readLGR.Close();
if (lineCount > 1)
{
CreateLedgerFile(coinPayloadByteSize[CoinType], GetRandomBuffer(coinPayloadByteSize[CoinType]), coinIP[CoinType], coinPort[CoinType], coinUser[CoinType], coinPassword[CoinType], WalletLabel, coinVersion[CoinType], coinMinTransaction[CoinType], "process\\" + processId + ".LGR", TransId, "");
}
else
{
lock (_buildLocker)
{
totalTransactionCost = 0;
CreateArchive(TransId, CoinType, false, false, null, null, true);
}
}
}
public void CreateLedgerFile(int PayloadByteSize, string Padding, string WalletRPCIP, string WalletRPCPort, string WalletRPCUser, string WalletRPCPassword, string WalletLabel, byte CoinVersion, decimal CoinMinTransaction, string FilePath = null, string ledgerId = null, string TextMessage = null)
{
int HeaderPaddingSize = coinPayloadByteSize[CoinType];
if (coinVariablePayloadByteSize[CoinType]) { HeaderPaddingSize = 10; }
String processId = Guid.NewGuid().ToString();
byte[] arcPayloadBytes = new byte[PayloadByteSize + 1];
byte[] arcPadding = UTF8Encoding.UTF8.GetBytes(Padding);
arcPayloadBytes[0] = CoinVersion;
int payloadBytePosition = 1;
byte[] fileBytes = null;
byte[] buffer = null;
byte[] msgBytes = null;
string cglText = "";
Dictionary<string, decimal> toMany = new Dictionary<string, decimal>();
Dictionary<string, decimal> lastTransaction = new Dictionary<string, decimal>();
string lastT = null;
string curT = null;
string lastTransactionID = null;
HashSet<string> addressHash = new HashSet<string>(StringComparer.Ordinal);
string signingAddress = null;
string line;
int tranCount = 1;
int ledgerCount = 0;
string transactionId = "";
int fileCount = 0;
int totalMsgSize = 0;
CoinRPC b = new CoinRPC(new Uri(GetURL(WalletRPCIP) + ":" + WalletRPCPort), new NetworkCredential(WalletRPCUser, WalletRPCPassword));
if (coinTransactionFee[CoinType] > 0) { b.SetTXFee(coinTransactionFee[CoinType]); }
try
{
if (!FilePath.ToUpper().EndsWith(".ADD"))
{
if (TextMessage.Length > 0)
{
if (chkNoMessage.Checked) { TextMessage = ""; }
msgBytes = Encoding.UTF8.GetBytes(TextMessage);
cglText = GetRandomDivider() + msgBytes.Length.ToString().PadLeft(HeaderPaddingSize - 2, '0') + GetRandomDivider();
totalMsgSize = msgBytes.Length + cglText.Length;
}
//Links the Appropriate Profile if Profile is selected.
if (ProfileID != "" && Path.GetFileName(FilePath) != "SEC" && ledgerId == null) {
string CoinExtension = "";
if (coinVariablePayloadByteSize[CoinType]) { CoinExtension = "@" + coinShortName[CoinType].Substring(0, coinShortName[CoinType].IndexOf('-')); }
if (FilePath.Length == 0) { FilePath = ProfileID+CoinExtension; } else { FilePath = FilePath + "," + ProfileID+CoinExtension; }
}
if (FilePath.Length > 0)
{
var mergeFiles = FilePath.Split(',');
bool isLNKFile = false;
byte[] readFileBytes;
foreach (var f in mergeFiles)
{
//additional logic and padding to ensure text data begins at byte[0] to assist in future searching.
fileCount++;
var intCurrentSize = 0;
readFileBytes = null;
var fileName = f;
Match match = Regex.Match(fileName, @"([a-fA-F0-9]{64})");
if (match.Success)
{
if (!isLNKFile)
{
var buildLNKFile = "";
foreach (var l in mergeFiles)
{
var match2 = Regex.Match(l, @"([a-fA-F0-9]{64})");
if (match2.Success)
{
buildLNKFile = buildLNKFile + l + Environment.NewLine;
}
}
readFileBytes = Encoding.UTF8.GetBytes(buildLNKFile);
fileName = "C:\\LNK";
}
}
if (!match.Success || (match.Success && !isLNKFile))
{
if (match.Success) { isLNKFile = true; }
if (readFileBytes == null) { readFileBytes = System.IO.File.ReadAllBytes(fileName); }
if (fileBytes != null) { intCurrentSize = fileBytes.Length; }
if (ledgerId != null)
{
cglText = ledgerId + GetRandomDivider() + readFileBytes.Length.ToString() + GetRandomDivider();
}
else
{
int totalFileSize = Path.GetFileName(fileName).Length + readFileBytes.Length.ToString().Length + readFileBytes.Length + 2;
int filePadding = HeaderPaddingSize - (totalFileSize % HeaderPaddingSize);
if (fileCount == mergeFiles.Length && totalMsgSize > 0)
{
filePadding = filePadding + (HeaderPaddingSize - (totalMsgSize % HeaderPaddingSize));
}
cglText = Path.GetFileName(fileName) + GetRandomDivider() + readFileBytes.Length.ToString().PadLeft(filePadding + readFileBytes.Length.ToString().Length, '0') + GetRandomDivider();
}
buffer = new byte[cglText.Length + intCurrentSize + readFileBytes.Length];
Encoding.UTF8.GetBytes(cglText).CopyTo(buffer, 0);
readFileBytes.CopyTo(buffer, cglText.Length);
if (fileBytes != null) { fileBytes.CopyTo(buffer, (readFileBytes.Length + cglText.Length)); }
fileBytes = buffer;
}
}
}
if (TextMessage.Length > 0)
{
cglText = GetRandomDivider() + msgBytes.Length.ToString().PadLeft(HeaderPaddingSize - 2, '0') + GetRandomDivider();
buffer = new byte[cglText.Length + msgBytes.Length];
Encoding.UTF8.GetBytes(cglText).CopyTo(buffer, 0);
msgBytes.CopyTo(buffer, cglText.Length);
msgBytes = buffer;
if (fileBytes != null)
{
buffer = new byte[msgBytes.Length + fileBytes.Length];
msgBytes.CopyTo(buffer, 0);
fileBytes.CopyTo(buffer, msgBytes.Length);
fileBytes = buffer;
}
else
{
fileBytes = msgBytes;
}
}
if (SignatureLabel != "" && ledgerId == null)
{
CoinRPC a = new CoinRPC(new Uri(GetURL(coinIP[CoinType]) + ":" + coinPort[CoinType]), new NetworkCredential(coinUser[CoinType], coinPassword[CoinType]));
//Sign and 0 pad the signature allowing the archive data to always begin at byte[0]. Allows for future file and keyword lookup
System.Security.Cryptography.SHA256 mySHA256 = SHA256Managed.Create();
byte[] hashValue = mySHA256.ComputeHash(fileBytes);
IEnumerable<string> Address = a.GetAddressesByAccount("~~" + SignatureLabel);
string signature = b.SignMessage(Address.First(), BitConverter.ToString(hashValue).Replace("-", String.Empty));
var sigBytes = Encoding.UTF8.GetBytes(signature);
if (!coinVariablePayloadByteSize[CoinType])
{
int totalSigSize = sigBytes.Length + sigBytes.Length.ToString().Length + 5;
int zeroPadding = HeaderPaddingSize - (totalSigSize % HeaderPaddingSize);
cglText = "SIG" + GetRandomDivider() + sigBytes.Length.ToString().PadLeft(zeroPadding + sigBytes.Length.ToString().Length, '0') + GetRandomDivider();
}
else
{
int totalSigSize = sigBytes.Length + sigBytes.Length.ToString().Length + Address.First().Length + 6;
int zeroPadding = HeaderPaddingSize - (totalSigSize % HeaderPaddingSize);
cglText = Address.First() + ".SIG" + GetRandomDivider() + sigBytes.Length.ToString().PadLeft(zeroPadding + sigBytes.Length.ToString().Length, '0') + GetRandomDivider();
}
buffer = new byte[cglText.Length + fileBytes.Length + sigBytes.Length];
Encoding.UTF8.GetBytes(cglText).CopyTo(buffer, 0);
sigBytes.CopyTo(buffer, cglText.Length);
if (fileBytes != null) { fileBytes.CopyTo(buffer, (sigBytes.Length + cglText.Length)); }
fileBytes = buffer;
}
if (ledgerId == null && Path.GetFileName(FilePath) != "SEC" && (VaultLabel != "" || (FriendLabel != "" && btnFriendEncryption.Text == "Private")))
{
Secp256k1.ECPoint publicKey = null;
if (VaultLabel != "")
{
CoinRPC a = new CoinRPC(new Uri(GetURL(coinIP[CoinType]) + ":" + coinPort[CoinType]), new NetworkCredential(coinUser[CoinType], coinPassword[CoinType]));
IEnumerable<string> Address = a.GetAddressesByAccount("~~~" + VaultLabel);
var privKeyHex = BitConverter.ToString(Base58.Decode(a.DumpPrivateKey(Address.First()))).Replace("-", "");
privKeyHex = privKeyHex.Substring(2, 64);
BigInteger privateKey = Hex.HexToBigInteger(privKeyHex);
publicKey = Secp256k1.Secp256k1.G.Multiply(privateKey);
}
else
{
if (System.IO.File.Exists("root\\" + FriendLabel + "\\PRO"))
{
string readFile = System.IO.File.ReadAllText("root//" + FriendLabel + "//PRO");
int startx = readFile.IndexOf("PKX=") + 4;
int lengthx = readFile.IndexOf(Environment.NewLine, startx);
int starty = readFile.IndexOf("PKY=") + 4;
int lengthy = readFile.IndexOf(Environment.NewLine, starty);
if (lengthx > 10 && lengthy > 10)
{
publicKey = new Secp256k1.ECPoint(Hex.HexToBigInteger(readFile.Substring(startx, lengthx - startx)), Hex.HexToBigInteger(readFile.Substring(starty, lengthy - starty)));
}
}
}
ECEncryption encryption = new ECEncryption();
byte[] encrypted = encryption.Encrypt(publicKey, fileBytes);
Directory.CreateDirectory("process\\" + processId);
File.WriteAllBytes("process\\" + processId + "\\SEC", encrypted);
CreateLedgerFile(coinPayloadByteSize[CoinType], GetRandomBuffer(coinPayloadByteSize[CoinType]), coinIP[CoinType], coinPort[CoinType], coinUser[CoinType], coinPassword[CoinType], WalletLabel, coinVersion[CoinType], coinMinTransaction[CoinType], System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\process\\" + processId + "\\SEC", null, "");
return;
}
System.IO.StreamWriter arcFile = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
for (int arcBytePosition = 0; arcBytePosition < fileBytes.Length; arcBytePosition++)
{
if (payloadBytePosition > coinPayloadByteSize[CoinType])
{
string EncodedBytes = "";
if (!coinVariablePayloadByteSize[CoinType])
{
EncodedBytes = Base58.EncodeWithCheckSum(arcPayloadBytes);
}
else { EncodedBytes = Convert.ToBase64String(arcPayloadBytes); }
addressHash.Add(EncodedBytes);
arcFile.WriteLine(EncodedBytes);
payloadBytePosition = 1;
arcPayloadBytes = new byte[coinPayloadByteSize[CoinType] + 1];
arcPayloadBytes[0] = CoinVersion;
}
arcPayloadBytes[payloadBytePosition] = fileBytes[arcBytePosition];
payloadBytePosition++;
}
if (!coinVariablePayloadByteSize[CoinType])
{
for (int i = payloadBytePosition; i < PayloadByteSize; i++)
{
arcPayloadBytes[i] = arcPadding[i];
}
string EncodedBytes = Base58.EncodeWithCheckSum(arcPayloadBytes);
addressHash.Add(EncodedBytes);
arcFile.WriteLine(EncodedBytes);
}
else
{
byte[] remainingPayloadBytes = new byte[payloadBytePosition];
Buffer.BlockCopy(arcPayloadBytes, 0, remainingPayloadBytes, 0, remainingPayloadBytes.Length);
// remainingPayloadBytes[0] = CoinVersion;
string EncodedBytes = Convert.ToBase64String(remainingPayloadBytes);
addressHash.Add(EncodedBytes);
arcFile.WriteLine(EncodedBytes);
}
arcFile.Close();
lblStatusInfo.ForeColor = System.Drawing.Color.Black;
lblStatusInfo.Text = "Encoded " + fileBytes.Length.ToString() + " bytes of data.";
}
else
{
processId = FilePath.ToUpper().Remove(0, FilePath.Length - 40).Replace(".ADD", "");
}
if (SignatureLabel != "" && !coinVariablePayloadByteSize[CoinType])
{
CoinRPC a = new CoinRPC(new Uri(GetURL(coinIP[CoinType]) + ":" + coinPort[CoinType]), new NetworkCredential(coinUser[CoinType], coinPassword[CoinType]));
IEnumerable<string> Address = a.GetAddressesByAccount("~~" + SignatureLabel);
signingAddress = Address.First();
}
if (chkKeywords.Checked && !coinVariablePayloadByteSize[CoinType])
{
var keywords = GetKeyWords(txtMessage.Text, "#");
if (keywords != null)
{
foreach (string keyword in keywords)
{
var addressOnly = keyword.Split('>');
//allow Keyword functionality by putting keyword addresses on the end of the archive
if (addressOnly[0] != signingAddress)
{
if (!addressHash.Contains(addressOnly[0]))
{
System.IO.StreamWriter arcSign = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
arcSign.WriteLine(keyword);
addressHash.Add(addressOnly[0]);
arcSign.Close();
}
}
}
}
}
if (chkEnableRecipients.Checked && !coinVariablePayloadByteSize[CoinType])
{
var keywords = GetKeyWords(txtMessage.Text, "@");
if (keywords != null)
{
foreach (string keyword in keywords)
{
var addressOnly = keyword.Split('>');
//allow Send to @Address functionality by putting Deliver To addresses on the end of the archive
if (addressOnly[0] != signingAddress)
{
if (!addressHash.Contains(addressOnly[0]))
{
System.IO.StreamWriter arcSign = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
arcSign.WriteLine(keyword);
addressHash.Add(addressOnly[0]);
arcSign.Close();
}
}
}
}
}
if (FriendLabel != "" && !coinVariablePayloadByteSize[CoinType])
{
try
{
string readFile = System.IO.File.ReadAllText("root//" + cmbTo.SelectedValue + "//PRO");
int start = readFile.IndexOf("MSG=") + 4;
int length = readFile.IndexOf(Environment.NewLine, start);
string sendToAddress = readFile.Substring(start, length - start);
if (!addressHash.Contains(sendToAddress))
{
System.IO.StreamWriter arcSign = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
arcSign.WriteLine(sendToAddress);
addressHash.Add(sendToAddress);
arcSign.Close();
}
}
catch { }
}
if (VaultLabel != "" && chkTrackVault.Checked && !coinVariablePayloadByteSize[CoinType])
{
CoinRPC a = new CoinRPC(new Uri(GetURL(coinIP[CoinType]) + ":" + coinPort[CoinType]), new NetworkCredential(coinUser[CoinType], coinPassword[CoinType]));
//allow tracking by putting a signature address on the end of the file
IEnumerable<string> Address = a.GetAddressesByAccount("~~~" + VaultLabel);
if (!addressHash.Contains(Address.First()))
{
System.IO.StreamWriter arcSign = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
arcSign.WriteLine(Address.First());
addressHash.Add(Address.First());
arcSign.Close();
}
}
if (strProofAddress != "" && ledgerId != null && !coinVariablePayloadByteSize[CoinType])
{
//added to assist in Proof Lookups by ensuring proof address is included with Ledger etching
if (!addressHash.Contains(strProofAddress))
{
System.IO.StreamWriter arcSign = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
arcSign.WriteLine(strProofAddress);
addressHash.Add(strProofAddress);
arcSign.Close();
}
}
//Folder address should always be the last or second to the last address in the array to allow for Folder Lookups.
if (ProfileLabel != "" && !coinVariablePayloadByteSize[CoinType])
{
CoinRPC a = new CoinRPC(new Uri(GetURL(coinIP[CoinType]) + ":" + coinPort[CoinType]), new NetworkCredential(coinUser[CoinType], coinPassword[CoinType]));
IEnumerable<string> Address = a.GetAddressesByAccount("~~~~" + ProfileLabel);
if (!addressHash.Contains(Address.First()))
{
System.IO.StreamWriter arcSign = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
arcSign.WriteLine(Address.First());
addressHash.Add(Address.First());
arcSign.Close();
}
}
//Signing address should always be the last address in the array to allow for Signature Lookups.
if (SignatureLabel != "" && !coinVariablePayloadByteSize[CoinType])
{
CoinRPC a = new CoinRPC(new Uri(GetURL(coinIP[CoinType]) + ":" + coinPort[CoinType]), new NetworkCredential(coinUser[CoinType], coinPassword[CoinType]));
//allow tracking by putting a signature address on the end of the file
System.IO.StreamWriter arcSign = new System.IO.StreamWriter("process\\" + processId + ".ADD", true);
IEnumerable<string> Address = a.GetAddressesByAccount("~~" + SignatureLabel);
if (!addressHash.Contains(Address.First())) { arcSign.WriteLine(Address.First()); }
arcSign.Close();
}
System.IO.StreamReader readARC = new System.IO.StreamReader("process\\" + processId + ".ADD");
System.IO.StreamWriter arcLedger = new System.IO.StreamWriter("process\\" + processId + ".LGR", true);
GetTransactionResponse transLookup = null;
while ((line = readARC.ReadLine()) != null)
{
if (!coinVariablePayloadByteSize[CoinType])
{
try
{
if (line.Contains('>') && chkEnableTips.Checked)
{
var tip = line.Split('>');
decimal tipAmount = CoinMinTransaction;
try
{
tipAmount = Convert.ToDecimal(tip[1]);
}
catch { }
toMany.Add(tip[0], tipAmount);
}
else
{
toMany.Add(line, CoinMinTransaction);
}
}
catch
{
//Cannot send to the same address more than twice in any one transaction
//If data is identical use previous transaction instead of archiving identical data.
if (lastTransaction.SequenceEqual(toMany))
{ transactionId = lastTransactionID; }
else
{
if (lastTransaction.Count > 0 && toMany.Count > 0)
{
lastT = lastTransaction.Last().Key;
curT = toMany.Last().Key;
//Wait for the wallet to catch up if sending to exact same address in a row.
if (lastT == curT)
{
ledgerCount = 1;
while (ledgerCount > 0)
{
transLookup = b.GetTransaction(lastTransactionID);
if (transLookup.confirmations > 0) { ledgerCount = 0; } else { System.Threading.Thread.Sleep(5000); }
}
}
}
transactionId = b.SendMany(WalletLabel, toMany);
System.Threading.Thread.Sleep(1000);
ledgerCount++;
}
arcLedger.WriteLine(transactionId);
arcLedger.Flush();
lastTransaction = new Dictionary<string, decimal>(toMany);
lastTransactionID = transactionId;
toMany.Clear();
if (line.Contains('>'))
{
var tip = line.Split('>');
toMany.Add(tip[0], Convert.ToDecimal(tip[1]));
}
else
{
toMany.Add(line, CoinMinTransaction);
}
tranCount = 0;
//Wait for the wallet to catch up.
while (ledgerCount > 5)
{
transLookup = b.GetTransaction(transactionId);
if (transLookup.confirmations > 0) { ledgerCount = 0; } else { System.Threading.Thread.Sleep(5000);}
}
}
if (tranCount == coinTransactionSize[CoinType])
{
//Breaking transaction file into size specified in wallet settings
if (lastTransaction.Count > 0 && toMany.Count > 0)
{
lastT = lastTransaction.Last().Key;
curT = toMany.Last().Key;
//Wait for the wallet to catch up if sending to exact same address in a row.
if (lastT == curT)
{
ledgerCount = 1;
while (ledgerCount > 0)
{
transLookup = b.GetTransaction(lastTransactionID);
if (transLookup.confirmations > 0) { ledgerCount = 0; } else { System.Threading.Thread.Sleep(5000); }
}
}
}
transactionId = b.SendMany(WalletLabel, toMany);
System.Threading.Thread.Sleep(1000);
ledgerCount++;
arcLedger.WriteLine(transactionId);
arcLedger.Flush();
lastTransaction = new Dictionary<string, decimal>(toMany);
lastTransactionID = transactionId;
toMany.Clear();
tranCount = 0;
//Wait for the wallet to catch up.
while (ledgerCount > 5)
{
transLookup = b.GetTransaction(transactionId);
if (transLookup.confirmations > 0) { ledgerCount = 0; } else { System.Threading.Thread.Sleep(10000); }
}
}
}
else
{
transactionId = b.SendData(line);
System.Threading.Thread.Sleep(1000);
ledgerCount++;
arcLedger.WriteLine(transactionId);
arcLedger.Flush();
lastTransactionID = transactionId;
//Wait for the wallet to catch up.
while (ledgerCount > 5)
{
transLookup = b.GetTransaction(transactionId);
if (transLookup.confirmations > 0) { ledgerCount = 0; } else { System.Threading.Thread.Sleep(10000); }
}
}
tranCount++;
}
if (toMany.Count > 0)
{
if (lastTransaction.Count > 0 && toMany.Count > 0)
{
lastT = lastTransaction.Last().Key;
curT = toMany.Last().Key;
//Wait for the wallet to catch up if sending to exact same address in a row.
if (lastT == curT)
{
ledgerCount = 1;
while (ledgerCount > 0)
{
transLookup = b.GetTransaction(lastTransactionID);
if (transLookup.confirmations > 0) { ledgerCount = 0; } else { System.Threading.Thread.Sleep(5000); }
}
}
}
//Catching the straglers
transactionId = b.SendMany(WalletLabel, toMany);
arcLedger.WriteLine(transactionId);
arcLedger.Flush();
lastTransaction = new Dictionary<string, decimal>(toMany);
lastTransactionID = transactionId;
toMany.Clear();
tranCount = 0;
}
arcLedger.Close();
readARC.Close();
processLedger(processId.ToString());
}
catch (Exception e)
{
lblStatusInfo.ForeColor = System.Drawing.Color.Black;
lblStatusInfo.Text = "Error: " + e.Message;
tmrStatusUpdate.Start();
tmrProgressBar.Start();
return;
}
lblStatusInfo.ForeColor = System.Drawing.Color.Black;
if (fileBytes != null)
{
lblStatusInfo.Text = "Encoded " + fileBytes.Length.ToString() + " bytes of data.";
}
else
{
lblStatusInfo.Text = "Encoded something extra special.";
}
tmrStatusUpdate.Start();
tmrProgressBar.Start();
if (!chkMonitorBlockChains.Checked)
{
TransIDSearch = transactionId;
performTransIDSearch(false);
}
}
private void btnArchive_Click(object sender, EventArgs e)
{
PerformArchive();
}
public void PerformArchive(string coinType, string fileName, string message)
{
CreateLedgerFile(coinPayloadByteSize[coinType], GetRandomBuffer(coinPayloadByteSize[coinType]), coinIP[coinType], coinPort[coinType], coinUser[coinType], coinPassword[coinType], WalletLabel, coinVersion[coinType], coinMinTransaction[coinType], fileName, null, message);
}
public void PerformArchive()
{
if (chkWarnArchive.Checked)
{
DialogResult dialogResult = MessageBox.Show("You are about to permanently etch data on " + CoinType + "." + Environment.NewLine + " !!! Apertus may lock up during this process !!!" + Environment.NewLine + " Please be patient. We will thread it better next time." + Environment.NewLine + Environment.NewLine + "NOTICE: Files or messages with repetitive data will greatly" + Environment.NewLine + " increase the cost and time of archivng.", "Confirm Saving", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
CreateLedgerFile(coinPayloadByteSize[CoinType], GetRandomBuffer(coinPayloadByteSize[CoinType]), coinIP[CoinType], coinPort[CoinType], coinUser[CoinType], coinPassword[CoinType], WalletLabel, coinVersion[CoinType], coinMinTransaction[CoinType], txtFileName.Text, null, txtMessage.Text);
}
else
{
return;
}
}
else
{
CreateLedgerFile(coinPayloadByteSize[CoinType], GetRandomBuffer(coinPayloadByteSize[CoinType]), coinIP[CoinType], coinPort[CoinType], coinUser[CoinType], coinPassword[CoinType], WalletLabel, coinVersion[CoinType], coinMinTransaction[CoinType], txtFileName.Text, null, txtMessage.Text);
}
txtMessage.Text = "";
txtFileName.Text = "";
//if (cmbFolder.SelectedIndex > 0) { RefreshFolderList(); }
//else if (cmbSignature.SelectedIndex > 0) { RefreshSignatureList(); }
//else if (VaultLabel != "") { RefreshVaultList(); }
}
private void btnAttachFiles_Click(object sender, EventArgs e)
{
DialogResult result = attachFiles.ShowDialog();
if (result == DialogResult.OK)
{
fileSize = (decimal)0;
string fileNames = "";
string processID = "";
foreach (var f in attachFiles.FileNames)
{
string fileName = f;
if (fileName.Contains(','))
{
DialogResult dialogResult = MessageBox.Show("One or more filename(s) contains special characters such as (/,). Please rename before etching.", "Notice", MessageBoxButtons.OK);
break;
}
if (fileNames != "") { fileNames = fileNames + ","; }
fileNames = fileNames + fileName;
var filebytes = new System.IO.FileInfo(fileName).Length;
fileSize = fileSize + filebytes;
}
txtFileName.Text = fileNames;
updateEstimatedCost();
}
}
private ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
private void Form1_Load(object sender, EventArgs e)
{
Directory.CreateDirectory("root");
Directory.CreateDirectory("process");
RefreshCoinTypes();
RefreshHashCache();
tmrStatusUpdate.Start();
LoadUserPref();
LoadFavorites();
}
public void LoadFavorites()
{
string favoritesLine = "";
if (System.IO.File.Exists("favorites.txt"))
{
System.IO.StreamReader readFavorite = new System.IO.StreamReader("favorites.txt");
while ((favoritesLine = readFavorite.ReadLine()) != null)
{
try
{
string transactionID = favoritesLine.Substring(99, favoritesLine.Length - 99);
treeView1.Nodes["favorites"].Nodes.Add(favoritesLine.Substring(0, 99)).Tag = transactionID;
}
catch { }
}
readFavorite.Close();
}
}
public void LoadUserPref()
{
this.Size = new System.Drawing.Size(Properties.Settings.Default.AppWidth, Properties.Settings.Default.AppHeight);
btnFriendEncryption.Text = Properties.Settings.Default.DirectMessage;
try
{
System.Drawing.Point windowLocation = new System.Drawing.Point(Convert.ToInt16(Properties.Settings.Default.AppLocation.Split(',').First()), Convert.ToInt16(Properties.Settings.Default.AppLocation.Split(',').Last()));
this.DesktopLocation = windowLocation;
chkEnableRecipients.Checked = Properties.Settings.Default.EnableRecipients;
chkKeywords.Checked = Properties.Settings.Default.EnableKeyWords;
chkMonitorBlockChains.Checked = Properties.Settings.Default.EnableMonitor;
chkTrackVault.Checked = Properties.Settings.Default.EnableTrackVault;
chkWarnArchive.Checked = Properties.Settings.Default.EnableSaveWarning;
chkSaveOnEnter.Checked = Properties.Settings.Default.EnableEnterEqualsSave;
chkEnableTips.Checked = Properties.Settings.Default.EnableTips;
chkBackLinks.Checked = Properties.Settings.Default.EnableBackLinks;
txtMessage.Font = Properties.Settings.Default.TextFont;
txtMessage.ForeColor = Properties.Settings.Default.TextColor;
}
catch { }
}
public void RefreshHashCache()
{
if (!System.IO.File.Exists("trust.conf"))
{
System.IO.StreamWriter writeTrustConf = new StreamWriter("trust.conf");
writeTrustConf.WriteLine("True True False False True");
writeTrustConf.Close();
}
System.IO.StreamReader readTrustConf = new System.IO.StreamReader("trust.conf");
while (!readTrustConf.EndOfStream)
{
var trustSettings = readTrustConf.ReadLine().Split(' ');
try
{
trustTrustedlistContent = Convert.ToBoolean(trustSettings[0]);
blockBlockedListContent = Convert.ToBoolean(trustSettings[1]);
blockUnSignedContent = Convert.ToBoolean(trustSettings[2]);
blockUntrustedContent = Convert.ToBoolean(trustSettings[3]);
followFollowedlistContent = Convert.ToBoolean(trustSettings[4]);
}
catch { }
}
readTrustConf.Close();
hashTrustedList.Clear();
if (System.IO.File.Exists("trust.txt"))
{
System.IO.StreamReader readTrust = new System.IO.StreamReader("trust.txt");
while (!readTrust.EndOfStream)
{
hashTrustedList.Add(readTrust.ReadLine());
}
readTrust.Close();
}
hashBlockedList.Clear();
if (System.IO.File.Exists("block.txt"))
{
System.IO.StreamReader readBlock = new System.IO.StreamReader("block.txt");
while (!readBlock.EndOfStream)
{
hashBlockedList.Add(readBlock.ReadLine());
}
readBlock.Close();
}
hashFollowedList.Clear();