Advertisement
Guest User

crash

a guest
Feb 21st, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. //REQUIRES https://github.com/emn178/js-sha3
  2. var hash = "0a6ae43a8a40074816f44cf23db029d3d4fc639dfb58925aa72b7ae03182c197";
  3. var secret = "639fd110d205287b5711070b8936019a30c073e5701ff67073b6edd166e223e6";
  4. var round_id = "435793";
  5. var day_of_month = "21";
  6. var crash_point = 1.09;
  7. var instant_crash_percentage = 4;
  8. var instant_crash_mode = 1;
  9.  
  10. var outcome = keccak512.create();
  11. outcome.update(secret);
  12. outcome.update(round_id);
  13. outcome.update(day_of_month);
  14.  
  15. var outcome_hash = outcome.hex();
  16.  
  17. var calculateCrashPoint = function(outcome_hash) {
  18. var divisible = function divisible(hash, mod) {
  19. var val = 0;
  20.  
  21. var o = hash.length % 4;
  22. for (var i = o > 0 ? o - 4 : 0; i < hash.length; i += 4) {
  23. val = ((val << 16) + parseInt(hash.substring(i, i + 4), 16)) %
  24. mod;
  25. }
  26. return val === 0;
  27. };
  28.  
  29. var isInstantCrash = function (hash, percentage) {
  30. //we calculate a ticket and check if its less than the crash percentage
  31. var ticket = 100.0;
  32. var sub_hash = "";
  33. for (var i = 0; i < outcome_hash.length; ++i) {
  34. sub_hash += outcome_hash[i];
  35. if (sub_hash.length > 7)
  36. {
  37. var num = parseInt(sub_hash, 16);
  38. if ((num != NaN)) { ticket = (num % 1000001) / 10000.0;
  39. break;
  40. } sub_hash = "";
  41. }
  42. }
  43. return ticket < percentage ? true : false;
  44. };
  45.  
  46. //we calculate if this round is instant crash with one of the following modes
  47. if ((instant_crash_mode === 0) && divisible(outcome_hash, 100.0 / instant_crash_percentage)) {
  48. return 0.0;
  49. }
  50. //new way of calculating instant crash so we can allow a lower percentage and more fairness
  51. else if ((instant_crash_mode === 1) && isInstantCrash(outcome_hash, instant_crash_percentage))
  52. {
  53. return 0.0;
  54. }
  55. // Use the most significant 52-bit from the hash to calculate the crash point
  56. var h = parseInt(outcome_hash.slice(0, 52 / 4), 16);
  57. var e = Math.pow(2, 52); return Math.floor((100 * e - h) / (e - h)) / 100.0;
  58. };
  59. console.log("calculated outcome:" + calculateCrashPoint(outcome_hash));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement