本文整理汇总了PHP中jsonRPCClient::getblock方法的典型用法代码示例。如果您正苦于以下问题:PHP jsonRPCClient::getblock方法的具体用法?PHP jsonRPCClient::getblock怎么用?PHP jsonRPCClient::getblock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonRPCClient
的用法示例。
在下文中一共展示了jsonRPCClient::getblock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_block_info
function get_block_info($block){
require_once('/var/www/midas/root/private/class/jsonRPCClient.php');
$darkcoin = new jsonRPCClient('http://xxxx:yyyy@127.0.0.1:9998/');
$hash_block = $darkcoin->getblockhash(intval($block));
$info_block = $darkcoin->getblock($hash_block);
$tx = $info_block["tx"][0];
$diff = round($info_block["difficulty"]);
$last_block = $block_id = $info_block["height"];
$block_time = $info_block["time"];
return $info_block;
}
示例2: mysqli
$rpchost = 'localhost';
$rpcuser = 'protosharesrpc';
$rpcpass = 'superdupersecretphrase';
$rpcport = '3838';
////////////////////////////////////////////////////////////////////////////////
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $database);
if ($mysqli->connect_errno) {
throw new Exception("database connection error");
}
$r = $mysqli->query("select max(block_num) from outputs", MYSQLI_USE_RESULT);
$w = $r->fetch_assoc();
$blocknum = $w["max(block_num)"] + 0;
$r->close();
$r = $mysqli->query("select sum(balance) from outputs", MYSQLI_USE_RESULT);
$w = $r->fetch_assoc();
$moneysupply = $w["sum(balance)"] + 0;
$r->close();
$pts = new jsonRPCClient("http://" . $rpcuser . ":" . $rpcpass . "@" . $rpchost . ":" . $rpcport);
$blockhash = $pts->getblockhash($blocknum);
$blockinfo = $pts->getblock($blockhash);
$blocktime = $blockinfo['time'];
echo "{\"blocknum\":" . $blocknum . ",\"blocktime\":" . $blocktime . ",\"moneysupply\":" . $moneysupply . ",\"balances\":\n";
echo " {\n";
$r = $mysqli->query("select * from outputs group by address order by balance desc", MYSQLI_USE_RESULT);
while ($w = $r->fetch_assoc()) {
echo " \"" . $w['address'] . "\":" . $w['balance'] . ",\n";
}
echo " }\n";
echo "}";
$r->close();
////////////////////////////////////////////////////////////////////////////////
示例3: foreach
if (is_array($unspents) && count($unspents) > 0) {
$balance = 0;
foreach (array_reverse($unspents) as $tx) {
$balance = $balance + intval($tx['amount'] * 100000000);
}
$obj['balance'] = $balance;
}
}
}
} else {
if ($call == 'block') {
$obj = ["blockchain" => $blockchain, "height" => "N/A", "hash" => "N/A", "prev" => "N/A", "next" => "N/A", "tx_count" => 0, "time" => "N/A"];
if (isset($_GET['id']) && $_GET['id']) {
$height = intval($_GET['id']);
$block_hash = $bitcoind->getblockhash($height);
$block = $bitcoind->getblock($block_hash);
$obj['raw'] = $block;
if ($block_hash) {
$obj['height'] = $height;
$obj['hash'] = $block_hash;
}
if ($block) {
if (isset($block['previousblockhash']) && $block['previousblockhash']) {
$obj['prev'] = $block['previousblockhash'];
}
if (isset($block['nextblockhash']) && $block['nextblockhash']) {
$obj['next'] = $block['nextblockhash'];
}
if (isset($block['tx']) && is_array($block['tx'])) {
$obj['tx_count'] = count($block['tx']);
}
示例4: mysqli
$rpcport = '3838';
////////////////////////////////////////////////////////////////////////////////
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $database);
if ($mysqli->connect_errno) {
throw new Exception("database connection error");
}
$r = $mysqli->query("select max(block_num) from outputs", MYSQLI_USE_RESULT);
$w = $r->fetch_assoc();
$last_block_in_db = $w["max(block_num)"] + 0;
$r->close();
$pts = new jsonRPCClient("http://" . $rpcuser . ":" . $rpcpass . "@" . $rpchost . ":" . $rpcport);
$blocknum = $pts->getblockcount();
if ($last_block_in_db < $blocknum) {
for ($i = $last_block_in_db + 1; $i <= $blocknum; $i++) {
echo "block " . $i . "\n";
$block = $pts->getblock($pts->getblockhash($i));
foreach ($block["tx"] as $txid) {
$tx = $pts->decoderawtransaction($pts->getrawtransaction($txid));
foreach ($tx["vin"] as $tx_in) {
if (!array_key_exists("coinbase", $tx_in)) {
$mysqli->query("delete from outputs where transaction_hash='" . $tx_in["txid"] . "' and sequence=" . $tx_in["vout"] . ";");
}
}
foreach ($tx["vout"] as $tx_out) {
$scripttype = $tx_out["scriptPubKey"]["type"];
switch ($scripttype) {
case "pubkeyhash":
case "pubkey":
case "scripthash":
$mysqli->query("insert into outputs (block_num, block_hash, transaction_hash, sequence, address, balance) values (" . $i . ", '" . $block["hash"] . "', '" . $txid . "', " . $tx_out["n"] . ", '" . $tx_out["scriptPubKey"]["addresses"][0] . "', " . $tx_out["value"] . ")");
break;
示例5: copyBlockToDB
/**
* @param $blockID - Block ID to process
* @return mixed
* @throws \RedBeanPHP\RedException
*/
private static function copyBlockToDB($blockID)
{
$wallet = new jsonRPCClient(HOTWALLET, true);
$getBlockHash = $wallet->getblockhash($blockID);
$getBlock = $wallet->getblock($getBlockHash);
//$return['getBlockHash'] = $getBlockHash;
//$return['getBlock'] = $getBlock;
$findOne = R::findOne('blocks', 'height = ?', [$blockID]);
if (!$findOne) {
$dispense = R::dispense('blocks');
foreach ($getBlock as $key => $value) {
if ($key == "tx") {
$dispense->{$key} = json_encode($value);
$processTX = self::processTransactions($value);
$dispense->totalvalue = $processTX['totalValue'];
$dispense->transactioncount = $processTX['transactionCount'];
} else {
$dispense->{$key} = $value;
}
}
R::store($dispense);
}
//$return['processTX'] = $processTX;
$return['data'] = "Processed";
return $return;
}