PascalCoinMiner.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. program PascalCoinMiner;
  2. {$mode objfpc}{$H+}
  3. {$DEFINE UseCThreads}
  4. {$I ./Units/PascalCoin/config.inc}
  5. { Copyright (c) 2017 by Albert Molina
  6. Distributed under the MIT software license, see the accompanying file LICENSE
  7. or visit http://www.opensource.org/licenses/mit-license.php.
  8. This unit is a part of Pascal Coin, a P2P crypto currency without need of
  9. historical operations.
  10. If you like it, consider a donation using BitCoin:
  11. 16K3HCZRhFUtM8GdWRcfKeaa6KsuyxZaYk
  12. }
  13. uses
  14. {$IFDEF UNIX}{$IFDEF UseCThreads}
  15. cthreads,
  16. {$ENDIF}{$ENDIF}
  17. Classes, SysUtils, CustApp, crt, SyncObjs,
  18. UBlockChain, UPoolMinerThreads, UGPUMining,
  19. UPoolMining, ULog, UThread, UAccounts, UCrypto,
  20. UConst, UTime, UJSONFunctions, UNode, UNetProtocol, USha256,
  21. UOpenSSL,
  22. DelphiCL;
  23. type
  24. { TPascalMinerApp }
  25. TPascalMinerApp = class(TCustomApplication)
  26. FLastLogs : TStringList;
  27. procedure ShowGPUDrivers;
  28. procedure OnConnectionStateChanged(Sender : TObject);
  29. procedure OnDeviceStateChanged(Sender : TObject);
  30. procedure OnMinerValuesChanged(Sender : TObject);
  31. procedure OnFoundNOnce(Sender : TCustomMinerDeviceThread; Timestamp, nOnce : Cardinal);
  32. procedure WriteLine(nline : Integer; txt : String);
  33. procedure OnInThreadNewLog(logtype : TLogType; Time : TDateTime; ThreadID : Cardinal; Const sender, logtext : AnsiString);
  34. protected
  35. FWindow32X1,FWindow32Y1,FWindow32X2,FWindow32Y2: DWord;
  36. FLock : TCriticalSection;
  37. FPrivateKey : TECPrivateKey;
  38. FPoolMinerThread : TPoolMinerThread;
  39. FDeviceThreads : TList;
  40. FAppStartTime : TDateTime;
  41. procedure DoRun; override;
  42. public
  43. constructor Create(TheOwner: TComponent); override;
  44. destructor Destroy; override;
  45. procedure WriteHelp; virtual;
  46. end;
  47. Const
  48. CT_MINER_VERSION = {$IFDEF PRODUCTION}'0.5'{$ELSE}{$IFDEF TESTNET}'0.5 TESTNET'{$ELSE}ERROR{$ENDIF}{$ENDIF};
  49. CT_Line_DeviceStatus = 3;
  50. CT_Line_ConnectionStatus = 4;
  51. CT_Line_MinerValues = 7;
  52. CT_Line_MiningStatus = 10;
  53. CT_Line_LastFound = 12;
  54. CT_Line_Logs = 15;
  55. CT_MaxLogs = 10;
  56. CT_OpenCL_FileName = 'pascalsha.cl';
  57. { TPascalMinerApp }
  58. procedure TPascalMinerApp.ShowGPUDrivers;
  59. Var i,j,n : Integer;
  60. dev : TDCLDevice;
  61. begin
  62. n := 0;
  63. If Not TGPUDriver.GPUDriver.HasOpenCL then WriteLn('No GPU driver found')
  64. else begin
  65. Writeln('');
  66. WriteLn('** Platforms (Total ',TGPUDriver.GPUDriver.Platforms.PlatformCount,')');
  67. for i:=0 to TGPUDriver.GPUDriver.Platforms.PlatformCount-1 do begin
  68. WriteLn('Platform ',i,' Name:',Trim(TGPUDriver.GPUDriver.Platforms.Platforms[i]^.Name),
  69. ' Version:',Trim(TGPUDriver.GPUDriver.Platforms.Platforms[i]^.Version),
  70. ' Vendor:',Trim(TGPUDriver.GPUDriver.Platforms.Platforms[i]^.Vendor),
  71. ' CPU''s:',TGPUDriver.GPUDriver.Platforms.Platforms[i]^.CPUCount,
  72. ' GPU''s:',TGPUDriver.GPUDriver.Platforms.Platforms[i]^.GPUCount,
  73. ' Devices: ',TGPUDriver.GPUDriver.Platforms.Platforms[i]^.DeviceCount
  74. );
  75. inc(n,TGPUDriver.GPUDriver.Platforms.Platforms[i]^.DeviceCount);
  76. end;
  77. Writeln('');
  78. Writeln('** Platforms and devices available: (Total ',n,')');
  79. for i:=0 to TGPUDriver.GPUDriver.Platforms.PlatformCount-1 do begin
  80. for j:=0 to TGPUDriver.GPUDriver.Platforms.Platforms[i]^.DeviceCount-1 do begin
  81. dev := TGPUDriver.GPUDriver.Platforms.Platforms[i]^.Devices[j]^;
  82. Writeln('-p ',i,' -d ',j,' Name:',Trim(dev.Name),' Compute Units:',dev.MaxComputeUnits,' Max Freq.:',dev.MaxClockFrequency);
  83. end;
  84. end;
  85. end;
  86. end;
  87. procedure TPascalMinerApp.OnConnectionStateChanged(Sender: TObject);
  88. Const CT_state : Array[boolean] of String = ('Disconnected','Connected');
  89. var i : Integer;
  90. s : String;
  91. begin
  92. If FPoolMinerThread.PoolMinerClient.PoolType=ptNone then s:='MINING'
  93. else s:='POOL MINING USER "'+FPoolMinerThread.PoolMinerClient.UserName+'"';
  94. If FPoolMinerThread.PoolMinerClient.Connected then begin
  95. WriteLine(CT_Line_ConnectionStatus,s + ' server: '+FPoolMinerThread.PoolMinerClient.ClientRemoteAddr);
  96. For i:=0 to FDeviceThreads.Count-1 do begin
  97. TCustomMinerDeviceThread(FDeviceThreads[i]).Paused:=false;
  98. end;
  99. end else begin
  100. For i:=0 to FDeviceThreads.Count-1 do begin
  101. TCustomMinerDeviceThread(FDeviceThreads[i]).Paused:=true;
  102. end;
  103. WriteLine(CT_Line_ConnectionStatus,'** NOT CONNECTED '+s + ' Connecting to '+FPoolMinerThread.PoolMinerClient.ClientRemoteAddr);
  104. end;
  105. end;
  106. procedure TPascalMinerApp.OnDeviceStateChanged(Sender: TObject);
  107. Var i : Integer;
  108. s : String;
  109. begin
  110. If Sender is TCustomMinerDeviceThread then begin
  111. If TCustomMinerDeviceThread(Sender).IsMining then WriteLine(CT_Line_DeviceStatus,'') // clear line
  112. else WriteLine(CT_Line_DeviceStatus,'*** Not mining ***');
  113. end;
  114. end;
  115. procedure TPascalMinerApp.OnMinerValuesChanged(Sender: TObject);
  116. begin
  117. If Sender is TCustomMinerDeviceThread then begin
  118. If TCustomMinerDeviceThread(Sender).MinerValuesForWork.block>0 then begin
  119. WriteLine(CT_Line_MinerValues,Format('Current block: %d Wallet Name: "%s" Target: %s',
  120. [TCustomMinerDeviceThread(Sender).MinerValuesForWork.block,
  121. FPoolMinerThread.GlobalMinerValuesForWork.payload_start,
  122. IntToHex(TCustomMinerDeviceThread(Sender).MinerValuesForWork.target,8)
  123. ]));
  124. end;
  125. end;
  126. end;
  127. procedure TPascalMinerApp.OnFoundNOnce(Sender: TCustomMinerDeviceThread; Timestamp, nOnce: Cardinal);
  128. begin
  129. WriteLine(CT_Line_LastFound + FDeviceThreads.Count,FormatDateTime('hh:nn:ss',now)+' Block:'+IntToStr(Sender.MinerValuesForWork.block)+' NOnce:'+Inttostr(nOnce)+
  130. ' Timestamp:'+inttostr(Timestamp)+' Miner:'+Sender.MinerValuesForWork.payload_start);
  131. end;
  132. procedure TPascalMinerApp.WriteLine(nline: Integer; txt: String);
  133. Var i : Integer;
  134. begin
  135. FLock.Acquire;
  136. try
  137. i := length(txt);
  138. if i<=(FWindow32X2-FWindow32X1+1) then begin
  139. setlength(txt,FWindow32X2-FWindow32X1+1);
  140. fillchar(txt[i+1],FWindow32X2-FWindow32X1+1-i,' ');
  141. end else begin
  142. txt := copy(txt,1,FWindow32X2-FWindow32X1+1);
  143. end;
  144. if (nline<=(FWindow32Y2-FWindow32Y1)) then begin
  145. GotoXY32(FWindow32X1,nline);
  146. write(txt);
  147. end;
  148. finally
  149. FLock.Release;
  150. end;
  151. end;
  152. procedure TPascalMinerApp.OnInThreadNewLog(logtype: TLogType; Time: TDateTime;
  153. ThreadID: Cardinal; const sender, logtext: AnsiString);
  154. var msg : String;
  155. i,nline : Integer;
  156. begin
  157. If logtype=ltdebug then exit;
  158. FLock.Acquire;
  159. try
  160. msg := formatdatetime('hh:nn:ss',now)+' '+CT_LogType[logtype]+' '+logtext;
  161. // TODO - test logtype is properly casted/stored/retrieved/accessed.
  162. // Confirm casting doesn't lose bits in 32/64 bit archs
  163. // OLD: FLastLogs.AddObject(msg,TObject(PtrInt(logtype)));
  164. FLastLogs.AddObject(msg,TObject(Int(QWord(logtype))));
  165. i := FLastLogs.Count-CT_MaxLogs;
  166. if (i<0) then i:=0;
  167. nline := CT_Line_Logs+FDeviceThreads.Count;
  168. while (i<FLastLogs.Count) do begin
  169. WriteLine(nline,FLastLogs[i]);
  170. inc(nline); inc(i);
  171. end;
  172. if FLastLogs.Count>(CT_MaxLogs*2) then begin
  173. for i:=1 to CT_MaxLogs do FLastLogs.Delete(0);
  174. end;
  175. Finally
  176. FLock.Release;
  177. end;
  178. end;
  179. procedure TPascalMinerApp.DoRun;
  180. var
  181. ErrorMsg: String;
  182. s : String;
  183. nsarr : TNodeServerAddressArray;
  184. Function AddMiners : Boolean;
  185. var p,d,c,i : Integer;
  186. strl : TStringList;
  187. devt : TCustomMinerDeviceThread;
  188. begin
  189. Result := false;
  190. if (Not HasOption('p','platform')) And (Not HasOption('d','device')) And (Not HasOption('c','cpu')) then begin
  191. Writeln('Need to specify -p X and -d Y for GPU mining or -c N for CPU mining. See -h for more info');
  192. ShowGPUDrivers;
  193. Terminate;
  194. Exit;
  195. end;
  196. if HasOption('c','cpu') then begin
  197. c := StrToIntDef(GetOptionValue('c','cpu'),-1);
  198. if (c<=0) or (c>CPUCount) then begin
  199. WriteLn('Invalid cpu value ',c,'. Valid values: 1..',CPUCount);
  200. Terminate;
  201. exit;
  202. end;
  203. devt:= TCPUDeviceThread.Create(FPoolMinerThread,CT_TMinerValuesForWork_NULL);
  204. devt.OnStateChanged:=@OnDeviceStateChanged;
  205. devt.OnMinerValuesChanged:=@OnMinerValuesChanged;
  206. devt.OnFoundNOnce:=@OnFoundNOnce;
  207. TCPUDeviceThread(devt).CPUs:=c;
  208. devt.Paused:=true;
  209. FDeviceThreads.Add(devt);
  210. end else begin
  211. p := StrToIntDef(GetOptionValue('p','platform'),-1);
  212. d := StrToIntDef(GetOptionValue('d','device'),-1);
  213. if (p<0) or (p>=TGPUDriver.GPUDriver.Platforms.PlatformCount) then begin
  214. WriteLn('Invalid Platform ',p,'. Valid values: 0..',TGPUDriver.GPUDriver.Platforms.PlatformCount-1);
  215. Terminate;
  216. exit;
  217. end;
  218. strl := TStringList.Create;
  219. try
  220. if (d<0) then begin
  221. // Is a value separated by commas?
  222. strl.Delimiter:=',';
  223. strl.DelimitedText:=GetOptionValue('d','device');
  224. end else strl.Text:=inttostr(d);
  225. for i:=0 to strl.Count-1 do begin
  226. d := StrToIntDef(strl[i],-1);
  227. if (d<0) or (d>=TGPUDriver.GPUDriver.Platforms.Platforms[p]^.DeviceCount) then begin
  228. WriteLn('Invalid device ',d,'. Valid values: 0..',TGPUDriver.GPUDriver.Platforms.Platforms[p]^.DeviceCount-1);
  229. Terminate;
  230. exit;
  231. end;
  232. //
  233. devt := TGPUDeviceThread.Create(FPoolMinerThread,CT_TMinerValuesForWork_NULL);
  234. devt.OnStateChanged:=@OnDeviceStateChanged;
  235. devt.OnMinerValuesChanged:=@OnMinerValuesChanged;
  236. devt.OnFoundNOnce:=@OnFoundNOnce;
  237. TGPUDeviceThread(devt).Platform:=p;
  238. TGPUDeviceThread(devt).Device:=d;
  239. TGPUDeviceThread(devt).ProgramFileName:=ExtractFileDir(ExeName)+PathDelim+CT_OpenCL_FileName;
  240. devt.Paused:=true;
  241. FDeviceThreads.Add(devt);
  242. end;
  243. finally
  244. strl.Free;
  245. end;
  246. end;
  247. Result := true;
  248. end;
  249. Procedure DoWaitAndLog;
  250. Var tc : Cardinal;
  251. gs,ms : TMinerStats;
  252. hrReal,hrHashing, glhrHashing, glhrReal : Real;
  253. i : Integer;
  254. devt : TCustomMinerDeviceThread;
  255. s : String;
  256. Begin
  257. tc := GetTickCount64;
  258. repeat
  259. If FPoolMinerThread.PoolMinerClient.Connected then begin
  260. for i:=0 to FDeviceThreads.Count-1 do begin
  261. TCustomMinerDeviceThread(FDeviceThreads[i]).Paused:=false;
  262. end;
  263. end;
  264. while (Not Terminated) do begin
  265. sleep(100);
  266. //devt := TCustomMinerDeviceThread(FDeviceThreads[0]);
  267. If (tc + 1000)<GetTickCount64 then begin
  268. tc := GetTickCount64;
  269. //ms := devt.DeviceStats;
  270. For i:=0 to FDeviceThreads.Count-1 do begin
  271. devt := TCustomMinerDeviceThread(FDeviceThreads[i]);
  272. ms := devt.DeviceStats;
  273. if ms.WorkingMillisecondsHashing>0 then hrHashing := (((ms.RoundsCount DIV Int64(ms.WorkingMillisecondsHashing)))/(1000))
  274. else hrHashing := 0;
  275. gs := devt.GlobalDeviceStats;
  276. If ms.RoundsCount>0 then begin
  277. s := FormatDateTime('hh:nn:ss',now)+Format(' Miner:"%s" at %0.2f MH/s - Rounds: %0.2f G Found: %d',[devt.MinerValuesForWork.payload_start,hrHashing, gs.RoundsCount/1000000000, gs.WinsCount]);
  278. If (gs.Invalids>0) then s := s +' '+inttostr(gs.Invalids)+' ERRORS!';
  279. WriteLine(CT_Line_MiningStatus+i,s);
  280. end else begin
  281. If gs.RoundsCount>0 then begin
  282. s := FormatDateTime('hh:nn:ss',now)+Format(' Miner:"%s" **NOT MINING** - Rounds: %0.2f G Found: %d',[devt.MinerValuesForWork.payload_start,gs.RoundsCount/1000000000, gs.WinsCount]);
  283. If (gs.Invalids>0) then s := s +' '+inttostr(gs.Invalids)+' ERRORS!';
  284. end else begin
  285. s := FormatDateTime('hh:nn:ss',now)+' Not mining...';
  286. end;
  287. WriteLine(CT_Line_MiningStatus+i,s);
  288. end;
  289. end;
  290. WriteLine(CT_Line_LastFound+FDeviceThreads.Count-1,'MY VALID BLOCKS FOUND: '+IntToStr(gs.WinsCount) +' Working time: '+IntToStr(Trunc(now - FAppStartTime))+'d '+FormatDateTime('hh:nn:ss',Now-FAppStartTime) );
  291. end;
  292. If KeyPressed then begin
  293. If ReadKey in ['c','C','q','Q'] then begin
  294. WriteLine(CT_Line_Logs+FDeviceThreads.Count+CT_MaxLogs,'Finalizing...');
  295. terminate;
  296. end;
  297. end;
  298. end;
  299. until Terminated;
  300. end;
  301. Procedure DoVisualprocess(minerName, UserName, Password : String);
  302. Var sc : tcrtcoord;
  303. Flog : TLog;
  304. devt : TCustomMinerDeviceThread;
  305. i : Integer;
  306. Begin
  307. FPoolMinerThread := TPoolMinerThread.Create(nsarr[0].ip,nsarr[0].port,FPrivateKey.PublicKey);
  308. try
  309. If (UserName<>'') then begin
  310. FPoolMinerThread.PoolMinerClient.PoolType:=ptIdentify;
  311. FPoolMinerThread.PoolMinerClient.UserName:=UserName;
  312. FPoolMinerThread.PoolMinerClient.Password:=Password;
  313. end;
  314. If Not AddMiners then exit;
  315. if HasOption('t','testmode') then begin
  316. i := StrToIntDef(GetOptionValue('t','testmode'),-1);
  317. if (i>=0) And (i<=32) then begin
  318. FPoolMinerThread.TestingPoWLeftBits:=i;
  319. end else begin
  320. WriteLn('Invalid bits for testing mode. value ',i,'. Valid values: 0..32 (0=No testing mode)');
  321. Terminate;
  322. exit;
  323. end;
  324. end;
  325. //
  326. cursoroff;
  327. try
  328. clrscr;
  329. FWindow32X1:=WindMinX;
  330. FWindow32X2:=WindMaxX;
  331. FWindow32Y1:=WindMinY;
  332. FWindow32Y2:=WindMaxY;
  333. WriteLine(1,'** PascalCoin miner ** Version: '+CT_MINER_VERSION);
  334. WriteLine(CT_Line_MinerValues-1,'MINER VALUES:');
  335. WriteLine(CT_Line_MiningStatus-1,'MINING STATUS:');
  336. WriteLine(CT_Line_LastFound+FDeviceThreads.Count-1,'MY VALID BLOCKS FOUND: 0');
  337. WriteLine(CT_Line_Logs+FDeviceThreads.Count-1,'LOGS:');
  338. FPoolMinerThread.MinerAddName:=minerName;
  339. WriteLine(CT_Line_MinerValues-1,'MINER VALUES: (My miner name="'+minerName+'")');
  340. FPoolMinerThread.OnConnectionStateChanged:=@OnConnectionStateChanged;
  341. OnConnectionStateChanged(FPoolMinerThread);
  342. If (FDeviceThreads.Count)=1 then begin
  343. devt := TCustomMinerDeviceThread(FDeviceThreads[0]);
  344. WriteLine(2,devt.MinerDeviceName);
  345. end else begin
  346. WriteLine(2,'Mining using '+IntToStr(FDeviceThreads.Count)+' devices');
  347. end;
  348. Flog := TLog.Create(Nil);
  349. try
  350. Flog.OnInThreadNewLog:=@OnInThreadNewLog;
  351. DoWaitAndLog;
  352. finally
  353. FLog.free;
  354. end;
  355. finally
  356. cursoron;
  357. end;
  358. Finally
  359. FPoolMinerThread.Terminate;
  360. FPoolMinerThread.Free;
  361. end;
  362. end;
  363. Var username,password : String;
  364. begin
  365. FLastLogs := TStringList.Create;
  366. FLock := TCriticalSection.Create;
  367. Try
  368. // quick check parameters
  369. ErrorMsg:=CheckOptions('hp:d:s::c:n::t:u::x::', 'help platform device server cpu minername testmode user pwd');
  370. if ErrorMsg<>'' then begin
  371. //ShowException(Exception.Create(ErrorMsg));
  372. WriteLn(ErrorMsg);
  373. Exit;
  374. end;
  375. // parse parameters
  376. if HasOption('h', 'help') then begin
  377. WriteHelp;
  378. Exit;
  379. end;
  380. if (Not HasOption('p','platform')) And (Not HasOption('d','device')) And (Not HasOption('c','cpu:')) then begin
  381. Writeln('Need to specify -p X and -d Y for GPU mining or -c N for CPU mining');
  382. Writeln('Execute ',ExtractFileName(ExeName),' -h for more info');
  383. ShowGPUDrivers;
  384. Exit;
  385. end;
  386. If Not FileExists(ExtractFileDir(ExeName)+PathDelim+CT_OpenCL_FileName) then begin
  387. Writeln('**********************');
  388. Writeln('OpenCL file not found!');
  389. Writeln('File: ',CT_OpenCL_FileName);
  390. Exit;
  391. end;
  392. If HasOption('s','server') then begin
  393. s := Trim(GetOptionValue('s','server'));
  394. if (s='') then s := 'localhost:'+inttostr(CT_JSONRPCMinerServer_Port);
  395. end else s:='';
  396. if (s='') then begin
  397. WriteLn('Input server name (default is localhost:',CT_JSONRPCMinerServer_Port,'):');
  398. Readln(s);
  399. trim(s);
  400. if (s='') then s := 'localhost:'+inttostr(CT_JSONRPCMinerServer_Port);
  401. end;
  402. if (pos(':',s)=0) then begin
  403. s := trim(s) + ':'+inttostr(CT_JSONRPCMinerServer_Port);
  404. end;
  405. TNode.DecodeIpStringToNodeServerAddressArray(s,nsarr);
  406. if (length(nsarr)<>1) then begin
  407. Writeln('INVALID SERVER VALUE ',s);
  408. WriteHelp;
  409. Exit;
  410. end;
  411. If (Not HasOption('n','minername')) then begin
  412. WriteLn('Input miner name that will be added to server miner name:');
  413. Readln(s);
  414. end else s:=GetOptionValue('n','minername');
  415. Try
  416. TCrypto.InitCrypto;
  417. Except
  418. On E:Exception do begin
  419. Writeln('**************************');
  420. Writeln('Error initializing library '+SSL_C_LIB+' (Not found or not valid)');
  421. Writeln('Error message: '+E.Message);
  422. Writeln('**************************');
  423. Exit;
  424. end;
  425. end;
  426. username:='';
  427. password:='';
  428. If (HasOption('u','user')) Or (HasOption('x','pwd')) then begin
  429. username:=trim(GetOptionValue('u','user'));
  430. password:=trim(GetOptionValue('x','pwd'));
  431. if (username='') then begin
  432. WriteLn('Input Pool username (or empty for non pool connection):');
  433. Readln(username);
  434. end;
  435. if (password='') And (username<>'') then begin
  436. WriteLn('Input Pool password for user ',username,':');
  437. Readln(password);
  438. end;
  439. end;
  440. FPrivateKey := TECPrivateKey.Create;
  441. Try
  442. FPrivateKey.GenerateRandomPrivateKey(CT_Default_EC_OpenSSL_NID);
  443. DoVisualprocess(s,username,password);
  444. finally
  445. FreeAndNil(FPrivateKey);
  446. end;
  447. finally
  448. FreeAndNil(FLock);
  449. FreeAndNil(FLastLogs);
  450. if not terminated then
  451. Terminate;
  452. end;
  453. end;
  454. constructor TPascalMinerApp.Create(TheOwner: TComponent);
  455. Var FLog : TLog;
  456. begin
  457. inherited Create(TheOwner);
  458. FDeviceThreads := TList.Create;
  459. StopOnException:=True;
  460. FAppStartTime := Now;
  461. FLog := TLog.Create(self);
  462. FLog.SaveTypes:=CT_TLogTypes_DEFAULT;
  463. FLog.FileName:=ExtractFileDir(ExeName)+PathDelim+'PascalCoinMiner.log';
  464. end;
  465. destructor TPascalMinerApp.Destroy;
  466. begin
  467. FreeAndNil(FDeviceThreads);
  468. inherited Destroy;
  469. end;
  470. procedure TPascalMinerApp.WriteHelp;
  471. begin
  472. { add your help code here }
  473. writeln('PascalCoin Miner - Version: ',CT_MINER_VERSION);
  474. writeln('Usage: ', ExtractFileName(ExeName), ' -h -s S -p X -d Y -c N -n MYNAME');
  475. writeln(' -h for help');
  476. writeln(' -s S (S is PascalCoin server:port where default value is localhost:',CT_JSONRPCMinerServer_Port,')');
  477. writeln(' -p X (X is GPU platform)');
  478. writeln(' -d Y (Y is GPU device for platform)');
  479. writeln(' Y can be multiple devices. Example -d 0,2,3 Will use devices 0, 2 and 3');
  480. writeln(' -c N (For CPU mining, where N is CPU''s to use. Activating this disable GPU mining)');
  481. writeln(' -n MYNAME (Will add MYNAME value to miner name assigned by server)');
  482. writeln(' ** POOL IDENTIFICATION PROTOCOL **');
  483. writeln(' (Not needed for PascalCoin core, only some third party pools)');
  484. writeln(' -u USERNAME');
  485. writeln(' -x PASSWORD');
  486. writeln('');
  487. writeln('Basic example GPU mining over multiple devices: ');
  488. writeln(' ',ExtractFileName(ExeName),' -p 0 -d 0,1,2,3 -s -n ABC');
  489. writeln(' (Devices 0,1,2,3 at server localhost:',CT_JSONRPCMinerServer_Port,' miner name ABC)');
  490. writeln('');
  491. ShowGPUDrivers;
  492. end;
  493. var
  494. Application: TPascalMinerApp;
  495. begin
  496. Application:=TPascalMinerApp.Create(nil);
  497. Application.Title:='Pascal Miner';
  498. Application.Run;
  499. Application.Free;
  500. end.