SHARE
TWEET

Untitled

a guest May 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ErrorActionPreference = "Continue"
  2. $DebugPreference       = "Continue"
  3.  
  4. # load functions
  5. # slack
  6.  
  7. function Send-Slack ($message) {
  8.     Set-StrictMode -Version Latest
  9.     $payload = @{
  10.         "channel"     = "#focus" # script will fail if channel doesn't exist. will default to webhook settings if not specified.
  11.         #"icon_emoji" = ":whale:"
  12.         "text"        = $message
  13.         "username"    = "MtGoxMon"
  14.     }
  15.     Invoke-WebRequest -Body (ConvertTo-Json -Compress -InputObject $payload) -Method Post -Uri $webhook | Out-Null
  16. }
  17.  
  18.  
  19. # environment specific variables
  20. # ---------------------------------------------------------
  21. # PROD
  22.    $webhook = "https://hooks.slack.com/services/" #bitcoinmarkets slack webhook here
  23. . "$($PSSCriptRoot)/Send-Tweet_PROD.ps1"  # twitter
  24. # ---------------------------------------------------------
  25.  
  26. $addresses = @('12KkeeRkiNS13GMbg7zos9KRn9ggvZtZgx',
  27. '12T4oSNd4t9ty9fodgNd47TWhK35pAxDYN',
  28. '13ahgw8sM95EDbugT3tdb8TYoMU46Uw7PX',
  29. '13dXFMyG22EsUsvaWhCqUo7SXuX7rBPog6',
  30. '13sXfpp2V16nnxYvW9FHHoBdMa3k98uJw8',
  31. '13Wv5hGhubAWgSPWtXYh6s1s7HX2N1psYg',
  32. '13xGCc4TPSYY9GYxBGVNox82KxyjkFnxMX',
  33. '1439q4Na8v88kPBqoyg8F4ueL9SYr8ANWj',
  34. '14mP6caC5dFhHdVAPCjPKM8Nm36MBDR5pM',
  35. '14p4w3TRCd6NMRSnzTmgdvQhNnbrAmzXmy',
  36. '14USZ558Rr28AZwdJQyciSQkN4JT1cEoj2',
  37. '155FsTtEFq4eGCcBxDseuwLKPbmtWbyHJR',
  38. '156HpsWfgkWYLT63uhTAGUSUF3ZMnB9WWj',
  39. '15kNZcrhxeFZgVVLK2Yjzd69tRidbFdJEZ',
  40. '15QcKCa84ZCHxbsqXDoKhi5XbmQB8jPEAd',
  41. '15SeCwVCFx5cWyrcdD1Zp1D1zxjH2SELPg',
  42. '15U4VsmWG1cdXAtizvQsW4r7iMxzp64Tgu',
  43. '16jZZkMYqjUWUtQ9DfDvHdH5ko5BcnH9XQ',
  44. '16W4XcUAKPmSES9MiUCio28msSCp8rDZgs',
  45. '16w6sZBDP58yyeyZAcvnxcEGJpwR9amM6g',
  46. '17etv2L3nhk6SCcWSNW4eoZkBy84izAm17',
  47. '17KcBp8g76Ue8pywgjta4q8Ds6wK4bEKp7',
  48. '17Tf4bVQaCzwWrDWGRPC97RLCHnU4LY8Qr',
  49. '18hcZVFPqDNAovJmb9vA6hEJrDz6uWXNGh',
  50. '18KDS3q6a4YV9Nn8jcyMvNoVPfcrfemeag',
  51. '18M1Z337NqLtK9V69bssnQUYsvb7hmfSFS',
  52. '18ok25NTkdrUzdByFJCNVsqVYkujZ8aP45',
  53. '18YDgRhxsomuBZ1g9d8Y1JuRmxDhF8Bvff',
  54. '195HvmjXgoF3M5vFaBC8swZPhwrE7VhxRD',
  55. '199Yxz2TJGtND3QKsHTptTJivqSaUZBvku',
  56. '19c8sUa54yQuRTVDfJa3iDkkCaFkzBJLPB',
  57. '19Cr4zXpKw43xLJhFZW9iv4DDNtQk2TDeB',
  58. '19eihBKk6e5YD2QXAe4SVUsxRLLnTDKsfv',
  59. '19KiFrafXEyJCUDYFEv3B6tBUwyfFo7kNU',
  60. '1Ar6meJQCkNoC9wnPcyRNNpzX5fBDaGcKd',
  61. '1AZu7TQmKBAes2duNDctYwjAB9nhHczUnA',
  62. '1B6kJM75iu5ty1HAHMMz6tT1HhjoGNTCa9',
  63. '1BDZBTb4KE5oq6wAgA6EvAe3uCFRrAbPao',
  64. '1BXyJc6BVuTFnHQCcjiWX2xmCPNVfaSZeb',
  65. '1BzK87zuqidZn489Wb2oLSktrjKrX7TLKe',
  66. '1C5aU4Xnpd3txbxehk46UZgiuNB8QdpHCH',
  67. '1CRjKZJu8LvTutnSKq4zTJ4yiqrzMAArYW',
  68. '1CZsoJfkknbnW5fKrt1oR7N1ALE5WmDGP1',
  69. '1DedUxzgwErg4ipNi988wPgLk5thwciKcc',
  70. '1Drshi4RAuvxk4T6Bkq959ZvLbvy7b1wvD',
  71. '1EiiKCCnFgHjEvPZdu29qqgdBm8zTvpU3U',
  72. '1EK8vW7UYaYHKiW4TZmYJKtwcZLM14VjvP',
  73. '1FhRuUkk8Bfx8FJDemtxhKAR4F8GCNKrXG',
  74. '1FrV9hv1AW34BGJvobJatyzUWYDWB9epRW',
  75. '1Fu4YgM3Y9CxvioGPqkSzkydAC8MVaPN1D',
  76. '1G23Uzwj55k2A9TRwaTknqGav66oDTkWCu',
  77. '1GkZQcDy8V6pmHFZqUBUBCnN9dc2hoWasD',
  78. '1GyDutntMuYyA2vQGW5HFcKLfx4cbDdbJq',
  79. '1H4K3dGfNbAN4AUfyUrpkGpjrd83sntDpV',
  80. '1Hb8DmmvvtTYv5RBLuGtDxznkZwVpd5Vjy',
  81. '1HdKXsNQtzDcfB6PGM7DWTgX9vhBWsz1ak',
  82. '1Hm6XDmhKCHz68wDEYTapN9MEanke8iwUk',
  83. '1HuPVqz2xvf1rdNFUqd62vRTyxP3jeX9Ch',
  84. '1HweN9p41BY2RBunsPqyVuheEq7gVoxA9u',
  85. '1HX4s3JeFU3x1eQgPNQVAdx6FoCtbb1hr8',
  86. '1HzEPuenagLEWj68igDXBBXrzc293RuR5V',
  87. '1JtgU6Uo1RAt5eiMf34EehyatUezBQP36C',
  88. '1JVmoJT3471FjsX5H4hAeR1RyrDgpkHbpm',
  89. '1JVU43LNKXqa9W5fCh8tppxDDEWgfeNg46',
  90. '1JztCg7eKSkb1vi7NzGJynXpLZmoaFtYud',
  91. '1KFDUSZuapMv7YaDmL6cyrHTQhma1MtFYs',
  92. '1LLc8aA9C9LLULGbYCYSFKXgxKP2DXdCqP',
  93. '1LS5EFRRMDgMQusW6zokQUHjzNUfy6HHCQ',
  94. '1LueUjEuBgc7cQhsWT8zAfTjcWmrNBZXaR',
  95. '1LXi3x7hyt17cxncscGE887WCrC6XDNZ4P',
  96. '1LzwbLgdKd4eFLkpRdeajkH1YJkVCip2zj',
  97. '1MkyfwJf7uhWTmVGGQXfcT5ip31DoHMxsz',
  98. '1Mm9brripN4RPTzkGnRrbt5uDWdqbfk2iX',
  99. '1MPJJzRaT8vLhowNB4dVyWRxxu79dq7WkB',
  100. '1MvpYtqgBH7CXbTutrSVCTNHPzm9vakuRy',
  101. '1N5X4kcZ56uRh24XrZoztS9Vb8G7j1Joop',
  102. '1NA3Tj4b1jtx9eGELe31Jw4DrzTqKP3ayH',
  103. '1Pq7hooZbEAz5y3QMnqFY8C5xqTdrjUwcA',
  104. '1PRXQEoL8vzEzoJJ9hbtAP6NaV2daccAUn',
  105. '1PxGTuJzDx1ceFHx4Z5CHaWuhiPBNovmZD')
  106.  
  107.  
  108. ### end environment specific variables
  109.  
  110. function checkBalance ($address) {
  111.  
  112.     $tweetTimestamp = Get-Date -Format ddMMHHmmss
  113.  
  114.     # if address log does not exist, create it and log its balance
  115.     if (!(Test-Path -Path $PSScriptRoot\log\$($address).log)) {
  116.  
  117.         [long]$balance = (Invoke-WebRequest -Uri "https://blockchain.info/q/addressbalance/$($address)" -UseBasicParsing).Content
  118.         Write-Output "$($balance)" | Out-File $PSScriptRoot\log\$($address).log -Force
  119.     }
  120.  
  121.  
  122.     # store the wallet balance from log in a variable
  123.     $oldBalance = Get-Content -Path $PSScriptRoot\log\$($address).log
  124.     Write-Debug  "Wallet balance ($address) is $oldBalance"
  125.  
  126.  
  127.     # check the address balance using api call
  128.     [long]$balance = (Invoke-WebRequest -Uri "https://blockchain.info/q/addressbalance/$($address)" -UseBasicParsing).Content
  129.     Write-Debug    "Old: $oldBalance | New: $balance"
  130.  
  131.     # compare old balance against most recent
  132.     if ($balance -eq $oldBalance) {
  133.         Write-Debug "No change"
  134.     }
  135.  
  136.     elseif ($balance -gt $oldBalance) {
  137.         Write-Debug "Increase"
  138.         $value = $($balance - $oldBalance)
  139.         # convert the value (returned in satoshis) to BTC
  140.         $value = $value/100000000
  141.         $value = [math]::round($value,4)
  142.         # send notifications
  143.         #Send-Slack "An address controlled by the Mt. Gox trustee has just *increased* in value by $($value) BTC. (<https://blockchain.info/address/$($address)|$($address)>)"
  144.         Send-Tweet -Message "$($address) increased by $($value)BTC https://blockchain.info/address/$($address) $tweetTimestamp" | Out-Null
  145.     }
  146.  
  147.     elseif ($balance -lt $oldBalance) {
  148.         Write-Debug "Decrease"
  149.         $value = $($balance - $oldBalance)
  150.         # value returned will be negative, so strip the negative indicator
  151.         $value = $value -replace "-"
  152.         # convert the value (returned in satoshis) to BTC
  153.         $value = $value/100000000
  154.         $value = [math]::round($value,4)
  155.         # send notifications
  156.         Send-Slack "An address controlled by the Mt. Gox trustee has just *decreased* in value by $($value) BTC. :rotating_light: This may mean these coins will soon be market-sold. :rotating_light: (<https://blockchain.info/address/$($address)|$($address)>)"
  157.         Send-Tweet -Message "$($address) decreased by $($value)BTC https://blockchain.info/address/$($address) $tweetTimestamp" | Out-Null
  158.     }
  159.  
  160.     # finally, if no errors, write the address balance to the log
  161.     Write-Output "$($balance)" | out-file $PSScriptRoot\log\$($address).log -Force
  162.  
  163.  }
  164.  
  165. Try {
  166.     ForEach ($address in $addresses) { checkBalance $address }
  167.     Write-Debug "Script exiting with success"
  168.     Exit 0
  169. }
  170.  
  171. Catch {
  172.     Write-Output "$(Get-Date -Format U) | ERROR | $_." | Out-File $PSScriptRoot\error\error.log -Append
  173.     Write-Debug "Failing with error: $_"
  174.     Exit 1
  175. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top