testReveal.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. require_once realpath(dirname(__FILE__)) . '/../common.php';
  3. ini_set("display_errors", "On");
  4. error_reporting(E_ALL & ~E_NOTICE);
  5. //$objLock = new Lock('changeBalance', 30);
  6. //$objLock->lockWait('test', 3);
  7. //sleep(4);
  8. //$objLock->unlock('test');
  9. //exit;
  10. $objEos = new Eos();
  11. $objRedis = dwRedis::init('dw_box');
  12. $objGame = new TableHelper('game', 'dw_box');
  13. $startId = 0;
  14. $errorNum = 0;
  15. for ($i = 0; $i < 100000; $i++) {
  16. if (!$startId) {
  17. $game = $objGame->getRow(['_sortKey' => 'id DESC']);
  18. $startId = (int) $game['id'] ?: 201809140551;
  19. } else {
  20. $game = null;
  21. }
  22. $id = $startId + $i;
  23. if ($game) {
  24. $source = $game['source'];
  25. $commitment = $game['commitment'];
  26. } else {
  27. $cmd = "openssl rand 32 -hex";
  28. $source = exec($cmd);
  29. $cmd = "echo '$source' | xxd -r -p | shasum -a 256 -b | awk '{print $1}'";
  30. $commitment = exec($cmd);
  31. $key = Eos::PRE_SIGN_MAP . $commitment;
  32. // 把原串信息缓存在redis
  33. $objRedis->setex($key, 1800, $source);
  34. }
  35. $cmd = "cleos -u {$GLOBALS['eosUrl']} push action {$GLOBALS['codeBaccarat']} creategame '[ {$id}, \"{$commitment}\" ]' -p {$GLOBALS['codeBaccarat']}";
  36. $output = [];
  37. exec($cmd, $output);
  38. var_dump($output);
  39. $cmd = "cleos -u {$GLOBALS['eosUrl']} push action {$GLOBALS['codeBaccarat']} reveal '[ {$id}, \"{$source}\" ]' -p {$GLOBALS['codeBaccarat']}";
  40. exec($cmd, $output);
  41. var_dump($output);
  42. if (!$output && $errorNum++ > 20) {
  43. break;
  44. }
  45. if ($i % 5 == 0) {
  46. // $objEos->syncGame();
  47. $objSyncGame = new Sync_Game();
  48. $objSyncGame->pubSubscribe();
  49. }
  50. }