forked from dk808/Raptoreum_SmartNode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_testnet.ps1
938 lines (885 loc) · 50.4 KB
/
install_testnet.ps1
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
#####################################
### Smartnode Installation Script ###
####### for Windows 10 & 11 #########
################ (: #################
# Admin control
function IsAdministrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if (-not (IsAdministrator)) {
Write-Host "$((Get-Date).ToString(`"yyyy-MM-dd HH:mm:ss`")) Please run this script with administrative privileges..." -ForegroundColor Cyan
pause
exit
}
# Script vars
$bootstrapZip = "https://bootstrap.raptoreum.com/testnet-bootstraps/rip01-testnet-no-index-bootstrap.zip" #Official testnet bootstrap
#$bootstrapZip = "https://github.com/wizz13150/Raptoreum_SmartNode/releases/download/Raptoreum_SmartNode/bootstrap-testnet.zip" #wizz's bootstrap
$configDir = "$env:APPDATA\RaptoreumSmartnode"
$coinPath = "$env:ProgramFiles (x86)\RaptoreumCore"
$testnetfolder = "rip01-testnet"
$configPath = "$configDir\$testnetfolder\raptoreum_testnet.conf"
$bootstrapZipPath = "$env:APPDATA\bootstrap\rip01-testnet-no-index-bootstrap.zip"
$serviceName = "RTMServiceTestnet"
Write-Host "================================================================================" -ForegroundColor Yellow
Write-Host " RTM Smartnode Setup for Testnet" -ForegroundColor Yellow
Write-Host "================================================================================" -ForegroundColor Yellow
Write-Host ""
Write-Host " July 2021, created and updated by dk808 from AltTank" -ForegroundColor Cyan
Write-Host " With Smartnode healthcheck by Delgon" -ForegroundColor Cyan
Write-Host " March 2023, adapted to Windows by Wizz" -ForegroundColor Cyan
Write-Host ""
Write-Host "================================================================================" -ForegroundColor Yellow
Write-Host " Remember to always encrypt your wallet with a strong password !" -ForegroundColor Yellow
Write-Host "================================================================================" -ForegroundColor Yellow
Write-Host " Testnet Node setup starting, press [CTRL-C] to cancel..." -ForegroundColor Cyan
Start-Sleep -Seconds 1
function KeepWindows-Up {
powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
powercfg -change -standby-timeout-ac 0
powercfg -change -standby-timeout-dc 0
powercfg -change -disk-timeout-ac 0
powercfg -change -disk-timeout-dc 0
powercfg -h off
}
function Write-CurrentTime {
Write-Host ('[' + (Get-Date).ToString("HH:mm:ss") + ']') -NoNewline
}
function Wipe-Clean {
Write-CurrentTime; Write-Host " Removing any previous instance of a testnet Smartnode (with this script)..." -ForegroundColor Yellow
Stop-Service -Name $serviceName -ErrorAction SilentlyContinue -Force
if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
sc.exe delete $serviceName | Out-Null
}
Remove-Item -Path $configDir\$testnetfolder -Recurse -ErrorAction SilentlyContinue -Force
Remove-Item -Path $coinPath -Recurse -ErrorAction SilentlyContinue -Force
[Environment]::SetEnvironmentVariable("traptoreumcli", "$null", "Machine")
$files = @(
"$env:USERPROFILE\update_testnet.ps1", "$env:USERPROFILE\check_testnet.ps1",
"$env:USERPROFILE\check_testnet.bat", "$env:USERPROFILE\chainbackup_testnet.ps1",
"$env:USERPROFILE\chainbackup_testnet.bat", "$env:USERPROFILE\RTM-MOTD_testnet.txt",
"$env:USERPROFILE\SmartNodeBash_testnet.bat", "$env:USERPROFILE\rtmdebuglogrotate_testnet.conf",
"$env:UserProfile\height_testnet.tmp", "$env:UserProfile\prev_stuck_testnet.tmp",
"$env:UserProfile\was_stuck_testnet.tmp", "$env:UserProfile\pose_score_testnet.tmp"
)
foreach ($file in $files) {
if (Test-Path $file) {
Remove-Item -Path $file -ErrorAction SilentlyContinue -Force
}
}
}
$global:CLI = ""
function Environment-Variable {
Write-CurrentTime; Write-Host " Set %traptoreumcli% as Environment Variable..." -ForegroundColor Cyan
# Env vars
$envPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
$newPath = "C:\Program Files (x86)\RaptoreumCore"
if (-not ($envPath.Contains($newPath))) {
[Environment]::SetEnvironmentVariable("Path", "$envPath;$newPath", "Machine")
}
$global:CLI = "`"$coinPath\raptoreum-cli.exe`" -testnet -datadir=`"$configDir`" -conf=`"$configDir\$testnetfolder\raptoreum_testnet.conf`""
[Environment]::SetEnvironmentVariable("traptoreumcli", "$CLI", "Machine")
}
function Install-7Zip {
$7zipKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe"
if (Test-Path $7zipKey) {
Write-CurrentTime; Write-Host " 7-Zip is already installed..." -ForegroundColor Yellow
} else {
$7zipInstallerUrl = "https://www.7-zip.org/a/7z1900-x64.msi"
$7zipInstallerPath = "$env:USERPROFILE\7z_installer.msi"
Write-CurrentTime; Write-Host " Downloading 7-Zip installer..." -ForegroundColor Cyan
Start-BitsTransfer -Source $7zipInstallerUrl -Destination $7zipInstallerPath -DisplayName "Downloading 7-Zip installer from $7zipInstallerUrl"
Write-CurrentTime; Write-Host " Installing 7-Zip..." -ForegroundColor Yellow
$msiArguments = @{
FilePath = "msiexec.exe"
ArgumentList = "/i `"$7zipInstallerPath`" /qn"
Wait = $true
Verb = "RunAs"
}
Start-Process @msiArguments
Remove-Item $7zipInstallerPath -Force
Write-CurrentTime; Write-Host " 7-Zip installed successfully..." -ForegroundColor Yellow
}
Start-Sleep -Seconds 1
}
function Extract-Bootstrap {
Write-CurrentTime; Write-Host " Extracting bootstrap from: $bootstrapZipPath..." -ForegroundColor Yellow
Write-CurrentTime; Write-Host " Extracting bootstrap to : $configDir\$testnetfolder..." -ForegroundColor Yellow
$zipProgram = ""
$7zipKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe"
if (Test-Path $7zipKey) {
$zipProgram = (Get-ItemProperty $7zipKey).'Path' + "7z.exe"
}
if ($zipProgram) {
Write-CurrentTime; Write-Host " 7-Zip detected, using 7-Zip to extract the bootstrap. Faster..." -ForegroundColor Cyan
& "$zipProgram" x $bootstrapZipPath -o"$configDir" -y
} else {
Write-CurrentTime; Write-Host " 7-Zip not detected, using 'Expand-Archive' to extract the bootstrap. Slower..." -ForegroundColor Cyan
Expand-Archive -Path $bootstrapZipPath -DestinationPath "$configDir" -Force -ErrorAction SilentlyContinue
}
Start-Sleep -Seconds 1
}
function Install-NSSM {
$NSSM_URL = "https://nssm.cc/release/nssm-2.24.zip"
$NSSM_ZipFile = "$env:TEMP\nssm.zip"
Write-CurrentTime; Write-Host " Downloading NSSM..." -ForegroundColor Cyan
Start-BitsTransfer -Source $NSSM_URL -Destination $NSSM_ZipFile -DisplayName "Downloading NSSM from $NSSM_URL"
Write-CurrentTime; Write-Host " Extracting NSSM to $env:UserProfile..." -ForegroundColor Yellow
Expand-Archive -Path $NSSM_ZipFile -DestinationPath $env:UserProfile -ErrorAction SilentlyContinue -Force
Write-CurrentTime; Write-Host " Removing NSSM Zip..." -ForegroundColor Yellow
Remove-Item -Path $NSSM_ZipFile -ErrorAction SilentlyContinue -Force
Start-Sleep -Seconds 1
}
function Install-LogrotateWin {
Write-CurrentTime; Write-Host " Installing LogrotateWin..." -ForegroundColor Cyan
$LogrotateWinUrl = "https://sourceforge.net/projects/logrotatewin/files/latest/download"
$LogrotateWinPath = "$env:TEMP\logrotatewin.zip"
$LogrotateWinExtractPath = "$env:UserProfile\LogrotateWin"
$LogrotateWinInstaller = "$LogrotateWinExtractPath\logrotateSetup.exe"
$LogrotateWinExtracted = Test-Path -Path "$LogrotateWinExtractPath\Logrotate.exe"
if ($LogrotateWinExtracted)
{
Write-CurrentTime; Write-Host " LogrotateWin already installed..." -ForegroundColor Yellow
} else {
Write-CurrentTime; Write-Host " Downloading and installing LogrotateWin ..." -ForegroundColor Cyan
Start-BitsTransfer -Source $LogrotateWinUrl -Destination $LogrotateWinPath -DisplayName "Downloading LogrotateWin from $LogrotateWinUrl"
Write-CurrentTime; Write-Host " Extracting LogrotateWin to $LogrotateWinExtractPath" -ForegroundColor Yellow
Expand-Archive -Path $LogrotateWinPath -DestinationPath $LogrotateWinExtractPath -ErrorAction SilentlyContinue -Force
.$LogrotateWinInstaller /s /v"INSTALLDIR=$LogrotateWinExtractPath" /V"AgreeToLicense=yes" /V"/qn"
Write-CurrentTime; Write-Host " LogrotateWin installed successfully..." -ForegroundColor Yellow
Write-CurrentTime; Write-Host " Removing LogrotateWin Zip..." -ForegroundColor Yellow
Remove-Item -Path $LogrotateWinPath -ErrorAction SilentlyContinue -Force
}
Start-Sleep -Seconds 1
}
function Create-Shortcuts {
# Create SmartNodeBash.lnk
$ShortcutPath = [Environment]::GetFolderPath("Desktop") + "\SmartNodeBash_testnet.lnk"
Write-CurrentTime; Write-Host " Creating a desktop shortcut for SmartNodeBash_testnet.bat..." -ForegroundColor Cyan
$TargetPath = "powershell.exe"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutPath)
$Shortcut.TargetPath = $TargetPath
$Command = "-Command `"Start-Process cmd.exe -ArgumentList '/c `"$env:USERPROFILE\SmartNodeBash_testnet.bat`"' -Verb RunAs`""
$Shortcut.Arguments = $Command
$Shortcut.IconLocation = "$coinPath\raptoreum-qt.exe"
$Shortcut.WorkingDirectory = [Environment]::GetFolderPath("Desktop")
$Shortcut.Save()
Write-CurrentTime; Write-Host " $ShortcutPath created successfully..." -ForegroundColor Yellow
# Create UpdateSmartnode.lnk
$UpdateShortcutPath = [Environment]::GetFolderPath("Desktop") + "\UpdateSmartnode_testnet.lnk"
Write-CurrentTime; Write-Host " Creating a desktop shortcut for Update_testnet.bat..." -ForegroundColor Cyan
$UpdateTargetPath = "powershell.exe"
$UpdateShortcut = $WScriptShell.CreateShortcut($UpdateShortcutPath)
$UpdateShortcut.TargetPath = $UpdateTargetPath
$UpdateCommand = "-Command `"Start-Process cmd.exe -ArgumentList '/c `"$env:USERPROFILE\update_testnet.bat`"' -Verb RunAs`""
$UpdateShortcut.Arguments = $UpdateCommand
$UpdateShortcut.IconLocation = "$coinPath\raptoreum-qt.exe"
$UpdateShortcut.WorkingDirectory = [Environment]::GetFolderPath("Desktop")
$UpdateShortcut.Save()
Write-CurrentTime; Write-Host " $UpdateShortcutPath created successfully..." -ForegroundColor Yellow
# Create Dashboard_testnet.lnk
$DashboardShortcutPath = [Environment]::GetFolderPath("Desktop") + "\Dashboard_testnet.lnk"
Write-CurrentTime; Write-Host " Creating a desktop shortcut for Dashboard_testnet.bat..." -ForegroundColor Cyan
$DashboardTargetPath = "cmd.exe"
$DashboardShortcut = $WScriptShell.CreateShortcut($DashboardShortcutPath)
$DashboardShortcut.TargetPath = $DashboardTargetPath
$DashboardCommand = "/c `"$env:USERPROFILE\Dashboard_testnet.bat`""
$DashboardShortcut.Arguments = $DashboardCommand
$DashboardShortcut.IconLocation = "$coinPath\raptoreum-qt.exe"
$DashboardShortcut.WorkingDirectory = [Environment]::GetFolderPath("Desktop")
$DashboardShortcut.Save()
Write-CurrentTime; Write-Host " $DashboardShortcutPath created successfully..." -ForegroundColor Yellow
}
$global:sshPort = ""
function Get-SSHPort {
Write-CurrentTime; Write-Host " Detecting SSH port being used..." -ForegroundColor Yellow
$sshdConfigPath = "$env:ProgramData\ssh\sshd_config"
if (Test-Path $sshdConfigPath) {
$content = Get-Content $sshdConfigPath
$portLine = $content | Where-Object { $_ -match "^Port\s+\d+" }
if ($portLine -ne $null) {
$global:sshPort = $portLine -replace "^Port\s+", ""
Write-CurrentTime; Write-Host " SSH Port: $($global:sshPort)" -ForegroundColor Yellow
} else {
$global:sshPort = 22
Write-CurrentTime; Write-Host " No port found in the configuration file. Default SSH port is $($global:sshPort)." -ForegroundColor Yellow
}
} else {
$global:sshPort = 22
Write-CurrentTime; Write-Host " OpenSSH server configuration file not found. Default SSH port is $($global:sshPort)." -ForegroundColor Yellow
}
do {
$useSSH = Read-Host -Prompt "Detected SSH port is $($global:sshPort), is this correct? (y/n) "
if ($useSSH -eq "n") {
$global:sshPort = Read-Host -Prompt "Enter SSH port "
}
} while ($useSSH -ne "y" -and $useSSH -ne "n" -and $useSSH -ne "")
Start-Sleep -Seconds 1
}
$global:wanIP = ""
function Confirm-IP {
Write-CurrentTime; Write-Host " Detecting IP address being used..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
$global:wanIP = Invoke-WebRequest -Uri "http://ipecho.net/plain" -UseBasicParsing | Select-Object -ExpandProperty Content
do {
$useDetectedIP = Read-Host -Prompt "Detected IP address is $($global:wanIP), is this correct? (y/n) "
if ($useDetectedIP -eq "n") {
$global:wanIP = Read-Host -Prompt "Enter IP address "
}
} while ($useDetectedIP -ne "y" -and $useDetectedIP -ne "n" -and $useDetectedIP -ne "")
Start-Sleep -Seconds 1
}
$global:smartnodeblsprivkey = ""
function Create-Conf {
# If $QuickSetup is provided, just ask about BLS key.
param(
[string]$QuickSetup
)
if (-not [string]::IsNullOrEmpty($QuickSetup)) {
do {
$global:smartnodeblsprivkey = Read-Host -Prompt "Enter your SmartNode BLS Privkey (operatorSecret)"
if ($global:smartnodeblsprivkey.Length -ne 64) {
Write-Host " The BLS must be exactly 64 characters long, please check your BLS..." -ForegroundColor Yellow
}
} until ($global:smartnodeblsprivkey.Length -eq 64)
return
}
if (Test-Path $configPath) {
Write-CurrentTime; Write-Host " Existing conf file found backing up to Raptoreum_testnet.old ..." -ForegroundColor Yellow
Move-Item -Path $configPath -Destination "$configDir\$testnetfolder\Raptoreum_testnet.old" -Force
}
$rpcUser = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
$password = -join ((65..90) + (97..122) | Get-Random -Count 20 | % {[char]$_})
Write-CurrentTime; Write-Host " Creating Conf File..." -ForegroundColor Cyan
Start-Sleep -Seconds 1
if (-not (Test-Path $configDir)) {
New-Item -ItemType Directory -Path $configDir | Out-Null
if (-not (Test-Path "$configDir\$testnetfolder")) {
New-Item -ItemType Directory -Path "$configDir\$testnetfolder" | Out-Null
}
}
$configContent = @"
[test]
rpcuser=$rpcUser
rpcpassword=$password
rpcallowip=127.0.0.1
rpcbind=127.0.0.1
port=10230
server=1
testnet=1
listen=1
txindex=1
smartnodeblsprivkey=$global:smartnodeblsprivkey
externalip=$global:wanIP
maxconnections=125
dbcache=1024
onlynet=ipv4
addnode=lbdn.raptoreum.com
"@
if (Test-Path $configPath) {
$configContent | Set-Content -Path $configPath -ErrorAction SilentlyContinue -Force
} else {
New-Item -ItemType File -Path $configPath -Value $configContent -ErrorAction SilentlyContinue -Force | Out-Null
}
Write-Host "$configPath created..."
Start-Sleep -Seconds 1
}
function Install-Bins {
Write-CurrentTime; Write-Host " Installing latest binaries..." -ForegroundColor Cyan
$uri = "https://api.github.com/repos/Raptor3um/raptoreum/releases"
$responses = Invoke-RestMethod -Uri $uri
$latestMainnetRelease = $null
foreach ($response in $responses) {
if ($response.tag_name -match "testnet") {
$latestMainnetRelease = $response
break
}
}
if (-not $latestMainnetRelease) {
Write-Host "Could not find a mainnet release, ping Wizz lol" -ForegroundColor Red
return
}
$latestVersion = $latestMainnetRelease.tag_name
# get the latest version url to download
$assets = $latestMainnetRelease.assets
$walletUrl = $null
foreach ($asset in $assets) {
if ($asset.name -match "raptoreum-win-$latestVersion.*\.zip$") {
$walletUrl = $asset.browser_download_url
}
}
if (-not $walletUrl) {
Write-Host "Could not find the wallet URL for the mainnet version, ping Wizz lol" -ForegroundColor Red
return
}
# Fetch the latest release using GitHub
$process = Get-Process "raptoreumd" -ErrorAction SilentlyContinue
if ($process) {
Write-CurrentTime; Write-Host " Raptoreum process detected, stopping..." -ForegroundColor Yellow
$confirmation = ""
do {
$confirmation = Read-Host "Do you want to stop RTMService ? (y/n) "
if ($confirmation -eq "y") {
Stop-Service RTMService -ErrorAction SilentlyContinue -Force
Write-CurrentTime; Write-Host " RTMService has been stopped..." -ForegroundColor Yellow
} elseif ($confirmation -eq "n") {
Write-CurrentTime; Write-Host " RTMService was not stopped, we can't install binaries..." -ForegroundColor Yellow
return
} else {
Write-CurrentTime; Write-Host " Please enter 'y' or 'n'..." -ForegroundColor Yellow
}
} while ($confirmation -ne "y" -and $confirmation -ne "n")
if (-not (Test-Path $coinPath)) {
New-Item -Path $coinPath -ItemType Directory | Out-Null
}
Write-CurrentTime; Write-Host " Downloading latest binaries ($latestVersion)..." -ForegroundColor Yellow
Start-BitsTransfer -Source $walletUrl -Destination "$coinPath\raptoreum.zip" -DisplayName "Downloading binaries from $walletUrl"
Write-CurrentTime; Write-Host " Unzipping..." -ForegroundColor Yellow
Expand-Archive -Path "$coinPath\raptoreum.zip" -DestinationPath $coinPath -ErrorAction SilentlyContinue -Force
Write-CurrentTime; Write-Host " Removing..." -ForegroundColor Yellow
Remove-Item -Path "$coinPath\raptoreum.zip" -Recurse -ErrorAction SilentlyContinue -Force
} else {
if (-not (Test-Path $coinPath)) {
New-Item -Path $coinPath -ItemType Directory| Out-Null
}
Write-CurrentTime; Write-Host " Downloading latest binaries ($latestVersion)..." -ForegroundColor Yellow
Start-BitsTransfer -Source $walletUrl -Destination "$coinPath\raptoreum.zip" -DisplayName "Downloading binaries from $walletUrl"
Write-CurrentTime; Write-Host " Unzipping..." -ForegroundColor Yellow
Expand-Archive -Path "$coinPath\raptoreum.zip" -DestinationPath $coinPath -ErrorAction SilentlyContinue -Force
Write-CurrentTime; Write-Host " Removing..." -ForegroundColor Yellow
Remove-Item -Path "$coinPath\raptoreum.zip" -Recurse -ErrorAction SilentlyContinue -Force
}
Start-Sleep -Seconds 1
}
$global:bootstrapAns = ""
function Bootstrap-Chain {
# If $QuickSetup is provided, just ask about bootstrap.
param(
[string]$QuickSetup
)
if (-not [string]::IsNullOrEmpty($QuickSetup)) {
do {
$prompt = Read-Host -Prompt "Would you like to bootstrap the chain? (y/n) "
if ($prompt -eq "y" -or $prompt -eq "") {
$global:bootstrapAns = 1
}
} while ($prompt -ne "y" -and $prompt -ne "n" -and $prompt -ne "")
return
}
if ($global:bootstrapAns -eq "1") {
if (-not (Test-Path -Path "$env:APPDATA\bootstrap")) {
New-Item -ItemType Directory -Path "$env:APPDATA\bootstrap" -ErrorAction SilentlyContinue -Force | Out-Null
}
Write-CurrentTime; Write-Host " Downloading the bootstrap, please be patient..." -ForegroundColor Cyan
Start-BitsTransfer -Source $bootstrapZip -Destination "$env:APPDATA\bootstrap\" -DisplayName "Downloading bootstrap from $bootstrapZip"
Extract-Bootstrap
}
Start-Sleep -Seconds 1
}
function Chain-Backup {
Write-CurrentTime; Write-Host " Creating bootstrap script..." -ForegroundColor Cyan
$chainBackupScript = @"
`$bootstrapZipPath = "$bootstrapZipPath"
`$configDir = "$configDir"
`$testnetfolder = "$testnetfolder"
Write-Host "(`$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss'))) Creating blockchain backup (bootstrap)..." -ForegroundColor Yellow
Move-Item -Path "`$env:USERPROFILE\check_testnet.ps1" -Destination "`$env:USERPROFILE\temp.ps1" -ErrorAction SilentlyContinue -Force
Stop-Service -Name $serviceName -ErrorAction SilentlyContinue -Force
Start-Sleep -Seconds 2
# Check if the wallet process is running and kill it if it is
`$walletProcess = Get-Process -Name "raptoreumd" -ErrorAction SilentlyContinue
if (`$walletProcess) {
Write-Host "(`$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss'))) Stopping the running Raptoreum process..." -ForegroundColor Yellow
Stop-Process `$walletProcess.Id -Force
} else {
Write-Host "(`$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss'))) No Raptoreum process detected..." -ForegroundColor Green
}
Start-Sleep -Seconds 2
Remove-Item -Path `$bootstrapZipPath -ErrorAction SilentlyContinue
`$zipProgram = ""
`$7zipKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe"
if (Test-Path `$7zipKey) {
`$zipProgram = (Get-ItemProperty `$7zipKey).'Path' + "7z.exe"
}
if (`$zipProgram) {
Write-Host "(`$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss'))) 7-Zip detected, using 7-Zip to compress the bootstrap. Faster..." -ForegroundColor Cyan
& "`$zipProgram" a -tzip `$bootstrapZipPath "`$configDir\`$testnetfolder\blocks" "`$configDir\`$testnetfolder\chainstate" "`$configDir\`$testnetfolder\evodb" "`$configDir\`$testnetfolder\llmq" "`$configDir\`$testnetfolder\powcache.dat"
} else {
Write-Host "(`$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss'))) 7-Zip not detected, using 'Expand-Archive' to compress the bootstrap. Slower..." -ForegroundColor Cyan
Compress-Archive -Path "`$configDir\`$testnetfolder\blocks", "`$configDir\`$testnetfolder\chainstate", "`$configDir\`$testnetfolder\evodb", "`$configDir\`$testnetfolder\llmq", "`$configDir\`$testnetfolder\powcache.dat" -DestinationPath `$bootstrapZipPath
}
Write-Host "(`$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss'))) Bootstrap created" -ForegroundColor Green
Start-Service -Name $serviceName -ErrorAction SilentlyContinue
Move-Item -Path "`$env:USERPROFILE\temp.ps1" -Destination "`$env:USERPROFILE\check_testnet.ps1" -ErrorAction SilentlyContinue -Force
Start-Sleep -Seconds 10
"@
Set-Content -Path "$env:USERPROFILE\chainbackup_testnet.ps1" -Value $chainBackupScript
Write-CurrentTime; Write-Host " Script created: $env:USERPROFILE\chainbackup_testnet.ps1..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
function Update-Script {
Write-CurrentTime; Write-Host " Creating a script to update binaries for future updates..." -ForegroundColor Cyan
$updateScript = @"
# Admin control
function IsAdministrator {
`$user = [Security.Principal.WindowsIdentity]::GetCurrent()
(New-Object Security.Principal.WindowsPrincipal `$user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if (-not (IsAdministrator)) {
Write-Host "`$((Get-Date).ToString(`"yyyy-MM-dd HH:mm:ss`")) Please run this script with administrative privileges..." -ForegroundColor Cyan
pause
exit
}
`$coinPath = "`$env:ProgramFiles (x86)\RaptoreumCore"
# Show versions
`$FilePath = "`$coinPath\raptoreumd.exe"
`$fileVersionInfo = Get-Item `$FilePath -ErrorAction SilentlyContinue | Get-ItemProperty | Select-Object -ExpandProperty VersionInfo
`$fileVerion = `$fileVersionInfo.ProductVersion
# Define the network type ("mainnet" or "testnet")
`$networkType = "testnet"
# Find the latest release corresponding to the network type
`$uri = "https://api.github.com/repos/Raptor3um/raptoreum/releases"
`$responses = Invoke-RestMethod -Uri `$uri
`$latestRelease = `$null
foreach (`$response in `$responses) {
if (`$response.tag_name -match `$networkType) {
`$latestRelease = `$response
break
}
}
if (-not `$latestRelease) {
Write-Host "Could not find a `$networkType release" -ForegroundColor Red
return
}
`$latestVersion = `$latestRelease.tag_name
# Display detected versions
if (Test-Path `$coinPath) {
if (`$fileVerion -ne `$latestVersion) {
Write-Host "Your Smartnode version is : `$fileVerion" -ForegroundColor Yellow
} else {
Write-Host "Your Smartnode version is : `$fileVerion" -ForegroundColor Green
}
} else {
Write-Host "Your Smartnode version is : Not found" -ForegroundColor Yellow
}
Write-Host "Last RaptoreumCore version available : `$latestVersion" -ForegroundColor Green
Write-Host "Download link: https://github.com/Raptor3um/raptoreum/releases/tag/`$latestVersion" -ForegroundColor Yellow
# Confirm update
`$confirmUpdate = Read-Host " Do you really want to update your SmartNode ? (y/n)"
if (`$confirmUpdate.ToLower() -eq "y") {
Write-Host "Stopping $serviceName..." -ForegroundColor Yellow
Stop-Service -Name $serviceName -ErrorAction SilentlyContinue
Start-Sleep -Seconds 5
# Check if the wallet process is running and kill it if it is
`$walletProcess = Get-Process "raptoreumd" -ErrorAction SilentlyContinue
if (`$walletProcess) {
Write-Host "Stopping the running raptoreumd process..." -ForegroundColor Yellow
Stop-Process "raptoreumd" -Force
} else {
Write-Host "No Raptoreum process detected..." -ForegroundColor Yellow
}
Write-Host "Deleting existing RaptoreumSmartnode binaries..." -ForegroundColor Yellow
`$files = @("raptoreum-cli.exe", "raptoreum-qt.exe", "raptoreum-tx.exe", "raptoreumd.exe", "checksum.txt")
`$filesExist = `$false
foreach (`$file in `$files) {
if (Test-Path `$file) {
`$filesExist = `$true
break
}
}
if (`$filesExist) {
foreach (`$file in `$files) {
if (Test-Path `$file) {
Remove-Item `$file -Force -ErrorAction SilentlyContinue
}
}
}
Write-Host "Installing latest binaries..." -ForegroundColor Yellow
`$assets = `$latestRelease.assets
`$walletUrl = `$null
foreach (`$asset in `$assets) {
if (`$asset.name -match "raptoreum-win-`$latestVersion.*\.zip`$") {
`$walletUrl = `$asset.browser_download_url
}
}
if (-not `$walletUrl) {
Write-Host "Could not find the wallet URL for the `$networkType version" -ForegroundColor Red
return
}
Write-Host "Downloading..." -ForegroundColor Yellow
Start-BitsTransfer -Source `$walletUrl -Destination "`$coinPath\raptoreum.zip" -DisplayName "Downloading binaries from `$walletUrl"
Write-Host "Unzipping..." -ForegroundColor Yellow
Expand-Archive -Path "`$coinPath\raptoreum.zip" -DestinationPath `$coinPath -ErrorAction SilentlyContinue -Force
Write-Host "Starting $serviceName..." -ForegroundColor Yellow
Start-Service -Name $serviceName -ErrorAction SilentlyContinue
Write-Host "Binaries updated to v`$latestVersion successfully..." -ForegroundColor Green
} else {
Write-Host "Skipping update..." -ForegroundColor Yellow
}
pause
"@
$updateBatch = @"
@echo off
powershell.exe -ExecutionPolicy Bypass -File "%USERPROFILE%\update_testnet.ps1"
"@
Set-Content -Path "$env:USERPROFILE\update_testnet.bat" -Value $updateBatch
Set-Content -Path "$env:USERPROFILE\update_testnet.ps1" -Value $updateScript
Write-CurrentTime; Write-Host " Script created: `%USERPROFILE%\update_testnet.bat..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
function Dashboard-Script {
Write-CurrentTime; Write-Host " Creating the Dashboard script..." -ForegroundColor Cyan
$dashboard = @"
function Get-DataColor(`$condition, `$trueColor = 'Green', `$falseColor = 'Yellow') {
if (`$condition) { return `$trueColor } else { return `$falseColor }
}
function Display-Information(`$message, `$value, `$color = 'Green') {
Write-Host "`$message : `$value" -ForegroundColor `$color
}
`$first = `$true
`$testnetfolder = "$testnetfolder"
while (`$true) {
if (`$first) {
Write-Host "----------------------------------" -ForegroundColor Cyan
Write-Host "Raptoreum Dashboard Pro 9000 Plus" -ForegroundColor Yellow
Write-Host "----------------------------------" -ForegroundColor cyan
Write-Host 'Gathering informations... ' -ForegroundColor Green
Write-Host 'This will take a few seconds...' -ForegroundColor Green
Write-Host 'Please, be patient...' -ForegroundColor Green
}
# Get informations
`$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
`$blockHeight = cmd /C "`$env:traptoreumcli getblockcount" | ConvertFrom-Json
if (`$first) {Write-Host "Retrieved blockHeight............." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$mempoolInfo = cmd /C "`$env:traptoreumcli getmempoolinfo" | ConvertFrom-Json
if (`$first) {Write-Host "Retrieved getmempoolinfo.........." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$getnettotals = cmd /C "`$env:traptoreumcli getnettotals" | ConvertFrom-Json
if (`$first) {Write-Host "Retrieved getnettotals............" -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$connectionCount = cmd /C "`$env:traptoreumcli getconnectioncount" | ConvertFrom-Json
if (`$first) {Write-Host "Retrieved getconnectioncount......" -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$smartnodeTotal = cmd /C "`$env:traptoreumcli smartnodelist status"
if (`$first) {Write-Host "Retrieved smartnodelist status...." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$smartnodeList = `$smartnodeTotal | Where-Object { `$_ -like "*ENABLED*" }
if (`$first) {Write-Host "Retrieved enabled smartnodes......" -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$smartnodeStatus = cmd /C "`$env:traptoreumcli smartnode status" | ConvertFrom-Json
if (`$first) {Write-Host "Retrieved smartnode status........" -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$networkHeight = (Invoke-WebRequest -Uri "https://testnet.raptoreum.com/api/getblockcount" -UseBasicParsing -ErrorAction SilentlyContinue).Content
if (`$first) {Write-Host "Retrieved getblockcount..........." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$smartnodeVersion = Get-Item "`$env:ProgramFiles (x86)\RaptoreumCore\raptoreumd.exe" -ErrorAction SilentlyContinue| Get-ItemProperty | Select-Object -ExpandProperty VersionInfo
if (`$first) {Write-Host "Retrieved smartnode version......." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$folderSize = Get-ChildItem "`$env:APPDATA\RaptoreumSmartnode\`$testnetfolder" -Recurse | Measure-Object -Property Length -Sum
if (`$first) {Write-Host "Retrieved smartnode folder size..." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$systemStabilityIndex = Get-WmiObject -Class Win32_ReliabilityStabilityMetrics | Select-Object -ExpandProperty SystemStabilityIndex -First 1
if (`$first) {Write-Host "Retrieved system stability index.." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$os = Get-CimInstance -ClassName Win32_OperatingSystem
`$cpuUsage = (Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Processor | Where-Object { `$_.Name -eq "_Total" }).PercentProcessorTime
`$drive = Get-Volume -DriveLetter (Split-Path -Qualifier `$env:APPDATA\RaptoreumSmartnode)[0]
`$ostime = Get-WmiObject -Class Win32_OperatingSystem
`$uptime = (Get-Date) - `$ostime.ConvertToDateTime(`$ostime.LastBootUpTime)
if (`$first) {Write-Host "Retrieved computer infos.........." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$lastPaidBlockHash = cmd /C "`$env:traptoreumcli getblockhash `$(`$smartnodeStatus.dmnState.lastPaidHeight)"
if (`$first) {Write-Host "Retrieved last paid block hash...." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$lastPaidBlock = cmd /C "`$env:traptoreumcli getblock `$lastPaidBlockHash" | ConvertFrom-Json
if (`$first) {Write-Host "Retrieved last paid block........." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
if (`$lastPaidBlock.tx -ne `$null -and `$lastPaidBlock.tx.Count -gt 0) {
`$smartnodeRewardTx = cmd /C "`$env:traptoreumcli getrawtransaction `$(`$lastPaidBlock.tx[0]) 1" | ConvertFrom-Json
} else {
`$smartnodeRewardTx = `$null
}
if (`$first) {Write-Host "Retrieved smartnode reward........" -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$latest = Invoke-RestMethod -Uri "https://api.github.com/repos/Raptor3um/raptoreum/releases/latest" -ErrorAction SilentlyContinue
if (`$first) {Write-Host "Retrieved latest version.........." -NoNewline -ForegroundColor cyan; Write-Host "√" -ForegroundColor Green}
`$first = `$false
`$stopwatch.Stop()
# Display informations
Clear-Host
Write-Host "----------------------------------" -ForegroundColor Cyan
Write-Host "Raptoreum Dashboard Pro 9000 Plus" -ForegroundColor Yellow
Write-Host "----------------------------------" -ForegroundColor Cyan
Display-Information 'Local/Network block height...' "`$blockHeight/`$networkHeight" -Color `$(Get-DataColor ([Math]::Abs(`$blockHeight - `$networkHeight) -lt 3))
Display-Information 'Active/Total Smartnodes......' "`$(`$smartnodeList.count)/`$(`$smartnodeTotal.count) (`$(((`$smartnodeList.count / `$smartnodeTotal.count) * 100).ToString("F1"))%)"
Display-Information 'Mempool (tx/size)............' "`$(`$mempoolInfo.size) tx / `$([math]::Round(`$mempoolInfo.bytes / 1MB, 3)) Mb"
Display-Information 'Local/Available version......' "`$(`$smartnodeVersion.ProductVersion) / `$(`$latest.tag_name)" -Color `$(Get-DataColor (`$smartnodeVersion.ProductVersion -eq `$latest.tag_name))
Write-Host "----------------------------------" -ForegroundColor Cyan
Display-Information 'Smartnode status.............' "`$(`$smartnodeStatus.status)" -Color `$(Get-DataColor (`$smartnodeStatus.status -match 'Ready'))
Display-Information 'Smartnode connections........' "`$(`$connectionCount)" -Color `$(Get-DataColor (`$connectionCount -gt 8))
Display-Information 'Smartnode folder size .......' "`$([math]::Round(`$folderSize.sum / 1GB, 2)) Gb"
if (`$smartnodeList -eq `$null -or `$smartnodeList.count -eq 0) {
Display-Information 'Estimated reward per day.....' "N/A"
} else {
Display-Information 'Estimated reward per day.....' "`$([Math]::Round((1440 / `$smartnodeList.count) * 1000, 2)) TRTM (+ fees)"
}
if (`$lastPaidBlock -ne `$null) {
`$lastPaidTime = [DateTimeOffset]::FromUnixTimeSeconds(`$lastPaidBlock.time).ToLocalTime().DateTime
`$timeElapsedDisplay = "{0}d {1}h {2}m" -f `$((Get-Date) - `$lastPaidTime).Days, `$((Get-Date) - `$lastPaidTime).Hours, `$((Get-Date) - `$lastPaidTime).Minutes
Display-Information 'Since last payment...........' "`$timeElapsedDisplay"}else{Display-Information 'Since last payment............: N/A'
}
Display-Information 'IP address and port..........' `$(`$smartnodeStatus.service)
Display-Information 'Smartnode ProTX..............' ((Get-Content "`$env:USERPROFILE\check_testnet.ps1" | Where-Object { `$_ -like "*NODE_PROTX =*" }) -replace ".*NODE_PROTX\s*=\s*", "" -replace '^"|"`$', '')
Display-Information 'Smartnode BLS Key............' ((Get-Content "`$env:APPDATA\RaptoreumSmartnode\`$testnetfolder\raptoreum_testnet.conf" | Where-Object { `$_ -like "smartnodeblsprivkey=*" }) -replace "smartnodeblsprivkey=", "")
Display-Information 'Payout address...............' `$(`$smartnodeStatus.dmnState.payoutAddress)
Display-Information 'Registered height............' `$(`$smartnodeStatus.dmnState.registeredHeight)
Display-Information 'PoSe score (Time to 0).......' "`$(`$smartnodeStatus.dmnState.PoSePenalty) (`$([math]::Floor((`$smartnodeStatus.dmnState.PoSePenalty) * 2 / 60))h `$(`$smartnodeStatus.dmnState.PoSePenalty * 2 % 60)min)" -Color `$(Get-DataColor (`$smartnodeStatus.dmnState.PoSePenalty -eq 0))
Display-Information 'PoSe ban/revived height......' "`$(`$smartnodeStatus.dmnState.PoSeBanHeight) / `$(`$smartnodeStatus.dmnState.PoSeRevivedHeight)"
Write-Host "----------------------------------" -ForegroundColor Cyan
Display-Information 'System stability index.......' "`$([Math]::Round(`$systemStabilityIndex,1))/10" -Color `$(Get-DataColor (`$systemStabilityIndex -eq 10))
Display-Information 'System uptime................' `$("{0}d {1}h {2}m" -f `$uptime.Days, `$uptime.Hours, `$uptime.Minutes)
Display-Information 'CPU usage....................' "`$cpuUsage %" -Color `$(Get-DataColor (`$cpuUsage -lt 90))
Display-Information 'RAM usage....................' "`$([math]::Round((`$os.TotalVisibleMemorySize - `$os.FreePhysicalMemory) / 1024 / 1024, 2))/`$([math]::Round(`$os.TotalVisibleMemorySize / 1024 / 1024, 2)) GB (`$([math]::Round(((`$os.TotalVisibleMemorySize - `$os.FreePhysicalMemory) / `$os.TotalVisibleMemorySize * 100), 0))% used)" -Color `$(Get-DataColor (((`$os.TotalVisibleMemorySize - `$os.FreePhysicalMemory) / `$os.TotalVisibleMemorySize * 100) -lt 90))
Display-Information 'Disk usage (Free/Total)......' "`$([math]::Round((`$drive.SizeRemaining / 1GB), 2))/`$([math]::Round((`$drive.Size / 1GB), 2)) GB (`$([math]::Round((1 - (`$drive.SizeRemaining / `$drive.Size)) * 100, 0))% used)" -Color `$(Get-DataColor ((1 - (`$drive.SizeRemaining / `$drive.Size)) * 100 -lt 90))
Display-Information 'Total received...............' "`$([math]::Round(`$getnettotals.totalbytesrecv / 1MB)) Mb"
Display-Information 'Total sent...................' "`$([math]::Round(`$getnettotals.totalbytessent / 1MB, 0)) Mb"
Write-Host "Loaded in `$(`$stopwatch.Elapsed.Seconds) sec"
# Countdown to refresh
`$spinner = @('|', '/', '-', '\')
`$spinnerPos = 0
`$endTime = (Get-Date).AddSeconds(30)
while ((Get-Date) -lt `$endTime) {
`$remainingSeconds = [math]::Ceiling((`$endTime - (Get-Date)).TotalSeconds)
Write-Host -NoNewline "`r`$(`$spinner[`$spinnerPos % 4]) Refresh in `$("{0:00}" -f `$remainingSeconds)" -BackgroundColor White -ForegroundColor Black
`$spinnerPos++
Start-Sleep -Seconds 1
} Write-Host -NoNewline "`r * Refreshing..."
}
"@
$dashboardBatch = @"
@echo off
powershell.exe -ExecutionPolicy Bypass -File "%USERPROFILE%\dashboard_testnet.ps1"
"@
Set-Content -Path "$env:USERPROFILE\dashboard_testnet.ps1" -Value $dashboard -Encoding UTF8 -ErrorAction SilentlyContinue -Force
Set-Content -Path "$env:USERPROFILE\dashboard_testnet.bat" -Value $dashboardBatch -ErrorAction SilentlyContinue -Force
Write-CurrentTime; Write-Host " Script created: `%USERPROFILE%\dashboard_testnet.ps1..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
function Create-Service {
if (-not (Get-Service -Name $serviceName -ErrorAction SilentlyContinue)) {
Install-NSSM
$ExecutablePath = "$coinPath\raptoreumd.exe"
$Arguments = "-testnet -datadir=$configDir -conf=$configPath"
$NSSM_exe = "$env:UserProfile\nssm-2.24\win64\nssm.exe"
Write-CurrentTime; Write-Host " Creating $serviceName with NSSM..." -ForegroundColor Cyan
& $NSSM_exe install $serviceName $ExecutablePath $Arguments | Out-Null
Write-CurrentTime; Write-Host " Setting $serviceName to start automatically..." -ForegroundColor Yellow
& $NSSM_exe set $serviceName Start SERVICE_AUTO_START | Out-Null
Write-CurrentTime; Write-Host " $serviceName has been created successfully." -ForegroundColor Yellow
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
if (-not $Null -eq $service) {
Write-CurrentTime; Write-Host " Starting daemon service & syncing chain please be patient this will take few moment (10s)..." -ForegroundColor Cyan
Start-Service $serviceName -ErrorAction Continue
Start-Sleep -Seconds 10
Write-CurrentTime; Write-Host " Getting blockchain info (%traptoreumclites% getblockchaininfo)..." -ForegroundColor Yellow
cmd /C "$global:CLI getblockchaininfo" 2>&1
Write-CurrentTime; Write-Host " Getting smartnode status (%traptoreumcli% smartnode status)..." -ForegroundColor Yellow
cmd /C "$global:CLI smartnode status" 2>&1
} else {
Write-CurrentTime; Write-Host " Something is not right, the daemon did not start. Will exit out so try and run the script again..." -ForegroundColor Red
pause
exit
}
Write-CurrentTime; Write-Host " $serviceName has been created and started successfully..." -ForegroundColor Yellow
}
Start-Sleep -Seconds 1
}
$global:securityAns = ""
function Basic-Security {
# If $QuickSetup is provided, just ask about basic security.
param(
[string]$QuickSetup
)
if (-not [string]::IsNullOrEmpty($QuickSetup)) {
do {
$result = Read-Host -Prompt "Would you like to setup basic firewall? (y/n) "
if ($result -eq "y" -or $result -eq "") {
$global:securityAns = 1
$validInput = $true
} elseif ($result -eq "n") {
$validInput = $true
} else {
Write-Host " Please enter 'y', 'n' or leave empty for 'y'..." -ForegroundColor Yellow
$validInput = $false
}
} while (-not $validInput)
return
}
if ($global:securityAns -eq "1") {
Write-CurrentTime; Write-Host " Configuring firewall..." -ForegroundColor Cyan
# Allow SSH and RTM ports
New-NetFirewallRule -DisplayName "Allow SSH" -Direction Inbound -LocalPort $global:sshPort -Protocol TCP -Action Allow | Out-Null
New-NetFirewallRule -DisplayName "Allow Testnet RTM" -Direction Inbound -LocalPort "10230" -Protocol TCP -Action Allow | Out-Null
#New-NetFirewallRule -DisplayName "Allow Raptoreumd" -Direction Inbound -Program "C:\program files (x86)\raptoreumcore\raptoreumd.exe" -Action Allow -Protocol TCP -LocalPort 10230 | Out-Null
#Set-NetFirewallRule -Name "Allow Raptoreumd" -Profile Any | Out-Null
Write-CurrentTime; Write-Host " Firewall configured successfully." -ForegroundColor Yellow
} else {
Write-CurrentTime; Write-Host " Skipping basic security..." -ForegroundColor Yellow
}
Start-Sleep -Seconds 1
}
$global:protxHash = ""
function Schedule-Jobs {
# If $QuickSetup is provided, just ask about ProTx Hash.
param (
[string]$QuickSetup
)
$checkScriptPath = "$env:USERPROFILE\check_testnet.bat"
$chainbackupScriptPath = "$env:USERPROFILE\chainbackup_testnet.bat"
if (-not [string]::IsNullOrEmpty($QuickSetup)) {
do {
$global:protxHash = Read-Host -Prompt "Please enter your protx hash for this SmartNode (txid)"
if ($global:protxHash.Length -ne 64) {
Write-Host " The proTX must be 64 characters long, please check your proTX..." -ForegroundColor Yellow
}
} until ($global:protxHash.Length -eq 64)
return
}
$checkUrl = "https://raw.githubusercontent.com/wizz13150/Raptoreum_SmartNode/main/check_testnet.ps1"
Start-BitsTransfer -Source $checkUrl -Destination "$env:USERPROFILE\check_testnet.ps1" -DisplayName "Downloading file from $checkUrl"
# Replace NODE_PROTX value in check_testnet.ps1
(Get-Content "$env:USERPROFILE\check_testnet.ps1").Replace('#NODE_PROTX=', "`$NODE_PROTX = `"$global:protxHash`"") | Set-Content "$env:USERPROFILE\check_testnet.ps1"
# Create scheduled tasks
Write-CurrentTime; Write-Host " Creating scheduled tasks..." -ForegroundColor cyan
$checkTaskName = "RTMCheck_testnet"
$chainBackupTaskName = "RTMChainBackup_testnet"
Unregister-ScheduledTask -TaskName $checkTaskName -Confirm:$false -ErrorAction SilentlyContinue
Unregister-ScheduledTask -TaskName $chainBackupTaskName -Confirm:$false -ErrorAction SilentlyContinue
# Create trigger for Check task (every 20 minutes)
$checkTrigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date.AddMinutes(20) -RepetitionInterval (New-TimeSpan -Minutes 20)
# Create trigger for ChainBackup task (weekly)
$chainBackupTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Wednesday -WeeksInterval 1 -At 03:00
$checkLog = "$env:USERPROFILE\check-testnet.log"
$bootstrapLog = "$env:USERPROFILE\bootstrap-testnet.log"
$checkAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-Command `"Start-Process cmd.exe -ArgumentList '/c `"$checkScriptPath`"' -Verb RunAs`" > `"$checkLog`""
$chainBackupAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-Command `"Start-Process cmd.exe -ArgumentList '/c `"$chainbackupScriptPath`"' -Verb RunAs`" > `"$bootstrapLog`""
$User = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$Principal = New-ScheduledTaskPrincipal -UserID $User -LogonType S4U -RunLevel Highest
# Timeout before next task
$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 18)
Register-ScheduledTask -TaskName $checkTaskName -Trigger $checkTrigger -Action $checkAction -Principal $Principal -Settings $settings | Out-Null
Register-ScheduledTask -TaskName $chainBackupTaskName -Trigger $chainBackupTrigger -Action $chainBackupAction -Principal $Principal -Settings $settings | Out-Null
Write-CurrentTime; Write-Host " Scheduled tasks successfully created..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
function Log-Rotate {
Install-LogrotateWin
$logrotateConfig = @"
# Debug.log configuration
$configDir\debug.log {
compress
copytruncate
missingok
daily
rotate 7
}
# Bootstrap.log configuration
$env:USERPROFILE\bootstrap_testnet.log {
size 1000k
copytruncate
missingok
rotate 0
}
# Check.log configuration
$env:USERPROFILE\check_testnet.log {
size 1000k
compress
copytruncate
missingok
rotate 3
}
"@
Write-CurrentTime; Write-Host " Configuring logrotate function for debug log..." -ForegroundColor Yellow
$logrotateConfigPath = "$env:USERPROFILE\LogrotateWin\Content\rtmdebuglogrotate_testnet.conf"
if (Test-Path $logrotateConfigPath) {
Write-CurrentTime; Write-Host " Existing log rotate conf found, backing up to ~/rtmdebuglogrotate.old ..." -ForegroundColor Yellow
Move-Item $logrotateConfigPath "$env:USERPROFILE\LogrotateWin\Content\rtmdebuglogrotate_testnet.old" -ErrorAction SilentlyContinue -Force
}
$logrotateConfig | Out-File -FilePath $logrotateConfigPath -Encoding utf8 -Force
Start-Sleep -Seconds 1
}
function Create-MOTD {
Write-Host "================================================================================" -ForegroundColor Yellow
Write-Host " COURTESY OF DK808 FROM ALTTANK ARMY" -ForegroundColor Cyan
Write-Host " Smartnode healthcheck by Delgon" -ForegroundColor Cyan
Write-Host " Adapted to Windows by Wizz" -ForegroundColor Cyan
Write-Host ""
Write-Host " Commands to manage $serviceName(deamon) with cmd :" -ForegroundColor Yellow
Write-Host " TO START - Net Start $serviceName" -ForegroundColor Cyan
Write-Host " TO STOP - Net Stop $serviceName" -ForegroundColor Cyan
Write-Host " STATUS - SC Query $serviceName" -ForegroundColor Cyan
Write-Host " In the event server reboots, the daemon service will auto-start"
Write-Host ""
Write-Host ' To use raptoreum-cli with cmd, simply start a command with %traptoreumcli% :' -ForegroundColor Yellow
Write-Host ' E.g %traptoreumcli% getblockchaininfo' -ForegroundColor Cyan
Write-Host ' E.g %traptoreumcli% smartnode status' -ForegroundColor Cyan
Write-Host ""
Write-Host " To manage the Smartnode, launch 'SmartnodeBash_testnet' on the desktop" -ForegroundColor Yellow
Write-Host " To update the Smartnode, launch 'UpdateSmartnode_testnet' on the desktop" -ForegroundColor Yellow
Write-Host "================================================================================" -ForegroundColor Yellow
Write-Host ' Remember to always encrypt your wallet with a strong password !' -ForegroundColor Green
Write-Host "================================================================================" -ForegroundColor Yellow
$MOTD = @"
================================================================================
SMARTNODE BASH for Testnet
================================================================================
COURTESY OF DK808 FROM ALTTANK ARMY
Smartnode healthcheck by Delgon
Adapted to Windows by Wizz
Commands to manage $serviceName(deamon) with cmd :
TO START - Net Start $serviceName
TO STOP - Net Stop $serviceName
STATUS - SC Query $serviceName
In the event server reboots, the daemon service will auto-start
To use raptoreum-cli with cmd, simply start a command with %traptoreumcli% :
E.g: %traptoreumcli% getblockchaininfo
E.g: %traptoreumcli% smartnode status
To update the Smartnode, launch 'UpdateSmartnode_testnet' on the desktop
================================================================================
Remember to always encrypt your wallet with a strong password !
================================================================================
"@
$bash = @"
@echo off
start cmd.exe /k "type %USERPROFILE%\RTM-MOTD_testnet.txt"
"@
$checkBash = @"
@echo off
powershell.exe -ExecutionPolicy RemoteSigned -File %USERPROFILE%\check_testnet.ps1"
"@
$backupBash = @"
@echo off
powershell.exe -ExecutionPolicy RemoteSigned -File %USERPROFILE%\chainbackup_testnet.ps1"
"@
$backupPath = "$env:USERPROFILE\chainbackup_testnet.bat"
Set-Content -Path $backupPath -Value $backupBash -ErrorAction SilentlyContinue -Force
$batchPath = "$env:USERPROFILE\check_testnet.bat"
Set-Content -Path $batchPath -Value $checkBash -ErrorAction SilentlyContinue -Force
$MOTDPath = "$env:USERPROFILE\RTM-MOTD_testnet.txt"
Set-Content -Path $MOTDPath -Value $MOTD -ErrorAction SilentlyContinue -Force
$bashPath = "$env:USERPROFILE\SmartNodeBash_testnet.bat"
Set-Content -Path $bashPath -Value $bash -ErrorAction SilentlyContinue -Force
}
# Clean the environment from possibly previous setup.
Wipe-Clean
Environment-Variable
KeepWindows-Up
# Ask about things first for quick setup.
Get-SSHPort
Confirm-IP
Create-Conf -QuickSetup $true
Basic-Security -QuickSetup $true
Bootstrap-Chain -QuickSetup $true
Schedule-Jobs -QuickSetup $true
# Run functions
Install-7Zip
Install-Bins
Create-Conf
Bootstrap-Chain
Chain-Backup
Basic-Security
Create-Service
Schedule-Jobs
Log-Rotate
Update-Script
Dashboard-Script
Create-Shortcuts
Create-MOTD
pause