예제 #1
1
 function actionIndex()
 {
     $this->layout = '//layouts/none';
     //header('Content-type: application/json');
     $null_wallets = Wallet::model()->findAllByAttributes(array('wallet_address' => null));
     foreach ($null_wallets as $null_wallet) {
         // CoinAddress::set_debug(true);      // optional - show debugging messages
         // CoinAddress::set_reuse_keys(true); // optional - use same key for all addresses
         $newcoin = CoinAddress::bitcoin();
         Yii::log("Created new address for {$newcoin['public_hex']}", "info");
         $new_wallet = new SecureWallet();
         $new_wallet->wallet_address = $newcoin['public'];
         $new_wallet->private_key = $newcoin['private'];
         $new_wallet->save();
         $null_wallet->wallet_address = $new_wallet->wallet_address;
         $null_wallet->save();
     }
     echo CJSON::encode(array('status' => 'ok'));
     Yii::app()->end();
 }
 public static function create_key_pair()
 {
     self::debug('create_key_pair');
     $privBin = '';
     for ($i = 0; $i < 32; $i++) {
         $privBin .= chr(mt_rand(0, $i ? 0xff : 0xfe));
     }
     self::debug('create_key_pair: privBin: ' . bin2hex($privBin));
     //self::debug('create_key_pair: point');
     $point = Point::mul(bcmath_Utils::bin2bc("" . $privBin), self::$secp256k1_G);
     self::debug('create_key_pair: point: ' . $point);
     //self::debug('create_key_pair: pubBinStr');
     $pubBinStr = "" . str_pad(bcmath_Utils::bc2bin($point->getX()), 32, "", STR_PAD_LEFT) . str_pad(bcmath_Utils::bc2bin($point->getY()), 32, "", STR_PAD_LEFT);
     self::debug('create_key_pair: pubBinStr: ' . bin2hex($pubBinStr));
     self::$key_pair_public = hash('ripemd160', hash('sha256', $pubBinStr, true), true);
     self::debug('create_key_pair: key_pair_public: ' . bin2hex(self::$key_pair_public));
     self::$key_pair_private = $privBin;
     self::debug('create_key_pair: key_pair_private: ' . bin2hex($privBin));
     //return array('public' => hash('ripemd160', hash('sha256', $pubBinStr, true), true), 'private' => $privBin);
 }
예제 #3
0
<?php

// PHPCoinAddress contrib: bulk wallet creator
// Version 0.0.1
$lib = '../PHPCoinAddress.php';
if (!is_readable($lib)) {
    print 'ERROR: missing lib';
    exit;
}
require_once $lib;
CoinAddress::set_debug(false);
CoinAddress::set_reuse_keys(false);
$coin_type = 'bitcoin';
$number = 25;
for ($x = 1; $x <= $number; $x++) {
    $coin = CoinAddress::$coin_type();
    //print "$x," . '"' . $coin['public'] . '","' . $coin['private'] . '"' . "\n";
    print "{$x}," . '"' . $coin['public_compressed'] . '","' . $coin['private_compressed'] . '"' . "\n";
}
예제 #4
0
// PHPCoinAddress contrib:  simple web interface
// Version 0.0.1
$lib = '../PHPCoinAddress.php';
if (!is_readable($lib)) {
    print 'ERROR: missing lib';
    exit;
}
require_once $lib;
web_header();
$debug = @$_GET['debug'];
if ($debug) {
    CoinAddress::set_debug(true);
}
$reuse_keys = @$_GET['reuse_keys'];
if ($reuse_keys) {
    CoinAddress::set_reuse_keys(true);
}
$coins = @$_GET['coin'];
if (!$coins) {
    web_form();
} else {
    web_results();
}
web_footer();
///////////////////////////////////////////////////////////////////
function web_form()
{
    print '
<form action="web.php" method="GET"><pre>

<input type="submit" value="Create Public/Private Keys" />
 private function get_template()
 {
     // get template name
     $this->a = $this->get_get('a', 'home');
     switch ($this->a) {
         case 'about':
             return 'about';
             break;
         case 'home':
             $this->open_wallet();
             return 'home';
             break;
         default:
             $msg = 'Unknown Action';
             include 'skins/simple/fatal.error.php';
             exit;
             break;
         case 'listtransactions':
             if (!$this->open_wallet()) {
                 $this->debug('ERROR: listtransactions: open_wallet failed');
                 return 'listtransactions';
             }
             if (!isset($_GET['account'])) {
                 $_GET['account'] = '*';
                 // ALL
             }
             if (isset($_GET['account']) && $_GET['account'] == '""') {
                 $_GET['account'] = '';
                 // Default Account
             }
             $this->account = $this->get_get('account', '');
             $this->count = $this->get_get('count', 9999999);
             $this->from = $this->get_get('from', 0);
             $this->listtransactions = $this->wallet->listtransactions((string) $this->account, (int) $this->count, (int) $this->from);
             $this->info['transactions_count'] = sizeof($this->listtransactions);
             $this->listtransactions = @array_reverse($this->listtransactions);
             $this->lisstransactions = @array_walk($this->listtransactions, array(&$this, 'post_process_listtransactions'));
             return 'listtransactions';
             break;
         case 'listaccounts':
             $this->open_wallet();
             $this->listaccounts = $this->wallet->listaccounts((int) $this->get_get('minconf', 1));
             return 'listaccounts';
             break;
         case 'listreceivedbyaccount':
             $this->open_wallet();
             $this->listreceivedbyaccount = $this->wallet->listreceivedbyaccount((int) $this->get_get('minconf', 1), (bool) $this->get_get('includeempty', 'false'));
             return 'listreceivedbyaccount';
             break;
         case 'getaccountaddress':
             $this->open_wallet();
             $this->getaccountaddress = $this->wallet->getaccountaddress((string) $this->get_get('account', '', $failonempty = true));
             return 'getaccountaddress';
             break;
         case 'getaddressesbyaccount':
             $this->open_wallet();
             $this->getaddressesbyaccount = $this->wallet->getaddressesbyaccount((string) $this->get_get('account', '', $failonempty = true), (int) $this->get_get('minconf', 1));
             return 'getaddressesbyaccount';
             break;
         case 'getreceivedbyaccount':
             $this->open_wallet();
             $this->getreceivedbyaccount = $this->wallet->getreceivedbyaccount((string) $this->get_get('account', '', true));
             return 'getreceivedbyaccount';
             break;
         case 'getbalance':
             $this->open_wallet();
             $this->getbalance = $this->wallet->getbalance((string) $this->get_get('account', '', true), (int) $this->get_get('minconf', 1));
             return 'getbalance';
             break;
             // Transactions
         // Transactions
         case 'gettransaction':
             $this->open_wallet();
             $this->gettransaction = $this->wallet->gettransaction((string) $this->get_get('txid', '', true));
             return 'gettransaction';
             break;
         case 'listreceivedbyaddress':
             $this->open_wallet();
             $this->listreceivedbyaddress = $this->wallet->listreceivedbyaddress((int) $this->get_get('minconf', 1), (bool) $this->get_get('includeempty', false));
             return 'listreceivedbyaddress';
             break;
         case 'getnewaddress':
             $this->open_wallet();
             $this->getnewaddress = $this->wallet->getnewaddress((string) $this->get_get('account', ''));
             return 'getnewaddress';
             break;
         case 'getreceivedbyaddress':
             $this->open_wallet();
             $this->getreceivedbyaddress = $this->wallet->getreceivedbyaddress((string) $this->get_get('address', ''), (int) $this->get_get('minconf', 1));
             return 'getreceivedbyaddress';
             break;
         case 'getaccount':
             $this->open_wallet();
             $this->getaccount = $this->wallet->getaccount((string) $this->get_get('address', '', true));
             return 'getaccount';
             break;
         case 'setaccount':
             $this->open_wallet();
             $this->setaccount = $this->wallet->setaccount((string) $this->get_get('address', '', true), (string) $this->get_get('account', '', true));
             if ($this->setaccount == '') {
                 $this->setaccount = 'OK';
             }
             return 'setaccount';
             break;
         case 'validateaddress':
             $this->open_wallet();
             $this->validateaddress = $this->wallet->validateaddress((string) $this->get_get('address', '', true));
             return 'validateaddress';
             break;
         case 'sendtoaddress':
             $this->open_wallet();
             $this->address = $this->get_get('address', '');
             $this->amount = $this->get_get('amount', '');
             $this->ok = $this->get_get('ok', '0');
             $this->debug("send address:{$this->address} amount:{$this->amount} ok:{$this->ok}");
             if ($this->address) {
                 $this->validateaddress = $this->wallet->validateaddress($this->address);
                 if (!$this->validateaddress['isvalid']) {
                     $this->debug('invalid address: ' . $this->address);
                     return 'sendtoaddress';
                     break;
                 }
             }
             if ($this->address && $this->amount && $this->ok) {
                 $this->debug("Sending coins");
                 $this->sendtoaddress = $this->wallet->sendtoaddress((string) $this->address, (double) $this->amount, (string) $this->get_get('comment', ''), (string) $this->get_get('comment_to', ''));
             }
             return 'sendtoaddress';
             break;
         case 'sendfrom':
             $this->open_wallet();
             $this->sendfrom = $this->wallet->sendfrom((string) $this->get_get('account', '', true), (string) $this->get_get('address', '', true), (double) $this->get_get('amount', '', true), (int) $this->get_get('minconf', 1), (string) $this->get_get('comment', ''), (string) $this->get_get('comment_to', ''));
             return 'sendfrom';
             break;
         case 'sendmany':
             $this->open_wallet();
             $this->sendmany = $this->wallet->sendmany((string) $this->get_get('account', '', true), (string) $this->get_get('tomany', '', true), (int) $this->get_get('minconf', 1), (string) $this->get_get('comment', ''));
             return 'sendmany';
             break;
         case 'move':
             $this->open_wallet();
             $this->move = $this->wallet->move((string) $this->get_get('fromaccount', '', true), (string) $this->get_get('toaccount', '', true), (double) $this->get_get('amount', '', true), (int) $this->get_get('minconf', 1), (string) $this->get_get('comment', ''));
             return 'move';
             break;
         case 'sendescrow':
             $this->open_wallet();
             $this->escrowaddrs = $this->get_get('escrowaddrs', '');
             $this->amount = $this->get_get('amount', '');
             $this->ok = $this->get_get('ok', '0');
             $this->debug("escrowaddrs:{$this->escrowaddrs} amount:{$this->amount} ok:{$this->ok}");
             if ($this->escrowaddrs && $this->amount && $this->ok) {
                 $this->debug("Sending escrow");
                 $this->sendescrow = $this->wallet->sendescrow((string) $this->escrowaddrs, (double) $this->amount, (string) $this->get_get('comment', ''), (string) $this->get_get('comment_to', ''));
             }
             return 'sendescrow';
             break;
         case 'redeemescrow':
             $this->open_wallet();
             $this->redeemescrow = $this->wallet->redeemescrow((string) $this->get_get('inputtx', ''), (string) $this->get_get('address', ''), (string) $this->get_get('txhex', ''));
             return 'redeemescrow';
             break;
         case 'getinfo':
             $this->open_wallet();
             $this->getinfo = @$this->info;
             return 'getinfo';
             break;
         case 'getblockcount':
         case 'getblocknumber':
         case 'getconnectioncount':
         case 'getdifficulty':
         case 'getgenerate':
         case 'gethashespersec':
         case 'getwork':
         case 'stop':
             $this->open_wallet();
             $this->{$this->a} = $this->wallet->{$this->a}();
             return 'debug';
             break;
         case 'start':
         case 'getprocess':
         case 'kill':
             $this->open_wallet();
             $this->{$this->a} = $this->wallet->{$this->a}();
             return 'debug';
             break;
         case 'backupwallet':
             $this->open_wallet();
             $this->backupwallet = $this->wallet->backupwallet((string) $this->get_get('destination', '', true));
             if ($this->backupwallet == '') {
                 $this->backupwallet = 'OK';
             }
             return 'backupwallet';
             break;
         case 'setgenerate':
             $this->open_wallet();
             // hacky fix until we do better per-_GET/_POST to $this->{_GET/_POST} var with typecasting
             switch ($this->get_get('generate', '', TRUE)) {
                 case 'false':
                 case '0':
                     $this->generate = 0;
                     break;
                 case 'true':
                 case '1':
                     $this->generate = 1;
                     break;
                 default:
                     $this->debug("ERROR: setgenerate generate is not boolean");
                     return 'setgenerate';
                     break;
             }
             $this->genproclimit = (int) $this->get_get('genproclimit', '');
             $this->setgenerate = $this->wallet->setgenerate((bool) $this->generate, (int) $this->genproclimit);
             if ($this->setgenerate == '') {
                 $this->setgenerate = "OK: setgenerate {$this->generate} {$this->genproclimit}";
             }
             return 'setgenerate';
             break;
         case 'help':
             $this->open_wallet();
             $this->help = $this->wallet->help((string) $this->get_get('command', ''));
             return 'help';
             break;
             // Namecoin
         // Namecoin
         case 'name_list':
             $this->open_wallet();
             $this->name_list = $this->wallet->name_list((string) $this->get_get('name', ''));
             return 'debug';
             break;
         case 'name_new':
             $this->open_wallet();
             $this->name_new = $this->wallet->name_new((string) $this->get_get('name', ''));
             return 'debug';
             break;
         case 'name_firstupdate':
             $this->open_wallet();
             $this->name_firstupdate = $this->wallet->name_firstupdate((string) $this->get_get('name', ''), (string) $this->get_get('rand', ''), (string) $this->get_get('tx', ''), (string) $this->get_get('value', ''));
             return 'debug';
             break;
         case 'name_update':
             $this->open_wallet();
             $this->name_update = $this->wallet->name_update((string) $this->get_get('name', ''), (string) $this->get_get('value', ''), (string) $this->get_get('address', ''));
             return 'debug';
             break;
         case 'name_scan':
             $this->open_wallet();
             $this->name_scan = $this->wallet->name_scan((string) $this->get_get('start_name', ''), (int) $this->get_get('max_returned', ''));
             return 'debug';
             break;
         case 'name_clean':
             $this->open_wallet();
             $this->name_clean = $this->wallet->name_clean();
             return 'debug';
             break;
         case 'deletetransaction':
             $this->open_wallet();
             $this->deletetransaction = $this->wallet->deletetransaction((string) $this->get_get('txid', '', true));
             return 'debug';
             break;
             ////////////////////////////////////////////////////////////////////////////////////////////////
         ////////////////////////////////////////////////////////////////////////////////////////////////
         case 'server.control':
             if (!SERVER_LOCALHOST) {
                 $this->info['control'] = 'Error: No Localhost server found in configuration';
                 return 'server.control';
             }
             if (SERVER_LOCALHOST_TYPE != 'windows') {
                 $this->info['control'] = 'Erro: No Windows platform found in configuration';
                 return 'server.control';
             }
             switch (strtolower($this->get_get('a1', ''))) {
                 case 'view':
                     // tasklist
                     $tasklist = shell_exec(WINDOWS_TASKLIST . ' /FO LIST /FI "IMAGENAME eq ' . SERVER_NAME . '" 2>&1');
                     //$tasklist = shell_exec(WINDOWS_TASKLIST . ' 2>&1');
                     $found = strpos($tasklist, SERVER_NAME);
                     if ($found === false) {
                         $this->info['control'] = SERVER_NAME . ' Process Not Found';
                         return 'server.control';
                     }
                     //$header = substr($tasklist, 0, 154);
                     //$info = substr($tasklist, $found, 76);
                     //$this->info['control'] = "$header\n$info";
                     $this->info['control'] = $tasklist;
                     break;
                 case 'start':
                     if (!file_exists(SERVER)) {
                         $this->info['control'] = "Error: Can not find server executable '" . SERVER . "'";
                         return 'server.control';
                     }
                     if (!file_exists(SERVER_CONF)) {
                         $this->info['control'] = "ERROR: Can not find server configuration file '" . SERVER_CONF . "'<br />Please create this configuration file.";
                         return 'server.control';
                     }
                     $start_cmd = 'start /B ' . SERVER . (SERVER_TESTNET ? ' -testnet ' : '') . ' -datadir=' . SERVER_DATADIR . ' -conf=' . SERVER_CONF;
                     $this->info['control'] = "Running: {$start_cmd}\n";
                     try {
                         //$this->info['control'] = shell_exec( $start_cmd. ' 2>&1');
                         pclose(popen("start /B " . $start_cmd, "r"));
                         // start in background, return execution to us
                     } catch (BitcoinClientException $e) {
                         $this->info['control'] .= "Error: Can not start server: \nCommand: {$cmd} \nMessage: " . $e->getMessage();
                     }
                     break;
             }
             // end switch
             return 'server.control';
             break;
             // misc
         // misc
         case 'PHPCoinAddress':
             print 'DEBUG PHPCoinAddress';
             $lib = 'plugins/PHPCoinAddress.php';
             if (!is_readable($lib)) {
                 print 'ERROR: missing ' . $lib;
                 exit;
             }
             require_once $lib;
             $debug = $this->get_get('debug', '');
             if ($debug) {
                 CoinAddress::set_debug(true);
             }
             $reuse_keys = $this->get_get('reuse_keys', '');
             if ($reuse_keys) {
                 CoinAddress::set_reuse_keys(true);
             }
             $coins = @$_GET['coin'];
             if (!$coins || !is_array($coins)) {
                 print 'ERROR: no coin type';
                 exit;
             }
             while (list(, $x) = each($coins)) {
                 switch ($x) {
                     case 'bitcoin':
                         $bitcoin = CoinAddress::bitcoin();
                         break;
                     case 'bitcoin_testnet':
                         $bitcoin_testnet = CoinAddress::bitcoin_testnet();
                         break;
                     case 'namecoin':
                         $namecoin = CoinAddress::namecoin();
                         break;
                     case 'namecoin_testnet':
                         $namecoin_testnet = CoinAddress::namecoin_testnet();
                         break;
                     case 'litecoin':
                         $litecoin = CoinAddress::litecoin();
                         break;
                     case 'litecoin_testnet':
                         $litecoin_testnet = CoinAddress::litecoin_testnet();
                         break;
                     case 'devcoin':
                         $devcoin = CoinAddress::devcoin();
                         break;
                     case 'devcoin_testnet':
                         $devcoin_testnet = CoinAddress::devcoin_testnet();
                         break;
                     case 'ppcoin':
                         $ppcoin = CoinAddress::ppcoin();
                         break;
                     case 'ppcoin_testnet':
                         $ppcoin_testnet = CoinAddress::ppcoin_testnet();
                         break;
                 }
             }
             $this->PHPCoinAddress = "\n<HR><pre>\nbitcoin : " . @$bitcoin['private'] . ' ' . @$bitcoin['public'] . "\nnamecoin: " . @$namecoin['private'] . ' ' . @$namecoin['public'] . "\ndevcoin : " . @$devcoin['private'] . ' ' . @$devcoin['public'] . "\nppcoin  : " . @$ppcoin['private'] . ' ' . @$ppcoin['public'] . "\n\nbitcoin_testnet : " . @$bitcoin_testnet['private'] . ' ' . @$bitcoin_testnet['public'] . "\nnamecoin_testnet: " . @$namecoin_testnet['private'] . ' ' . @$namecoin_testnet['public'] . "\ndevcoin_testnet : " . @$devcoin_testnet['private'] . ' ' . @$devcoin_testnet['public'] . "\nppcoin_testnet  : " . @$ppcoin_testnet['private'] . ' ' . @$ppcoin_testnet['public'] . "\n\ndebug:{$debug} \nreuse_keys:{$reuse_keys} \n</pre>";
             return 'debug';
             //return 'PHPCoinAddress';
             break;
         case 'mtgox':
             include_once 'plugins/mtgox.php';
             $this->info['mtgox_ticker'] = mtgox_get_ticker();
             //= null_data_ticker();
             switch ($this->get_get('a1', '')) {
                 case 'depth':
                     $this->info['mtgox_depth'] = mtgox_get_depth();
                     //= null_data_depth();
                     break;
                 case 'trades':
                     $this->info['mtgox_trades'] = mtgox_get_trades();
                     //= null_data_trades();
                     break;
             }
             return 'mtgox';
             break;
     }
     // end switch
 }
예제 #6
0
$coin = CoinAddress::smallchange();
coin_info('Smallchange', $coin);
$coin = CoinAddress::terracoin();
coin_info('Terracoin', $coin);
$coin = CoinAddress::yacoin();
coin_info('Yacoin', $coin);
$coin = CoinAddress::bitcoin_testnet();
coin_info('Bitcoin Testnet', $coin);
$coin = CoinAddress::bbqcoin_testnet();
coin_info('BBQcoin Testnet', $coin);
$coin = CoinAddress::bitbar_testnet();
coin_info('Bitbar Testnet', $coin);
// all other coin testnets uses Bitcoin prefixes
$public_prefix = '0x' . dechex(mt_rand(0, 255));
$private_prefix = '0x' . dechex(mt_rand(0, 255));
$coin = CoinAddress::generic($public_prefix, $private_prefix);
coin_info('Random', $coin);
// END TEST
$end = microtime(1);
$duration = $end - $start;
$duration = round($duration, 8);
print "\nTest Time: {$duration} seconds\n";
exit;
//////////////////////////////////////////////
function coin_info($name, $coin)
{
    print "\n{$name}";
    print " [ prefix_public: " . CoinAddress::$prefix_public;
    print "  prefix_private: " . CoinAddress::$prefix_private . " ]\n";
    print "uncompressed:\n";
    print 'public (base58): ' . $coin['public'] . "\n";
예제 #7
0
     * @param currency string Currency short handle, defaults to config option
     * @return bool true or false
     **/
    public function update($userID, $address, $currency = NULL)
    {
        if ($currency === NULL) {
            $currency = $this->config['currency'];
        }
        if ($address != $this->getCoinAddress($userID) && $this->existsCoinAddress($address)) {
            $this->setErrorMessage('Unable to update coin address, address already exists');
            return false;
        }
        if ($this->getCoinAddress($userID) != NULL) {
            $stmt = $this->mysqli->prepare("UPDATE " . $this->getTableName() . " SET coin_address = ? WHERE account_id = ? AND currency = ?");
            if ($this->checkStmt($stmt) && $stmt->bind_param('sis', $address, $userID, $currency) && $stmt->execute()) {
                return true;
            }
        } else {
            $stmt = $this->mysqli->prepare("INSERT INTO " . $this->getTableName() . " (coin_address, account_id, currency) VALUES (?, ?, ?)");
            if ($this->checkStmt($stmt) && $stmt->bind_param('sis', $address, $userID, $currency) && $stmt->execute()) {
                return true;
            }
        }
        return $this->sqlError();
    }
}
$coin_address = new CoinAddress();
$coin_address->setDebug($debug);
$coin_address->setConfig($config);
$coin_address->setMysql($mysqli);
$coin_address->setErrorCodes($aErrorCodes);
예제 #8
0
 public static function create_key_pair()
 {
     $privBin = '';
     for ($i = 0; $i < 32; $i++) {
         $privBin .= chr(mt_rand(0, $i ? 0xff : 0xfe));
     }
     $point = Point::mul(bcmath_Utils::bin2bc("" . $privBin), self::$secp256k1_G);
     $pubBinStr = "" . str_pad(bcmath_Utils::bc2bin($point->getX()), 32, "", STR_PAD_LEFT) . str_pad(bcmath_Utils::bc2bin($point->getY()), 32, "", STR_PAD_LEFT);
     $pubBinStrCompressed = (intval(substr($point->getY(), -1, 1)) % 2 == 0 ? "" : "") . str_pad(bcmath_Utils::bc2bin($point->getX()), 32, "", STR_PAD_LEFT);
     self::$key_pair_public = hash('ripemd160', hash('sha256', $pubBinStr, true), true);
     self::$key_pair_public_hex = bin2hex($pubBinStr);
     self::$key_pair_private = $privBin;
     self::$key_pair_private_hex = bin2hex($privBin);
     self::$key_pair_compressed_public = hash('ripemd160', hash('sha256', $pubBinStrCompressed, true), true);
     self::$key_pair_compressed_public_hex = bin2hex($pubBinStrCompressed);
     self::$key_pair_compressed_private = self::base58check_encode(self::$prefix_private, $privBin, 0x1);
     self::$key_pair_compressed_private_hex = self::$key_pair_private_hex;
 }