Post
Topic
Board Announcements (Altcoins)
Re: [*] 8BIT [Dark Masternodes][Anon][Roadmap Stage 4]
by
2xjO9M3P
on 26/11/2017, 10:26:35 UTC
I am trying to write a script for my mns which will automatically select all reward inputs within each wallet (everything except for the initial 112 8bit mn deposit) and send them to my staking wallet. It is tedious and time-consuming to open each wallet in qt.

I'm assuming people have done this? If so, might anyone be willing to post a sample of their code?

Something to get you started. It's not exactly automated, but shouldn't take too much extra work to get it that step further.

coincontrol.php will give you an overview of all blocks in a wallet, and let you select which blocks to include in a transaction, as well as define an output address.
This will be passed on to createraw.php which will create the "createrawtransaction" string. NB This script will only display the transaction string. You will have to manually run the "createrawtransaction" string on the daemon (followed, of course, by "signrawtransaction" and "sendrawtransaction").

Code is provided as-is. Hope it helps.

coincontrol.php
Code:
$name="8Bit";
$user="rpcuser";
$pass="rpcpass";
$ip="127.0.0.1";
$port="18889";

class 
Coin {
  private 
$username;
  private 
$password;
  private 
$proto;
  private 
$host;
  private 
$port;
  private 
$url;
  public 
$status;
  public 
$error;
  public 
$raw_response;
  public 
$response;
  private 
$id 0;
  public function 
__construct($username$password$host 'localhost'$port 8332) {
    
$this->username    $username;
    
$this->password    $password;
    
$this->host      $host;
    
$this->port      $port;
  }
  public function 
__call($method$params) {
    
$this->status     null;
    
$this->error    null;
    
$this->raw_response null;
    
$this->response   null;
    
$params array_values($params);
    
$this->id++;
    
$request json_encode(array(
      
'method' => $method,
      
'params' => $params,
      
'id'   => $this->id));
    
$curl  curl_init("http://{$this->host}:{$this->port}/");
    
$options = array(
      
CURLOPT_HTTPAUTH     => CURLAUTH_BASIC,
      
CURLOPT_USERPWD    => $this->username ':' $this->password,
      
CURLOPT_RETURNTRANSFER => true,
      
CURLOPT_FOLLOWLOCATION => true,
      
CURLOPT_MAXREDIRS    => 10,
      
CURLOPT_HTTPHEADER   => array('Content-type: application/json'),
      
CURLOPT_POST       => true,
      
CURLOPT_POSTFIELDS   => $request);
    
curl_setopt_array($curl$options);
    
$this->raw_response curl_exec($curl);
    
$this->response   json_decode($this->raw_responsetrue);
    
$this->status curl_getinfo($curlCURLINFO_HTTP_CODE);
    
$curl_error curl_error($curl);
    
curl_close($curl);
    if (!empty(
$curl_error)) {
      
$this->error $curl_error;
    }
    if (
$this->response['error']) {
      
$this->error $this->response['error']['message'];
    } elseif (
$this->status != 200) {
      switch (
$this->status) {
        case 
400:
          
$this->error 'HTTP_BAD_REQUEST';
          break;
        case 
401:
          
$this->error 'HTTP_UNAUTHORIZED';
          break;
        case 
403:
          
$this->error 'HTTP_FORBIDDEN';
          break;
        case 
404:
          
$this->error 'HTTP_NOT_FOUND';
          break;
      }
    }
    if (
$this->error) {
      return 
false;
    }
    return 
$this->response['result'];
  }
}

echo 
"\n";
echo 
"\n";
echo 
"\n\n";
echo 
"\n";
echo 
"[Coin Control]\n\n\n";

echo 
$name."
\n";
echo 
"\n";
echo 
"\n";
echo 
"\n";
echo 
"\n";
echo 
"\n";
echo 
"\n";
echo 
"\n";


$coin = new Coin($user,$pass,$ip,$port);
$listunsentlist=$coin->listunspent();
foreach (
$listunsentlist as $listunspent) {
  
$txid=$listunspent["txid"];
  
$vout=$listunspent["vout"];
  
$account=$listunspent["account"];
  
$amount=$listunspent["amount"];
  
$confirm=$listunspent["confirmations"];
  echo 
"\n";
  echo 
"\n";
  echo 
"\n";
  echo 
"\n";
  echo 
"\n";
  echo 
"\n";
  echo 
"";
}

echo 
"
 AccountAmountTXIDvoutConfirmations
.$txid.":".$vout.":".$amount."'>".$account."".number_format($amount,8)."".$txid."".$vout."".$confirm."
\n"
;
echo 
"
Recipient: 
"
;
echo 
"\n";
echo 
"\n";
echo 
"

\n"
;
echo 
"\n";
mysqli_close($con);
?>

createraw.php
Code:
$tx=$_POST['tx'];
$addr=$_POST['addr'];
$in=0;
$am=0;
$rawstr="";
echo 
"\n";
echo 
"\n";
echo 
"\n\n";
echo 
"\n";
echo 
"[Raw Transaction]\n\n\n";

foreach (
$tx as $txs) {
  echo 
$txs."
"
;
  
$txdata=explode(":",$txs);
  
$txid=$txdata[0];
  
$vout=$txdata[1];
  
$amnt=$txdata[2];
  
$in=$in+1;
  
$am=$am+$amnt;
  if (
strlen($rawstr)==0) {
    
$rawstr="createrawtransaction '[{\"txid\":\"".$txid."\",\"vout\":".$vout."}";
  } else {
    
$rawstr=$rawstr.",{\"txid\":\"".$txid."\",\"vout\":".$vout."}";
  }
}
$rawstr=$rawstr."]'";
$txsize=$in*149 44;
$txfee=ceil($txsize/1000)*0.0001;
$txout=$am-$txfee;
$rawstr=$rawstr." '{\"".$addr."\":".$txout."}'";
echo 
"
Input count: "
.$in."
"
;
echo 
"Input amount: ".$am."
"
;
echo 
"TX Size: ".$txsize."
"
;
echo 
"TX Fee: ".$txfee."
"
;
echo 
"To be sent: ".$txout."
"
;
echo 
"".$rawstr."";

echo 
"

\n"
;
echo 
"\n";
?>