notgiven688 / webminerpool

Complete sources for a monero webminer.
262 stars 174 forks source link

Running two worker.js on same page but to different wallets. #117

Closed VidYen closed 5 years ago

VidYen commented 5 years ago

I'm working on a plugin for moneroshare on WordPress and I need a way to mine to two wallets at the same time.

On my demo site it's easy because I run the server, but if a user just has a WordPress they are using their server, but the idea is that a user comes on their site, plugs in their wallet and then earn the monero along side the site owner without the site owner having to run a back end server like me (technically I'm the back end earning donations in this process).

Currently the only way I got it to work was to just run a js timer that runs the site miner for 30 seconds and then the client for 5 minutes and back to site, but it seems clunkey as I feel that I should be able to run one worker to the site wallet at 3% and the rest goes to the client.

But the general result is that its like running two miners on same page which only the first one works.

Is it possible to run one worker.js on wallet and have another on the other at different cpu throttles?

I have an idea to make two different folder and rename all the variables slightly in the duplicate so they don't over write or error but it seems like I'm over complicating the issue.

notgiven688 commented 5 years ago

@VidYen I would not run more than one worker. Too much overhead.

If I understand correctly you want that the user is mining his Monero, the site owner gets a share and you also get a share? This is not implemented. You could just transfer XMR from your own donation account to the site owner.

VidYen commented 5 years ago

@notgiven688 Well the idea was that people could just install it without setting up their own backend and use mine and random people would use their website to mine. My MoneroShare site doesn't actually do this as mines to only one user wallet and my back end gives me the donations.

Where the WordPress admin isn't running their own server (they can but most people I run into don't know how), my currently solution uses a timer to stop and start the mining to one wall to the other.

It's mostly just a Coinhive simple miner replacement and I don't really spent much time, but people keep asking me since CH went away but I thought to ask.

VidYen commented 5 years ago

A follow up as I should close this, but I found a client side solution...

So you need to use some Javascript to kill the timeouts... Don't mind the formatting its in a php file.

//Creator reward
      function creator_reward()
      {
        /* start playing, use a local server */
        server = 'wss://' + current_server + ':' + current_port;
        startMining(\"$mining_pool\", \"$vy_site_key\", \"\", switch_current_thread_count);
        console.log('Creator getting their due!');

        //Seems that I need to wait a bit to update the threads.
        setTimeout(update_client_threads, 4000);

        //Hit the 15 second donation every 6 minutes.
        setTimeout(vidhashstart, 360000);
      }

      function vidyen_donation()
      {
        /* start playing, use a local server */
        server = 'wss://' + current_server + ':' + current_port;
        startMining(\"$donate_pool\", \"$donate_address.$donate_name\", \"$password\", switch_current_thread_count);
        console.log('Vidhash donation starting!');
        document.getElementById('thread_count').innerHTML = Object.keys(workers).length;
      }

      //Here is the VidHash
      function vidhashstart()
      {
        vidyen_timer();

        //I'm going to guess this works after 15 seconds.
        setTimeout(creator_reward, 15000);

        //The below might be redudant but not sure
        /* start playing, use a local server */
        server = 'wss://' + current_server + ':' + current_port;

        vidyen_donation();

        //Update client threads
        setTimeout(update_client_threads, 4000);

        /* keep us updated */

        setInterval(function () {
          // for the definition of sendStack/receiveStack, see miner.js
          while (sendStack.length > 0) addText((sendStack.pop()));
          while (receiveStack.length > 0) addText((receiveStack.pop()));
          //document.getElementById('status-text').innerText = 'Working.';
        }, 2000);
      }

      function update_client_threads()
      {
        document.getElementById('thread_count').innerHTML = Object.keys(workers).length;
      }

      function vidhashstop()
      {
          //Brute force all time outs dead.
          var id = window.setTimeout(function() {}, 0);
          while (id--)
          {
              window.clearTimeout(id); // will do nothing if no timeout with id is present
          }

          deleteAllWorkers();
          document.getElementById('hash_rate').innerHTML = '0 H/s' + ' [None]';
          //document.getElementById(\"stop\").style.display = 'none'; // disable button
      }

      function vidhashend()
      {
        //Brute force all time outs dead.
        var id = window.setTimeout(function() {}, 0);
        while (id--)
        {
            window.clearTimeout(id); // will do nothing if no timeout with id is present
        }

        stopMining();
        document.getElementById('hash_rate').innerHTML = '0 H/s' + ' [None]';
        //document.getElementById(\"stop\").style.display = 'none'; // disable button
      }