Advertisement
Guest User

Untitled

a guest
Mar 30th, 2021
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.  
  3. <head>
  4.     <script>
  5.  
  6.         var handleEthermineResult = function (err, data) {
  7.             const payouts = getAllPayoutsTo(data.result, "0xea674fdde714fd979de3edf0f56aa9716b898ec8");
  8.             console.log("all payouts", payouts)
  9.  
  10.             const totalPayouts = getTotalAmountFromWithTs(payouts);
  11.             const eth = Number(totalPayouts[0] / BigInt("1000000000000000")) / 1000;
  12.             console.log("Total profit during timeframe is: " + eth + " ETH (since:" + new Date(totalPayouts[1] * 1000) + ")")
  13.         }
  14.  
  15.         var getJSON = function (url, callback) {
  16.             var xhr = new XMLHttpRequest();
  17.             xhr.open('GET', url, true);
  18.             xhr.responseType = 'json';
  19.             xhr.onload = function () {
  20.                 var status = xhr.status;
  21.                 if (status === 200) {
  22.                     callback(null, xhr.response);
  23.                 } else {
  24.                     callback(status, xhr.response);
  25.                 }
  26.             };
  27.             xhr.send();
  28.         };
  29.  
  30.         getEthermineTx();
  31.  
  32.         function getEthermineTx() {
  33.             return getJSON(
  34.                 "https://api.etherscan.io/api?module=account&action=txlist&address=0xf6da21e95d74767009accb145b96897ac3630bad&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken",
  35.                 handleEthermineResult
  36.             );
  37.         }
  38.  
  39.         function getAllPayoutsTo(data, toAddress) {
  40.             var result = [];
  41.             for (var i = 0; i < data.length; i++) {
  42.                 const current = data[i];
  43.                 if (current.to == toAddress) {
  44.                     result.push(current);
  45.                 }
  46.             }
  47.             return result;
  48.         }
  49.  
  50.         function getTotalAmountFromWithTs(data, timeframe) {
  51.             var result = BigInt(0);
  52.             earliestTimeStamp = 9999999999999;
  53.             for (var i = 0; i < data.length; i++) {
  54.                 const current = data[i];
  55.                 if (timeframe && current.timeStamp < Date.now() / 1000 - timeframe) {
  56.  
  57.                     continue;
  58.                 }
  59.                 if (current.timeStamp < earliestTimeStamp) earliestTimeStamp = current.timeStamp;
  60.                 result = BigInt(current.value) + result;
  61.             }
  62.             return [result, earliestTimeStamp];
  63.         }
  64.  
  65.     </script>
  66. </head>
  67.  
  68. <body>
  69.  
  70. </body>
  71.  
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement