PascalCoinMiner.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. FLastLogs.AddObject(msg,TObject(PtrInt(logtype)));
  162. i := FLastLogs.Count-CT_MaxLogs;
  163. if (i<0) then i:=0;
  164. nline := CT_Line_Logs+FDeviceThreads.Count;
  165. while (i<FLastLogs.Count) do begin
  166. WriteLine(nline,FLastLogs[i]);
  167. inc(nline); inc(i);
  168. end;
  169. if FLastLogs.Count>(CT_MaxLogs*2) then begin
  170. for i:=1 to CT_MaxLogs do FLastLogs.Delete(0);
  171. end;
  172. Finally
  173. FLock.Release;
  174. end;
  175. end;
  176. procedure TPascalMinerApp.DoRun;
  177. var
  178. ErrorMsg: String;
  179. s : String;
  180. nsarr : TNodeServerAddressArray;
  181. Function AddMiners : Boolean;
  182. var p,d,c,i : Integer;
  183. strl : TStringList;
  184. devt : TCustomMinerDeviceThread;
  185. begin
  186. Result := false;
  187. if (Not HasOption('p','platform')) And (Not HasOption('d','device')) And (Not HasOption('c','cpu')) then begin
  188. Writeln('Need to specify -p X and -d Y for GPU mining or -c N for CPU mining. See -h for more info');
  189. ShowGPUDrivers;
  190. Terminate;
  191. Exit;
  192. end;
  193. if HasOption('c','cpu') then begin
  194. c := StrToIntDef(GetOptionValue('c','cpu'),-1);
  195. if (c<=0) or (c>CPUCount) then begin
  196. WriteLn('Invalid cpu value ',c,'. Valid values: 1..',CPUCount);
  197. Terminate;
  198. exit;
  199. end;
  200. devt:= TCPUDeviceThread.Create(FPoolMinerThread,CT_TMinerValuesForWork_NULL);
  201. devt.OnStateChanged:=@OnDeviceStateChanged;
  202. devt.OnMinerValuesChanged:=@OnMinerValuesChanged;
  203. devt.OnFoundNOnce:=@OnFoundNOnce;
  204. TCPUDeviceThread(devt).CPUs:=c;
  205. devt.Paused:=true;
  206. FDeviceThreads.Add(devt);
  207. end else begin
  208. p := StrToIntDef(GetOptionValue('p','platform'),-1);
  209. d := StrToIntDef(GetOptionValue('d','device'),-1);
  210. if (p<0) or (p>=TGPUDriver.GPUDriver.Platforms.PlatformCount) then begin
  211. WriteLn('Invalid Platform ',p,'. Valid values: 0..',TGPUDriver.GPUDriver.Platforms.PlatformCount-1);
  212. Terminate;
  213. exit;
  214. end;
  215. strl := TStringList.Create;
  216. try
  217. if (d<0) then begin
  218. // Is a value separated by commas?
  219. strl.Delimiter:=',';
  220. strl.DelimitedText:=GetOptionValue('d','device');
  221. end else strl.Text:=inttostr(d);
  222. for i:=0 to strl.Count-1 do begin
  223. d := StrToIntDef(strl[i],-1);
  224. if (d<0) or (d>=TGPUDriver.GPUDriver.Platforms.Platforms[p]^.DeviceCount) then begin
  225. WriteLn('Invalid device ',d,'. Valid values: 0..',TGPUDriver.GPUDriver.Platforms.Platforms[p]^.DeviceCount-1);
  226. Terminate;
  227. exit;
  228. end;
  229. //
  230. devt := TGPUDeviceThread.Create(FPoolMinerThread,CT_TMinerValuesForWork_NULL);
  231. devt.OnStateChanged:=@OnDeviceStateChanged;
  232. devt.OnMinerValuesChanged:=@OnMinerValuesChanged;
  233. devt.OnFoundNOnce:=@OnFoundNOnce;
  234. TGPUDeviceThread(devt).Platform:=p;
  235. TGPUDeviceThread(devt).Device:=d;
  236. TGPUDeviceThread(devt).ProgramFileName:=ExtractFileDir(ExeName)+PathDelim+CT_OpenCL_FileName;
  237. devt.Paused:=true;
  238. FDeviceThreads.Add(devt);
  239. end;
  240. finally
  241. strl.Free;
  242. end;
  243. end;
  244. Result := true;
  245. end;
  246. Procedure DoWaitAndLog;
  247. Var tc : Cardinal;
  248. gs,ms : TMinerStats;
  249. hrReal,hrHashing, glhrHashing, glhrReal : Real;
  250. i : Integer;
  251. devt : TCustomMinerDeviceThread;
  252. s : String;
  253. Begin
  254. tc := GetTickCount;
  255. repeat
  256. If FPoolMinerThread.PoolMinerClient.Connected then begin
  257. for i:=0 to FDeviceThreads.Count-1 do begin
  258. TCustomMinerDeviceThread(FDeviceThreads[i]).Paused:=false;
  259. end;
  260. end;
  261. while (Not Terminated) do begin
  262. sleep(100);
  263. //devt := TCustomMinerDeviceThread(FDeviceThreads[0]);
  264. If (tc + 1000)<GetTickCount then begin
  265. tc := GetTickCount;
  266. //ms := devt.DeviceStats;
  267. For i:=0 to FDeviceThreads.Count-1 do begin
  268. devt := TCustomMinerDeviceThread(FDeviceThreads[i]);
  269. ms := devt.DeviceStats;
  270. if ms.WorkingMillisecondsHashing>0 then hrHashing := (((ms.RoundsCount DIV Int64(ms.WorkingMillisecondsHashing)))/(1000))
  271. else hrHashing := 0;
  272. gs := devt.GlobalDeviceStats;
  273. If ms.RoundsCount>0 then begin
  274. 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]);
  275. If (gs.Invalids>0) then s := s +' '+inttostr(gs.Invalids)+' ERRORS!';
  276. WriteLine(CT_Line_MiningStatus+i,s);
  277. end else begin
  278. If gs.RoundsCount>0 then begin
  279. 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]);
  280. If (gs.Invalids>0) then s := s +' '+inttostr(gs.Invalids)+' ERRORS!';
  281. end else begin
  282. s := FormatDateTime('hh:nn:ss',now)+' Not mining...';
  283. end;
  284. WriteLine(CT_Line_MiningStatus+i,s);
  285. end;
  286. end;
  287. 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) );
  288. end;
  289. If KeyPressed then begin
  290. If ReadKey in ['c','C','q','Q'] then begin
  291. WriteLine(CT_Line_Logs+FDeviceThreads.Count+CT_MaxLogs,'Finalizing...');
  292. terminate;
  293. end;
  294. end;
  295. end;
  296. until Terminated;
  297. end;
  298. Procedure DoVisualprocess(minerName, UserName, Password : String);
  299. Var sc : tcrtcoord;
  300. Flog : TLog;
  301. devt : TCustomMinerDeviceThread;
  302. i : Integer;
  303. Begin
  304. FPoolMinerThread := TPoolMinerThread.Create(nsarr[0].ip,nsarr[0].port,FPrivateKey.PublicKey);
  305. try
  306. If (UserName<>'') then begin
  307. FPoolMinerThread.PoolMinerClient.PoolType:=ptIdentify;
  308. FPoolMinerThread.PoolMinerClient.UserName:=UserName;
  309. FPoolMinerThread.PoolMinerClient.Password:=Password;
  310. end;
  311. If Not AddMiners then exit;
  312. if HasOption('t','testmode') then begin
  313. i := StrToIntDef(GetOptionValue('t','testmode'),-1);
  314. if (i>=0) And (i<=32) then begin
  315. FPoolMinerThread.TestingPoWLeftBits:=i;
  316. end else begin
  317. WriteLn('Invalid bits for testing mode. value ',i,'. Valid values: 0..32 (0=No testing mode)');
  318. Terminate;
  319. exit;
  320. end;
  321. end;
  322. //
  323. cursoroff;
  324. try
  325. clrscr;
  326. FWindow32X1:=WindMinX;
  327. FWindow32X2:=WindMaxX;
  328. FWindow32Y1:=WindMinY;
  329. FWindow32Y2:=WindMaxY;
  330. WriteLine(1,'** PascalCoin miner ** Version: '+CT_MINER_VERSION);
  331. WriteLine(CT_Line_MinerValues-1,'MINER VALUES:');
  332. WriteLine(CT_Line_MiningStatus-1,'MINING STATUS:');
  333. WriteLine(CT_Line_LastFound+FDeviceThreads.Count-1,'MY VALID BLOCKS FOUND: 0');
  334. WriteLine(CT_Line_Logs+FDeviceThreads.Count-1,'LOGS:');
  335. FPoolMinerThread.MinerAddName:=minerName;
  336. WriteLine(CT_Line_MinerValues-1,'MINER VALUES: (My miner name="'+minerName+'")');
  337. FPoolMinerThread.OnConnectionStateChanged:=@OnConnectionStateChanged;
  338. OnConnectionStateChanged(FPoolMinerThread);
  339. If (FDeviceThreads.Count)=1 then begin
  340. devt := TCustomMinerDeviceThread(FDeviceThreads[0]);
  341. WriteLine(2,devt.MinerDeviceName);
  342. end else begin
  343. WriteLine(2,'Mining using '+IntToStr(FDeviceThreads.Count)+' devices');
  344. end;
  345. Flog := TLog.Create(Nil);
  346. try
  347. Flog.OnInThreadNewLog:=@OnInThreadNewLog;
  348. DoWaitAndLog;
  349. finally
  350. FLog.free;
  351. end;
  352. finally
  353. cursoron;
  354. end;
  355. Finally
  356. FPoolMinerThread.Terminate;
  357. FPoolMinerThread.Free;
  358. end;
  359. end;
  360. Var username,password : String;
  361. begin
  362. FLastLogs := TStringList.Create;
  363. FLock := TCriticalSection.Create;
  364. Try
  365. // quick check parameters
  366. ErrorMsg:=CheckOptions('hp:d:s::c:n::t:u::x::', 'help platform device server cpu minername testmode user pwd');
  367. if ErrorMsg<>'' then begin
  368. //ShowException(Exception.Create(ErrorMsg));
  369. WriteLn(ErrorMsg);
  370. Exit;
  371. end;
  372. // parse parameters
  373. if HasOption('h', 'help') then begin
  374. WriteHelp;
  375. Exit;
  376. end;
  377. if (Not HasOption('p','platform')) And (Not HasOption('d','device')) And (Not HasOption('c','cpu:')) then begin
  378. Writeln('Need to specify -p X and -d Y for GPU mining or -c N for CPU mining');
  379. Writeln('Execute ',ExtractFileName(ExeName),' -h for more info');
  380. ShowGPUDrivers;
  381. Exit;
  382. end;
  383. If Not FileExists(ExtractFileDir(ExeName)+PathDelim+CT_OpenCL_FileName) then begin
  384. Writeln('**********************');
  385. Writeln('OpenCL file not found!');
  386. Writeln('File: ',CT_OpenCL_FileName);
  387. Exit;
  388. end;
  389. If HasOption('s','server') then begin
  390. s := Trim(GetOptionValue('s','server'));
  391. if (s='') then s := 'localhost:'+inttostr(CT_JSONRPCMinerServer_Port);
  392. end else s:='';
  393. if (s='') then begin
  394. WriteLn('Input server name (default is localhost:',CT_JSONRPCMinerServer_Port,'):');
  395. Readln(s);
  396. trim(s);
  397. if (s='') then s := 'localhost:'+inttostr(CT_JSONRPCMinerServer_Port);
  398. end;
  399. if (pos(':',s)=0) then begin
  400. s := trim(s) + ':'+inttostr(CT_JSONRPCMinerServer_Port);
  401. end;
  402. TNode.DecodeIpStringToNodeServerAddressArray(s,nsarr);
  403. if (length(nsarr)<>1) then begin
  404. Writeln('INVALID SERVER VALUE ',s);
  405. WriteHelp;
  406. Exit;
  407. end;
  408. If (Not HasOption('n','minername')) then begin
  409. WriteLn('Input miner name that will be added to server miner name:');
  410. Readln(s);
  411. end else s:=GetOptionValue('n','minername');
  412. Try
  413. TCrypto.InitCrypto;
  414. Except
  415. On E:Exception do begin
  416. Writeln('**************************');
  417. Writeln('Error initializing library '+SSL_C_LIB+' (Not found or not valid)');
  418. Writeln('Error message: '+E.Message);
  419. Writeln('**************************');
  420. Exit;
  421. end;
  422. end;
  423. username:='';
  424. password:='';
  425. If (HasOption('u','user')) Or (HasOption('x','pwd')) then begin
  426. username:=trim(GetOptionValue('u','user'));
  427. password:=trim(GetOptionValue('x','pwd'));
  428. if (username='') then begin
  429. WriteLn('Input Pool username (or empty for non pool connection):');
  430. Readln(username);
  431. end;
  432. if (password='') And (username<>'') then begin
  433. WriteLn('Input Pool password for user ',username,':');
  434. Readln(password);
  435. end;
  436. end;
  437. FPrivateKey := TECPrivateKey.Create;
  438. Try
  439. FPrivateKey.GenerateRandomPrivateKey(CT_Default_EC_OpenSSL_NID);
  440. DoVisualprocess(s,username,password);
  441. finally
  442. FreeAndNil(FPrivateKey);
  443. end;
  444. finally
  445. FreeAndNil(FLock);
  446. FreeAndNil(FLastLogs);
  447. if not terminated then
  448. Terminate;
  449. end;
  450. end;
  451. constructor TPascalMinerApp.Create(TheOwner: TComponent);
  452. Var FLog : TLog;
  453. begin
  454. inherited Create(TheOwner);
  455. FDeviceThreads := TList.Create;
  456. StopOnException:=True;
  457. FAppStartTime := Now;
  458. FLog := TLog.Create(self);
  459. FLog.SaveTypes:=CT_TLogTypes_DEFAULT;
  460. FLog.FileName:=ExtractFileDir(ExeName)+PathDelim+'PascalCoinMiner.log';
  461. end;
  462. destructor TPascalMinerApp.Destroy;
  463. begin
  464. FreeAndNil(FDeviceThreads);
  465. inherited Destroy;
  466. end;
  467. procedure TPascalMinerApp.WriteHelp;
  468. begin
  469. { add your help code here }
  470. writeln('PascalCoin Miner - Version: ',CT_MINER_VERSION);
  471. writeln('Usage: ', ExtractFileName(ExeName), ' -h -s S -p X -d Y -c N -n MYNAME');
  472. writeln(' -h for help');
  473. writeln(' -s S (S is PascalCoin server:port where default value is localhost:',CT_JSONRPCMinerServer_Port,')');
  474. writeln(' -p X (X is GPU platform)');
  475. writeln(' -d Y (Y is GPU device for platform)');
  476. writeln(' Y can be multiple devices. Example -d 0,2,3 Will use devices 0, 2 and 3');
  477. writeln(' -c N (For CPU mining, where N is CPU''s to use. Activating this disable GPU mining)');
  478. writeln(' -n MYNAME (Will add MYNAME value to miner name assigned by server)');
  479. writeln(' ** POOL IDENTIFICATION PROTOCOL **');
  480. writeln(' (Not needed for PascalCoin core, only some third party pools)');
  481. writeln(' -u USERNAME');
  482. writeln(' -x PASSWORD');
  483. writeln('');
  484. writeln('Basic example GPU mining over multiple devices: ');
  485. writeln(' ',ExtractFileName(ExeName),' -p 0 -d 0,1,2,3 -s -n ABC');
  486. writeln(' (Devices 0,1,2,3 at server localhost:',CT_JSONRPCMinerServer_Port,' miner name ABC)');
  487. writeln('');
  488. ShowGPUDrivers;
  489. end;
  490. var
  491. Application: TPascalMinerApp;
  492. begin
  493. Application:=TPascalMinerApp.Create(nil);
  494. Application.Title:='Pascal Miner';
  495. Application.Run;
  496. Application.Free;
  497. end.